웹브라우저컨트롤

응용프로그램/Visual Basic 2014. 6. 16. 15:37 Posted by 초절정고수

원본 : http://www.vbforums.com/showthread.php?384076-Webbrowser-Control-Tip-and-Examples


Navigating to a site:
사이트 찾기...


visual basic code:

WebBrowser1.Navigate "www.google.com"


팝업창을 윈도우 폼으로 열기
사이트에서 새로운 팝업창이 열리게 될때 정한 폼을 대상으로 새 창이 열리게 된다.


visual basic code:

Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
Dim frm As Form1
Set frm = New Form1
Set ppDisp = frm.WebBrowser1.Object
frm.Show
End Sub


단어/문장을 페이지에서 찾아냄
단어나 문장을 찾아냄.


visual basic code:

Private Sub Command1_Click()
    Dim strfindword As String
        strfindword = InputBox("What are you looking for?", "Find", "") ' what word to find?
            If WebPageContains(strfindword) = True Then 'check if the word is in page
                MsgBox "The webpage contains the text" 'string is in page
            Else
                MsgBox "The webpage doesn't contains the text" 'string is not in page
            End If
End Sub
Private Function WebPageContains(ByVal s As String) As Boolean
    Dim i As Long, EHTML
    For i = 1 To WebBrowser1.Document.All.length
        Set EHTML = _
        WebBrowser1.Document.All.Item(i)


        If Not (EHTML Is Nothing) Then
            If InStr(1, EHTML.innerHTML, _
            s, vbTextCompare) > 0 Then
            WebPageContains = True
            Exit Function
        End If
    End If
Next i
End Function
Private Sub Form_Load()
    WebBrowser1.Navigate2 "www.msn.com"
End Sub


시작 페이지 만들기
이코드는 이벤트에서 어떻게 만들어지고 보여지나.


visual basic code:

Private Sub Form_Load()
    WebBrowser1.Navigate "about:blank"
End Sub

Private Sub Command1_Click()
    Dim HTML As String
        '----------The HTML CODE GOES FROM HERE AND DOWN----------
    HTML = "<HTML>" & _
            "<TITLE>Page On Load</TITLE>" & _
            "<BODY>" & _
            "<FONT COLOR = BLUE>" & _
            "This is a " & _
            "<FONT SIZE = 5>" & _
            "<B>" & _
            "programmatically " & _
            "</B>" & _
            "</FONT SIZE>" & _
            "made page" & _
            "</FONT>" & _
            "</BODY>" & _
            "</HTML>"
            '----------The HTML CODE GOES HERE AND ABOVE----------
    WebBrowser1.document.write HTML
End Sub


보통 브라우저 함수
간단한 브라우저의 함수.


visual basic code:

Private Sub Command1_Click(Index As Integer)
On Error Resume Next ' just in case there is no page back or forward
                    'I showed how to disabel them if you scroll down more
    Select Case Index
        Case 0 'Go Back Button
            WebBrowser1.GoBack 'Go Back one Page
        Case 1 'Go Forward Button
            WebBrowser1.GoForward 'Go Forward one Page
        Case 2 'Stop Button
            WebBrowser1.Stop 'stop page
        Case 3 'Refresh Button
            WebBrowser1.Refresh 'refresh page
        Case 4 'Go Home Button
            WebBrowser1.GoHome 'Go to home page
        Case 5 'Search Button
            WebBrowser1.GoSearch 'Search
    End Select
End Sub


고급 브라우저 함수
이것들은 복잡한 브라우저의 함수 프린트나 페이지 속성.


visual basic code:

Private Sub Command1_Click() 'Print Button
    WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DODEFAULT 'Show Print Window
End Sub
Private Sub Command2_Click() 'Print Preview Button
    WebBrowser1.ExecWB OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_DODEFAULT 'Show Print Preview Window
End Sub
Private Sub Command3_Click() 'Page Setup Button
    WebBrowser1.ExecWB OLECMDID_PAGESETUP, OLECMDEXECOPT_DODEFAULT 'Show Page Setup Window
End Sub
Private Sub Command4_Click() 'Page Properties Button
    WebBrowser1.ExecWB OLECMDID_PROPERTIES, OLECMDEXECOPT_DODEFAULT 'Show Page Properties Window
End Sub
Private Sub Form_Load()
    WebBrowser1.Navigate "www.google.com"
End Sub


웹의 글꼴 사이즈 변경
페이지의 글꼴크기를 어떻게 변경 하느냐,  internet explorer 보기-> 텍스트크기 메뉴


visual basic code:

Private Sub Command1_Click() ' Smallest Button
On Error Resume Next
    WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(0), vbNull
End Sub
Private Sub Command2_Click() 'Small Button
On Error Resume Next
    WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(1), vbNull
End Sub
Private Sub Command3_Click() 'Medium Button
On Error Resume Next
    WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(2), vbNull
End Sub
Private Sub Command4_Click() 'Large Button
On Error Resume Next
    WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(3), vbNull
End Sub
Private Sub Command5_Click() 'Largest Button
On Error Resume Next
    WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(4), vbNull
End Sub
Private Sub Form_Load()
    WebBrowser1.Navigate2 "www.google.com"
End Sub


페이지 목록의 함수 (뒤로/앞으로)
버튼의 사용/사용안함과 열어본 페이지중 뒤/앞 페이지를 열 수 있다.


visual basic code:

Private Sub Command1_Click() 'Go Back Button
    WebBrowser1.GoBack 'Go Back
End Sub
Private Sub Command2_Click() 'Go Forward Button
    WebBrowser1.GoForward 'Go Forward
End Sub
Private Sub Form_Load()
    WebBrowser1.Navigate "www.google.com"
End Sub
Private Sub WebBrowser1_CommandStateChange(ByVal Command As Long, ByVal Enable As Boolean)
    Select Case Command
        Case 1 'Forward
            Command2.Enabled = Enable
        Case 2 'Back
            Command1.Enabled = Enable
    End Select
End Sub


인쇠 관련 함수 (페이지 설정/프린트 미리보기/프린터 설정)
이함수는 어떻게 페이지 설정,미리보기,프린터 설정을 하는가를 보여준다.


visual basic code:

Private Sub Command1_Click() 'Print Button
    WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DODEFAULT 'Show Print Window
End Sub
Private Sub Command2_Click() 'Print Preview Button
    WebBrowser1.ExecWB OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_DODEFAULT 'Show Print Preview Window
End Sub
Private Sub Command3_Click() 'Page Setup Button
    WebBrowser1.ExecWB OLECMDID_PAGESETUP, OLECMDEXECOPT_DODEFAULT 'Show Page Setup Window
End Sub
Private Sub Form_Load()
    WebBrowser1.Navigate "www.google.com"
End Sub
Public Function Enable_or_Disable()
    If WebBrowser1.QueryStatusWB(OLECMDID_PRINT) = 0 Then
        Command1.Enabled = False
    Else
        Command1.Enabled = True
    End If
    If WebBrowser1.QueryStatusWB(OLECMDID_PRINTPREVIEW) = 0 Then
        Command2.Enabled = False
    Else
        Command2.Enabled = True
    End If

    If WebBrowser1.QueryStatusWB(OLECMDID_PAGESETUP) = 0 Then
        Command3.Enabled = False
    Else
        Command3.Enabled = True
    End If
End Function
Private Sub WebBrowser1_BeforeNavigate2 _
                    (ByVal pDisp As Object, _
                                URL As Variant, _
                                Flags As Variant, _
                        TargetFrameName As Variant, _
                                PostData As Variant, _
                                    Headers As Variant, _
                                        Cancel As Boolean)
    Enable_or_Disable
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    Enable_or_Disable
End Sub


Removing Right Click Menu From the browser control
So you need to remove the right click menu from the control, right? well there are more then two ways one of them, which i knew but i won't bother telling is using lots of hooking, waist of thime since all you have to do is download a simple helper file.
First you need to go to http://support.microsoft.com/kb/q183235/ and download the WBCustomizer.dll. once done go to the"Project Menu" and click on "Refrences" Click on browse and add the 'WBCustomizer.dll' to you app. once done just add this simple code.


visual basic code:

Option Explicit
    Dim CustomWB As WBCustomizer 'Deceler the CustomWB
Private Sub Form_Load()
   Set CustomWB = New WBCustomizer
   With CustomWB
      .EnableContextMenus = False 'Disable The Menu
      .EnableAllAccelerators = True
      
      Set .WebBrowser = WebBrowser1
   End With
    WebBrowser1.Navigate "www.google.com"
        CustomWB.EnableContextMenus = False
End Sub

Grab all links on the page
This code shows how to grab and list all the links on a page, this can be used a spider software for a search engine site.
In order to get this code to load you must add the "Microsoft HTML Object Library" into your app refrences.


visual basic code:

Option Explicit
Private Sub Form_Load()
    WebBrowser1.Navigate "www.vbforums.com"
End Sub
Private Sub WebBrowser1_DownloadComplete()
    'you must add the "Microsoft HTML Object Library"!!!!!!!!!
    Dim HTMLdoc As HTMLDocument
        Dim HTMLlinks As HTMLAnchorElement
            Dim STRtxt As String
    ' List the links.
    On Error Resume Next
        Set HTMLdoc = WebBrowser1.Document
            For Each HTMLlinks In HTMLdoc.links
                STRtxt = STRtxt & HTMLlinks.href & vbCrLf
            Next HTMLlinks
        Text1.Text = STRtxt
End Sub


You can add this code in order to log this files.


visual basic code:

Open "C:\Documents and Settings\[YOU USERNAME]\Desktop\link log.txt" For Append As #1
Print #1, STRtxt
Close #1


Save Page
This code shows you how to save the browser's page.


visual basic code:

Option Explicit
Private Sub Command1_Click()
WebBrowser1.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_DODEFAULT
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate2 "www.google.com"
End Sub


Open Page
Here is how to load a webpage into the webbrowser.


visual basic code:

Private Sub Command2_Click()
    WebBrowser1.ExecWB OLECMDID_OPEN, OLECMDEXECOPT_PROMPTUSER
End Sub


This is how to open a page, using the comman dialog's way


visual basic code:

Option Explicit
Private Sub Command1_Click()
On Error Resume Next
    With CommonDialog1
        .DialogTitle = "Open File"
        .Filter = "Web page (*.htm;*.html) | *.htm;*.html|" & _
        "All Supported Picture formats|*.gif;*.tif;*.pcd;*.jpg;*.wmf;" & _
        "*.tga;*.jpeg;*.ras;*.png;*.eps;*.bmp;*.pcx|" & _
        "Text formats (*.txt;*.doc)|*.txt;*.doc|" & _
        "All files (*.*)|*.*|"
        .ShowOpen
        .Flags = 5
    WebBrowser1.Navigate2 .FileName
    End With
End Sub
Private Sub Form_Load()
    WebBrowser1.Navigate2 "www.google.com"
End Sub


Auto Submit
This Simple Code I Made To show you how to make a submittion form. This code will autofill the need filled and submit it.


visual basic code:

Private Sub Command1_Click()
Dim strwebsite As String
    Dim stremail As String
        strwebsite = "http://www.mysite.com"
            stremail = "myemail@host.com"
WebBrowser1.Document.addurl.URL.Value = strwebsite
    WebBrowser1.Document.addurl.Email.Value = stremail
        WebBrowser1.Document.addurl.Submit
End Sub
Private Sub Form_Load()
    WebBrowser1.Navigate "http://www.scrubtheweb.com/addurl.html"
End Sub


Using A ProgressBar With The Webbrowser
This is to show how to use a progressbar with a webbrowser control.


visual basic code:

Private Sub Form_Load()
    WebBrowser1.Navigate "www.msn.com"
    ProgressBar1.Appearance = ccFlat
    ProgressBar1.Scrolling = ccScrollingSmooth
End Sub

Private Sub WebBrowser1_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
On Error Resume Next
    If Progress = -1 Then ProgressBar1.Value = 100
        Me.Caption = "100%"
    If Progress > 0 And ProgressMax > 0 Then
        ProgressBar1.Value = Progress * 100 / ProgressMax
        Me.Caption = Int(Progress * 100 / ProgressMax) & "%"
    End If
    Exit Sub
End Sub


Setting a Control in a Webbrowser to focus
This shows how to set a control inside the webbrowser into focus.


visual basic code:

Private Sub Command1_Click()
    WebBrowser1.Document.All("q").focus 'Set the search text filed in focus
End Sub

Private Sub Command2_Click()
    WebBrowser1.Document.All("btnI").focus 'Set the google "I Am feeling lucky in focus button"
End Sub

Private Sub Form_Load()
    WebBrowser1.Navigate "http://www.google.com/"
End Sub



Or you can use:


visual basic code:

WebBrowser1.Document.getElementById("Object's Name").Focus


Checkbox in a page, how to control it
This is an example on how to check or uncheck the remember me checkbox on the google login page:


visual basic code:

Private Sub Form_Load()
WebBrowser1.Navigate "https://www.google.com/accounts/ManageAccount"
End Sub
Private Sub Check1_Click()
    If Check1.Value = 0 Then
        WebBrowser1.Document.All.PersistentCookie.Checked = False 'unchecked
    Else
        WebBrowser1.Document.All.PersistentCookie.Checked = True 'checked
    End If
End Sub


Or


visual basic code:

Private Sub Form_Load()
WebBrowser1.Navigate "https://www.google.com/accounts/ManageAccount"
End Sub
Private Sub Check1_Click()
    If Check1.Value = 0 Then
        WebBrowser1.Document.All.PersistentCookie.Checked = 0 'unchecked
    Else
        WebBrowser1.Document.All.PersistentCookie.Checked = 1 'checked
    End If
End Sub


Or


visual basic code:

Private Sub Form_Load()
WebBrowser1.Navigate "https://www.google.com/accounts/ManageAccount"
End Sub
Private Sub Check1_Click()
    If Check1.Value = 0 Then
        WebBrowser1.Document.getElementById("PersistentCookie").Checked = False 'unchecked
    Else
        WebBrowser1.Document.getElementById("PersistentCookie").Checked = True 'checked
    End If
End Sub


Custom Right Click Menu
This is an example show how to make your own custom right click menu. in order for this to work you must add the "Must Add Microsoft HTML Object Library" to your refrance.Also make your own custom menu using the menu editor I named my "mnu"
Please Note it will effect all the context menus in the webbrowser.


visual basic code:

'Must Add Microsoft HTML Object Library
Option Explicit
    Public WithEvents HTML As HTMLDocument

Private Function HTML_oncontextmenu() As Boolean
   HTML_oncontextmenu = False
   PopupMenu mnu '<---Check the mnu to your own menu name
End Function

Private Sub Form_Load()
    WebBrowser1.Navigate "www.google.com"
End Sub

Private Sub Form_Unload(Cancel As Integer)
   Set HTML = Nothing
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, _
                                                 URL As Variant)
   Set HTML = WebBrowser1.Document
End Sub

Copy the contents of the WebBrowser control to the Clipboard

To programmatically copy text from the WebBrowser control you can use its ExecWB method, to which you must pass the OLECMDID_COPY constant as its first argument.

WebBrowser1.ExecWB OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT
You can also select the entire WebBrowser's contents by invoking the ExecWB method with the OLECMDID_SELECTALL constant. For example, you can quickly copy the textual contents of the WebBrowser control (that is, plain text instead of HTML text) with the following statements:

' select the entire document WebBrowser1.ExecWB OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT ' copy the text to Clipboard WebBrowser1.ExecWB OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT ' clear the selection WebBrowser1.ExecWB OLECMDID_CLEARSELECTION, OLECMDEXECOPT_DONTPROMPTUSER


요청 개체 오류 'ASP 0104 : 80004005'

허용되지 않는 작업

/stock/RegStock.asp, 줄 2

 

이런 오류가 발생할때~~~~?????

 

========================================================

 

 

파일 형식때문에 오류가 나는게 아니구

 

파일 크기 때문에 오류가 나는거예요..^^

 

Server의 운영체제가 windows 2003 이시죠?

 

서비스에서 IIS Admin Service 를 중단하고 C:\winnt\system32\inetsrv 의

 

metabase.xml을 수정하세요...

 

주의할 점 : 꼭 IIS를 중단하고 수정할 것.

그렇지 않으면 AspMaxRequestEntityAllowed 이 값이 사라져서 한참을 고생하게 됩니다...

 

AspMaxRequestEntityAllowed

 

이부분을 204800 = 200kb (200 kb로 제한되어 있습니다.)

204800 * 5 (10MB가 되겠죠)

 

고친후 iis를 다시 시작하시면 됩니다...

 

[출처 : 네이버 지식인]

 

========================================================================

 

 

IIS 6 에서 ASP 에서 대용량 파일을 업로드시 403 오류 - KB327659

 

ASP(Active Server Pages) 요청을 사용하여 Microsoft 인터넷 정보 서비스(IIS) 5.0, Microsoft 인터넷 정보 서비스(IIS) 5.1 또는 Microsoft 인터넷 정보 서비스(IIS) 6.0이 설치된 컴퓨터에 큰 파일을 업로드하면 업로드가 실패할 수 있습니다. 또한 403 오류 응답이나 다음 중 하나와 유사한 오류 메시지가 나타날 수 있습니다.


오류 메시지 1

Request object error 'ASP 0104 : 80004005' 허용되지 않는 작업 :

 

 

오류 메시지 2

007~ASP 0104~허용되지 않는 작업

많은 폼 데이터를 ASP 페이지에 게시할 때 다음과 유사한 오류 메시지가 나타날 수 있습니다.

오류 ’80020009’ 예외가 발생했습니다.

또한 Response.binaryWrite 메서드를 사용할 때 파일 업로드가 실패할 수 있습니다.


이 문제는 Content-Length 헤더가 있고 Content-Length 헤더에서 IIS 메타베이스의 AspMaxRequestEntityAllowed 속성 값보다 큰 데이터 양을 지정하는 경우 발생합니다. AspMaxRequestEntityAllowed 속성의 기본값은 204,800바이트입니다.

 


해결 방법

cscript adsutil.vbs set w3svc/ASPMaxRequestEntityAllowed size

 

(*이 명령에서 size는 허용할 최대 파일 크기 업로드의 자리 표시자입니다. 최대값은 1,073,741,824바이트입니다. 이 값을 원하는 기능에 허용되는 최소값으로 설정하십시오.)

 

--> 업로드 컴포넌트의 성능에 따라서, 대용량 파일을 업로드 하면 웹서버측 메모리 과다 점유로 인해서 성능저하가 발생할 수 있으니 조심 스럽게 설정하는게 좋습니다.^^

이와 관련된 메타베이스 값으로 AspBufferingLimit 있습니다. 이 부분은 다운로드 버퍼링에 관련된 것으로 파일 링크를 막기 위해서 Asp 코드에 파일 쓰기후 다운로드 처리를 하는 경우가 많은데요,. 이때 대용량 파일 다운로드시에 지정된 크기 이상일 경우 오류가 발생하게 됩니다.

AspBufferingLimit : http://msdn.microsoft.com/library/default.asp?url=/library/
en-us/iissdk/html/ecfc3d4a-0178-45e8-89f8-304429b7fda5.asp

 

AspMaxRequestEntityAllowed 속성은 ASP 요청의 엔터티 본문에서 허용되는 최대 바이트 수를 지정합니다. Content-Length 헤더가 있고 Content-Length 헤더에서 AspMaxRequestEntityAllowed 속성 값보다 큰 데이터 양을 지정하는 경우 IIS에서 403 오류 응답을 반환합니다. AspMaxRequestEntityAllowed 속성은 PUT 요청과 POST 요청에만 적용되고, GET 요청에는 적용되지 않습니다. 이 메타베이스 속성이 ASP에만 적용되기 때문에 다른 ISAPI(인터넷 서버 API) 확장은 영향을 받지 않습니다.

 

AspMaxRequestEntityAllowed 속성은 MaxRequestEntityAllowed 속성의 기능과 관련되어 있습니다. 그러나 AspMaxRequestEntityAllowed 속성은 ASP 요청에만 적용됩니다. MaxRequestEntityAllowed 속성을 WWW 서비스(World Wide Web 게시 서비스) 수준에서 1MB로 설정할 수 있습니다. 그런 다음 특정 ASP 응용 프로그램에서 더 작은 양의 데이터를 처리하는 것을 알고 있는 경우 AspMaxRequestEntityAllowed 속성을 더 작은 값으로 설정할 수 있습니다.

 

--> ASP.NET 에서는 machine.config  또는 전역 web.config 및 각 웹사이트의 web.config 에서 지정할 수 있습니다.^^

스크랩원본글: http://www.serverinfo.pe.kr/TipnTech.aspx?Category=&Mode=View&KeyName=&KeyWord=&Page=&Seq=289

 

 

 

[출처웹사이트: 서버주무르기[Serverinfo.pe.kr]

 


' > ASP' 카테고리의 다른 글

IIS6 다운로드/업로드 크기제한  (0) 2015.09.20
ASP에서 UTF-8 처리 외 기타  (0) 2014.04.08
ASP DateAdd함수  (0) 2014.03.04

비주얼베이직 6.0  컴파일 할때 도움이 되는 링커

비쥬얼베이직 6.0 에서 exe를 만들려면 컴파일을 해야합니다.

그때 자체 컴파일을 하는것보다 이 링커를 쓰시면 
오류도 해결할수도있고 (vb6ko.dll) 을 필요없게 한다던지 여러가지 좋은점이 있습니다.


VB서비스링커.exe


 



※ VB Linker Helper의 특징:

 - VB6KO.DLL 요구하지 않게 패치 가능.

 - 일반 DLL 제작 가능.

 - 콘솔 응용 프로그램 제작 가능.

 - UPX/FSG 패커 내장 및 UPX 언팩 방지 기능.

 - 일반 링커가 수행하는 왠만한 기능 가능 (ImageBase 변경, MAP 파일 생성 등)

 - 링커 설정을 저장할 수 있음.

 - 비스타 이상의 PC에서 관리자 권한을 요구할 수 있음. (※ 기본 사항이 아니므로, 이 기능은 기본적으로 선택 해제되어 있음.)

 - 그 외 다수.

 

 ※ 설치 방법:

 첨부된 Setup.exe(알집 SFX) 파일을 실행 후 압축을 푸시면 됩니다.

파일 경로는 c:\ - program files - Microsoft Visual Studio - VB98 << 기본 설치 경로 
다른곳에설치하였다면 자기가 비쥬얼베이직을 설치한 경로에 압축을 풀어주세요

비주얼베이직 경로에 Link.exe를 넣고, 기존에 있던 Link.exe의 이름을 LiNKWIN.EXE로 변경해주세요.

그럼 정상적으로 작동될 것입니다.

 

[TIP]

EXE가 만들어 지지 않는다면?

- 포터블 버젼이다.

- 컴파일을 시도해보시고 exe를 만들어 보세요.

- 프로젝트 저장하기 해서 비베를 끈후 다시 그 프로젝트를 실행해 시도해보세요.



'응용프로그램 > Visual Basic' 카테고리의 다른 글

웹브라우저컨트롤  (0) 2014.06.16