Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

PB does OCXs: Web Browser example

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PB does OCXs: Web Browser example

    A little example of how to put a Web Browser in your DDT dialog.
    August 8, 2003: I have cleaned a little the code. There were some
    unneeded instructions that I forgot to remove.
    Code:
      #DIM ALL
      #INCLUDE "win32api.inc"
    
    
      %ID_OCX     = 1001
      %IDC_URL    = 1010
      %IDC_BTNAVG = 1011
      %IDC_BTBACK = 1012
      %IDC_BTFRWD = 1013
      %IDC_LABEL1 = 1014
    
      GLOBAL hDlg AS DWORD
      GLOBAL hOcx AS DWORD
      GLOBAL oOcx AS DISPATCH
    
    
      DECLARE FUNCTION AtlAxWinInit LIB "ATL.DLL" ALIAS "AtlAxWinInit" () AS LONG
    ' *********************************************************************************************
      DECLARE FUNCTION AtlAxWinTerm () AS LONG
    ' *********************************************************************************************
      FUNCTION AtlAxWinTerm () AS LONG
        UnregisterClass ("AtlAxWin", GetModuleHandle(BYVAL %NULL))
      END FUNCTION
    ' *********************************************************************************************
    ' **********************************************************************************************
      DECLARE FUNCTION AtlAxGetControl LIB "ATL.DLL" ALIAS "AtlAxGetControl" _
         ( _
         BYVAL hWnd AS DWORD, _   ' [in] A handle to the window that is hosting the control.
         BYREF pp AS DWORD _      ' [out] The IUnknown of the control being hosted.
      ) AS DWORD
    ' *********************************************************************************************
    
    ' *********************************************************************************************
    ' Puts the address of an object in a variant and marks it as containing a dispatch variable
    ' *********************************************************************************************
      SUB AtlMakeDispatch ( _
         BYVAL lpObj AS DWORD, _                        ' Address of the object instance
         BYREF vObj AS VARIANT _                        ' Variant to contain this address
         ) EXPORT
    
         LOCAL lpvObj AS VARIANTAPI PTR                 ' Pointer to a VARIANTAPI structure
         LET vObj = EMPTY                               ' Make sure is empty to avoid memory leaks
         lpvObj = VARPTR(vObj)                          ' Get the VARIANT address
         @lpvObj.vt = %VT_DISPATCH                      ' Mark it as containing a dispatch variable
         @lpvObj.vd.pdispVal = lpObj                    ' Set the dispatch pointer address
    
      END SUB
    ' *********************************************************************************************
    
    ' *********************************************************************************************
    ' Main dialog callback
    ' *********************************************************************************************
      CALLBACK FUNCTION MainDlgProc()
    
         LOCAL rc AS RECT
         LOCAL r AS LONG
         LOCAL x AS LONG
         LOCAL y AS LONG
         LOCAL xx AS LONG
         LOCAL yy AS LONG
    
    
         SELECT CASE CBMSG
    
            CASE %WM_SIZE
               GetClientRect CBHNDL, rc
               x = rc.nLeft
               y = rc.nTop
               xx = rc.nRight - rc.nLeft
               yy = rc.nBottom - rc.nTop - 32
               MoveWindow hOcx, x, y, xx, yy, %TRUE
    
            CASE %WM_DESTROY
               PostQuitMessage 0
    
            CASE %WM_COMMAND
               SELECT CASE CBCTL
                  CASE %IDCANCEL
                     IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                        DIALOG END CBHNDL, 0
                     END IF
                  CASE %IDC_BTNAVG
                     IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                        LOCAL strUrl AS STRING, vVar AS VARIANT
                        CONTROL GET TEXT CBHNDL, %IDC_URL TO strUrl
                        vVar = strUrl
                        OBJECT CALL oOcx.Navigate(vVar)
                     END IF
                  CASE %IDC_BTBACK
                     IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                        OBJECT CALL oOcx.GoBack
                     END IF
                  CASE %IDC_BTFRWD
                     IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                        OBJECT CALL oOcx.GoForward
                     END IF
               END SELECT
    
         END SELECT
    
      END FUNCTION
    ' *********************************************************************************************
    
    ' *********************************************************************************************
    ' Main
    ' *********************************************************************************************
      FUNCTION PBMAIN
    
         LOCAL hInst AS DWORD
         LOCAL hr AS DWORD
         LOCAL OcxName AS ASCIIZ * 255
         LOCAL pUnk AS DWORD
         LOCAL vVar AS VARIANT
         LOCAL uMsg AS tagMsg
    
         OcxName = "Shell.Explorer"
    
         AtlAxWinInit   ' // Initializes ATL
    
         DIALOG NEW 0, "A Web Browser in a DDT dialog",,, 528, 334, %WS_OVERLAPPEDWINDOW, 0 TO hDlg
         CONTROL ADD "AtlAxWin", hDlg, %ID_OCX, OcxName, 0, 0, 0, 0, %WS_VISIBLE OR %WS_CHILD
         CONTROL HANDLE hDlg, %ID_OCX TO hOcx
         CONTROL ADD LABEL, hDlg, %IDC_LABEL1, "URL", 226, 322, 16, 12
         CONTROL ADD TEXTBOX, hDlg, %IDC_URL, "", 250, 320, 210, 14
         CONTROL ADD BUTTON, hDlg, %IDC_BTNAVG, "&Navigate", 470, 320, 46, 14, %WS_TABSTOP OR %BS_DEFAULT
         CONTROL ADD BUTTON, hDlg, %IDC_BTBACK, "&Back", 5, 320, 46, 14, %WS_TABSTOP
         CONTROL ADD BUTTON, hDlg, %IDC_BTFRWD, "&Forward", 58, 320, 46, 14, %WS_TABSTOP
         CONTROL SET TEXT hDlg, %IDC_URL, "http://www.powerbasic.com"
    
         AtlAxGetControl(hOcx, pUnk)
         AtlMakeDispatch(pUnk, vVar)
         SET oOcx = vVar
    
         SetFocus(hOcx)
         DIALOG SHOW MODAL hDlg, CALL MainDlgProc TO hr
    
         AtlAxWinTerm   ' // Uninitializes ATL
         SET oOcx = NOTHING
    
      END FUNCTION
    ' *********************************************************************************************
    ------------------


    [This message has been edited by JOSE ROCA (edited August 07, 2003).]

  • #2
    Nice!

    But your controls are not moving when you resize the window ...

    ------------------
    Kind Regards
    Mike

    Comment


    • #3
      Originally posted by Mike Trader:
      Nice!

      But your controls are not moving when you resize the window ...

      Who cares really ??

      Beautifull, first time I see a 'real' live html page full layout
      in an PB window. Just Lovely !!!

      Thanks Jose !!!



      ------------------
      You gotta run, and don't loop back.
      You gotta run, and don't loop back.

      Comment


      • #4
        The same example with events added. In the function
        ShellWebBrowser_NavigateComplete2, that receives the notification
        of the NavigateComplete2 event, I have added the instruction
        Code:
             CONTROL SET TEXT hDlg, %IDC_URL, VARIANT$(vURL)
        to show the location URL.

        There is also remed example code to show how you can obtain the
        location name:
        Code:
             ' // To get the location name:
        '     local vLocName as variant
        '     object get oOcx.LocationName to vLocName
        '     CONTROL SET TEXT hDlg, %IDC_URL, VARIANT$(vLocName)
        The needed class to implement a Dispatch interface and the functions
        to subscribe and unsubscribe to the events, as well as the indivual
        functions to deal with every event has been generated by the
        TypeLib Viewer 1.04. For this example, I have retained only the
        events for the WebBrowser interface. The only code that you have
        really to write is:
        Code:
             '// Subscribe to the WebBroser events
             hr = ShellWebBrowser_SetEvents(OBJPTR(oOcx), dwCookie)
        
             ......
             ......
        
             ' // Unsubscribe from the WebBrowser events
             hr = ShellWebBrowser_ReleaseEvents(OBJPTR(oOcx), dwCookie)
        ...and, of course, the code that you will want to add in each function
        to react to the events fired by the control.
        Code:
        '
        ' -------------------------------------------------------------------
        '
          #DIM ALL
          #INCLUDE "win32api.inc"
        
        
          %ID_OCX     = 1001
          %IDC_URL    = 1010
          %IDC_BTNAVG = 1011
          %IDC_BTBACK = 1012
          %IDC_BTFRWD = 1013
          %IDC_LABEL1 = 1014
        
          GLOBAL hDlg AS DWORD
          GLOBAL hOcx AS DWORD
          GLOBAL oOcx AS DISPATCH
        
        
        ' --------------------------------------------------------------------------------------------
        ' CoClass: WebBrowser
        ' GUID: {8856F961-340A-11D0-A96B-00C04FD705A2}
        ' --------------------------------------------------------------------------------------------
        ' Default event interface: DWebBrowserEvents2
        ' Default interface IID: {34A715A0-6587-11D0-924A-0020AFC7AC4D}
        ' --------------------------------------------------------------------------------------------
        
        ' StatusTextChange                        DispId: &H00000066 (102)
        ' ProgressChange                          DispId: &H0000006C (108)
        ' CommandStateChange                      DispId: &H00000069 (105)
        ' DownloadBegin                           DispId: &H0000006A (106)
        ' DownloadComplete                        DispId: &H00000068 (104)
        ' TitleChange                             DispId: &H00000071 (113)
        ' PropertyChange                          DispId: &H00000070 (112)
        ' BeforeNavigate2                         DispId: &H000000FA (250)
        ' NewWindow2                              DispId: &H000000FB (251)
        ' NavigateComplete2                       DispId: &H000000FC (252)
        ' DocumentComplete                        DispId: &H00000103 (259)
        ' OnQuit                                  DispId: &H000000FD (253)
        ' OnVisible                               DispId: &H000000FE (254)
        ' OnToolBar                               DispId: &H000000FF (255)
        ' OnMenuBar                               DispId: &H00000100 (256)
        ' OnStatusBar                             DispId: &H00000101 (257)
        ' OnFullScreen                            DispId: &H00000102 (258)
        ' OnTheaterMode                           DispId: &H00000104 (260)
        ' WindowSetResizable                      DispId: &H00000106 (262)
        ' WindowSetLeft                           DispId: &H00000108 (264)
        ' WindowSetTop                            DispId: &H00000109 (265)
        ' WindowSetWidth                          DispId: &H0000010A (266)
        ' WindowSetHeight                         DispId: &H0000010B (267)
        ' WindowClosing                           DispId: &H00000107 (263)
        ' ClientToHostWindow                      DispId: &H0000010C (268)
        ' SetSecureLockIcon                       DispId: &H0000010D (269)
        ' FileDownload                            DispId: &H0000010E (270)
        ' NavigateError                           DispId: &H0000010F (271)
        ' PrintTemplateInstantiation              DispId: &H000000E1 (225)
        ' PrintTemplateTeardown                   DispId: &H000000E2 (226)
        ' UpdatePageStatus                        DispId: &H000000E3 (227)
        ' PrivacyImpactedStateChange              DispId: &H00000110 (272)
        
        ' --------------------------------------------------------------------------------------------
        ' EXCEPINFO structure
        ' --------------------------------------------------------------------------------------------
        
          TYPE EXCEPINFO
             wCode AS WORD               ' // An error code describing the error.
             wReserved AS WORD
             bstrSource AS DWORD         ' // Source of the exception.
             bstrDescription AS DWORD    ' // Textual description of the error.
             bstrHelpFile AS DWORD       ' // Help file path.
             dwHelpContext AS DWORD      ' // Help context ID.
             pvReserved AS DWORD
             pfnDeferredFillIn AS DWORD  ' // Pointer to a function that takes an EXCEPINFO structure as an argument and returns an HRESULT value.
             scode AS DWORD              ' // A return value describing the error.
          END TYPE
        
        ' --------------------------------------------------------------------------------------------
        ' IDispatchVTable
        ' --------------------------------------------------------------------------------------------
          TYPE IDispatchVTable
             pQueryInterface AS DWORD     ' Returns pointers to supported interfaces.
             pAddRef AS DWORD             ' Increments reference count.
             pRelease AS DWORD            ' Decrements reference count.
             pGetTypeInfoCount AS DWORD   ' Retrieves the number of type descriptions.
             pGetTypeInfo AS DWORD        ' Retrieves a description of object's programmable interface.
             pGetIDsOfNames AS DWORD      ' Maps name of method or property to DispId.
             pInvoke AS DWORD             ' Calls one of the object's methods, or gets/sets one of its properties.
          END TYPE
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' UI4 Release()
        ' --------------------------------------------------------------------------------------------
        
          DECLARE FUNCTION Proto_ShellWebBrowser_Release (BYVAL pThis AS DWORD) AS DWORD
        
          FUNCTION ShellWebBrowser_Release (BYVAL pUnk AS DWORD) AS DWORD
             LOCAL HRESULT AS DWORD
             LOCAL ppunk AS DWORD PTR
             LOCAL pvtbl AS DWORD PTR
             LOCAL ppmethod AS DWORD PTR
             LOCAL pmethod AS DWORD
             ppunk = pUnk
             pvtbl = @ppunk
             ppmethod = pvtbl + 8
             pmethod = @ppmethod
             CALL DWORD pmethod USING Proto_ShellWebBrowser_Release(pUnk) TO HRESULT
             FUNCTION = HRESULT
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' HRESULT QueryInterface([in] *GUID riid, [out] **VOID ppvObj)
        ' --------------------------------------------------------------------------------------------
        
          DECLARE FUNCTION Proto_ShellWebBrowser_IConnectionPointContainer_QueryInterface (BYVAL pUnk AS DWORD, BYREF riid AS GUID, BYREF ppvObj AS DWORD) AS DWORD
        
          FUNCTION ShellWebBrowser_IConnectionPointContainer_QueryInterface (BYVAL pUnk AS DWORD, BYREF riid AS GUID, BYREF ppvObj AS DWORD) AS DWORD
             LOCAL HRESULT AS DWORD
             LOCAL ppunk AS DWORD PTR
             LOCAL pvtbl AS DWORD PTR
             LOCAL ppmethod AS DWORD PTR
             LOCAL pmethod AS DWORD
             ppunk = pUnk
             pvtbl = @ppunk
             ppmethod = pvtbl
             pmethod = @ppmethod
             CALL DWORD pmethod USING Proto_ShellWebBrowser_IConnectionPointContainer_QueryInterface(pUnk,riid,ppvObj) TO HRESULT
             FUNCTION = HRESULT
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' HRESULT FindConnectionPoint([in] *GUID riid, [out] **VOID ppCP)
        ' --------------------------------------------------------------------------------------------
        
          DECLARE FUNCTION Proto_ShellWebBrowser_IConnectionPointContainer_FindConnectionPoint (BYVAL pUnk AS DWORD, BYREF riid AS GUID, BYREF ppCP AS DWORD) AS DWORD
        
          FUNCTION ShellWebBrowser_IConnectionPointContainer_FindConnectionPoint (BYVAL pUnk AS DWORD, BYREF riid AS GUID, BYREF ppCP AS DWORD) AS DWORD
             LOCAL HRESULT AS DWORD
             LOCAL ppunk AS DWORD PTR
             LOCAL pvtbl AS DWORD PTR
             LOCAL ppmethod AS DWORD PTR
             LOCAL pmethod AS DWORD
             ppunk = pUnk
             pvtbl = @ppunk
             ppmethod = pvtbl + 16
             pmethod = @ppmethod
             CALL DWORD pmethod USING Proto_ShellWebBrowser_IConnectionPointContainer_FindConnectionPoint(pUnk,riid,ppCP) TO HRESULT
             FUNCTION = HRESULT
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' HRESULT Advise([in] *IUNKNOWN pSink, [out] *DWORD pdwCookie)
        ' --------------------------------------------------------------------------------------------
        
          DECLARE FUNCTION Proto_ShellWebBrowser_IConnectionPoint_Advise (BYVAL pUnk AS DWORD, BYVAL pSink AS DWORD, BYREF pReturn AS DWORD) AS DWORD
        
          FUNCTION ShellWebBrowser_IConnectionPoint_Advise (BYVAL pUnk AS DWORD, BYVAL pSink AS DWORD, BYREF pdwCookie AS DWORD) AS DWORD
             LOCAL pReturn AS DWORD
             LOCAL HRESULT AS DWORD
             LOCAL ppunk AS DWORD PTR
             LOCAL pvtbl AS DWORD PTR
             LOCAL ppmethod AS DWORD PTR
             LOCAL pmethod AS DWORD
             ppunk = pUnk
             pvtbl = @ppunk
             ppmethod = pvtbl + 20
             pmethod = @ppmethod
             CALL DWORD pmethod USING Proto_ShellWebBrowser_IConnectionPoint_Advise(pUnk,pSink,pReturn) TO HRESULT
             pdwCookie = pReturn
             FUNCTION = HRESULT
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        '  HRESULT Unadvise([in] DWORD dwCookie)
        ' --------------------------------------------------------------------------------------------
        
          DECLARE FUNCTION Proto_ShellWebBrowser_IConnectionPoint_Unadvise (BYVAL pUnk AS DWORD, BYVAL pdwCookie AS DWORD) AS DWORD
        
          FUNCTION ShellWebBrowser_IConnectionPoint_Unadvise (BYVAL pUnk AS DWORD, BYVAL dwCookie AS DWORD) AS DWORD
             LOCAL HRESULT AS DWORD
             LOCAL ppunk AS DWORD PTR
             LOCAL pvtbl AS DWORD PTR
             LOCAL ppmethod AS DWORD PTR
             LOCAL pmethod AS DWORD
             ppunk = pUnk
             pvtbl = @ppunk
             ppmethod = pvtbl + 24
             pmethod = @ppmethod
             CALL DWORD pmethod USING Proto_ShellWebBrowser_IConnectionPoint_Unadvise(pUnk,dwCookie) TO HRESULT
             FUNCTION = HRESULT
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Builds the IDispatch VTable
        ' --------------------------------------------------------------------------------------------
        
          SUB ShellWebBrowser_IDispatch_BuildVTable (Vt AS IDispatchVTable)
             Vt.pQueryInterface   = CODEPTR(ShellWebBrowser_IDispatch_QueryInterface)
             Vt.pAddRef           = CODEPTR(ShellWebBrowser_IDispatch_AddRef)
             Vt.pRelease          = CODEPTR(ShellWebBrowser_IDispatch_Release)
             Vt.pGetTypeInfoCount = CODEPTR(ShellWebBrowser_IDispatch_GetTypeInfoCount)
             Vt.pGetTypeInfo      = CODEPTR(ShellWebBrowser_IDispatch_GetTypeInfo)
             Vt.pGetIDsOfNames    = CODEPTR(ShellWebBrowser_IDispatch_GetIDsOfNames)
             Vt.pInvoke           = CODEPTR(ShellWebBrowser_IDispatch_Invoke)
          END SUB
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' UI4 AddRef()
        ' --------------------------------------------------------------------------------------------
        
          FUNCTION ShellWebBrowser_IDispatch_AddRef (BYVAL pUnk AS DWORD) AS DWORD
             FUNCTION = %S_OK
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' UI4 Release()
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_IDispatch_Release (BYVAL pUnk AS DWORD) AS DWORD
             FUNCTION = %S_OK
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' HRESULT QueryInterface([in] *GUID riid, [out] **VOID ppvObj)
        ' --------------------------------------------------------------------------------------------
        
          FUNCTION ShellWebBrowser_IDispatch_QueryInterface (BYVAL pUnk AS DWORD, BYREF riid AS GUID, BYREF ppvObj AS DWORD) AS DWORD
             STATIC pSink AS DWORD
             STATIC Vtbl AS IDispatchVTable
             ShellWebBrowser_IDispatch_BuildVTable(Vtbl)
             pSink = VARPTR(VTbl)
             ppvObj = VARPTR(pSink)
             ShellWebBrowser_IDispatch_AddRef(pUnk)
             FUNCTION = %S_OK
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' HRESULT GetTypeInfoCount([out] *UINT pctinfo)
        ' --------------------------------------------------------------------------------------------
        
          FUNCTION ShellWebBrowser_IDispatch_GetTypeInfoCount (BYVAL pUnk AS DWORD, BYREF pctInfo AS DWORD) AS DWORD
             FUNCTION = %E_NOTIMPL
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' HRESULT GetTypeInfo([in] UINT itinfo, [in] UI4 lcid, [out] **VOID pptinfo)
        ' --------------------------------------------------------------------------------------------
        
          FUNCTION ShellWebBrowser_IDispatch_GetTypeInfo (BYVAL pUnk AS DWORD, BYVAL itinfo AS DWORD, BYVAL lcid AS DWORD, BYREF pptinfo AS DWORD) AS DWORD
             FUNCTION = %E_NOTIMPL
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' HRESULT GetIDsOfNames([in] *GUID riid, [in] **I1 rgszNames, [in] UINT cNames, [in] UI4 lcid, [out] *I4 rgdispid)
        ' --------------------------------------------------------------------------------------------
        
          FUNCTION ShellWebBrowser_IDispatch_GetIDsOfNames (BYVAL pUnk AS DWORD, BYREF riid AS GUID, BYVAL rgszNames AS DWORD, BYVAL cNames AS DWORD, BYVAL lcid AS DWORD, BYREF rgdispid AS LONG) AS DWORD
             FUNCTION = %E_NOTIMPL
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Establishes a connection between the connection point object and the client's sink.
        ' Returns a token that uniquely identifies this connection.
        ' --------------------------------------------------------------------------------------------
        
          FUNCTION ShellWebBrowser_SetEvents (BYVAL pUnk AS DWORD, BYREF pdwCookie AS DWORD) AS DWORD
        
             LOCAL hr AS DWORD        ' HRESULT
             LOCAL pCPC AS DWORD      ' IConnectionPointContainer
             LOCAL pCP AS DWORD       ' IConnectionPoint
             LOCAL IID_CPC AS GUID    ' IID_IConnectionPointContainer
             LOCAL IID_CP AS GUID     ' MSHFlexGrid events dispinterface
             LOCAL pSink AS DWORD     ' Pointer to our sink interface
             LOCAL dwCookie AS DWORD  ' Returned token
             STATIC VTbl AS IDispatchVTable
        
             IID_CPC = GUID$(" {B196B284-BAB4-101A-B69C-00AA00341D07}")
             IID_CP  = GUID$("{34A715A0-6587-11D0-924A-0020AFC7AC4D}")
        
             hr = ShellWebBrowser_IConnectionPointContainer_QueryInterface(pUnk, IID_CPC, pCPC)
             IF hr <> %S_OK THEN
                FUNCTION = hr
                EXIT FUNCTION
             END IF
        
             hr = ShellWebBrowser_IConnectionPointContainer_FindConnectionPoint(pCPC, IID_CP, pCP)
             ShellWebBrowser_Release(pCPC)
             IF hr <> %S_OK THEN
                FUNCTION = hr
                EXIT FUNCTION
             END IF
        
             ShellWebBrowser_IDispatch_BuildVTable(VTbl)
             pSink = VARPTR(VTbl)
             hr = ShellWebBrowser_IConnectionPoint_Advise(pCP, BYVAL VARPTR(pSink), dwCookie)
        
             pdwCookie = dwCookie
             ShellWebBrowser_Release(pCP)
             FUNCTION = hr
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        
          FUNCTION ShellWebBrowser_ReleaseEvents (BYVAL pUnk AS DWORD, BYVAL dwCookie AS DWORD) AS DWORD
        
             LOCAL hr AS DWORD        ' HRESULT
             LOCAL pCPC AS DWORD      ' IConnectionPointContainer
             LOCAL pCP AS DWORD       ' IConnectionPoint
             LOCAL IID_CPC AS GUID    ' IID_IConnectionPointContainer
             LOCAL IID_CP AS GUID     ' ConnectionEvents dispinterface
        
             IID_CPC = GUID$(" {B196B284-BAB4-101A-B69C-00AA00341D07}")
             IID_CP  = GUID$("{34A715A0-6587-11D0-924A-0020AFC7AC4D}")
        
             hr = ShellWebBrowser_IConnectionPointContainer_QueryInterface(pUnk, IID_CPC, pCPC)
             IF hr <> %S_OK THEN
                FUNCTION = hr
                EXIT FUNCTION
             END IF
        
             hr = ShellWebBrowser_IConnectionPointContainer_FindConnectionPoint(pCPC, IID_CP, pCP)
             ShellWebBrowser_Release(pCPC)
             IF hr <> %S_OK THEN
                FUNCTION = hr
                EXIT FUNCTION
             END IF
        
             hr = ShellWebBrowser_IConnectionPoint_Unadvise(pCP, dwCookie)
             ShellWebBrowser_Release(pCP)
             FUNCTION = hr
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' ********************************************************************************************
        ' OnEvent Functions
        ' ********************************************************************************************
        
        ' --------------------------------------------------------------------------------------------
        ' Statusbar text changed.
        ' DispId: &H00000066 (102)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' Text                                STRING    BYVAL  [flags: 1] [in]  '[VT_BSTR] (8)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_StatusTextChange (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL bstrText AS STRING
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             bstrText = VARIANT$(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when download progress is updated.
        ' DispId: &H0000006C (108)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' Progress                            LONG      BYVAL  [flags: 1] [in]  '[VT_I4] (3)
        ' ProgressMax                         LONG      BYVAL  [flags: 1] [in]  '[VT_I4] (3)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_ProgressChange (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL i4Progress AS LONG
             LOCAL i4ProgressMax AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             i4Progress = VARIANT#(@pv[1])
             i4ProgressMax = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' The enabled state of a command changed.
        ' DispId: &H00000069 (105)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' Command                             LONG      BYVAL  [flags: 1] [in]  '[VT_I4] (3)
        ' Enable                              LONG      BYVAL  [flags: 1] [in]  '[VT_BOOL] (11)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_CommandStateChange (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL i4Command AS LONG
             LOCAL bEnable AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             i4Command = VARIANT#(@pv[1])
             bEnable = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Download of a page started.
        ' DispId: &H0000006A (106)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_DownloadBegin (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Download of page complete.
        ' DispId: &H00000068 (104)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_DownloadComplete (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Document title changed.
        ' DispId: &H00000071 (113)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' Text                                STRING    BYVAL  [flags: 1] [in]  '[VT_BSTR] (8)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_TitleChange (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL bstrText AS STRING
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             bstrText = VARIANT$(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when the PutProperty method has been called.
        ' DispId: &H00000070 (112)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' szProperty                          STRING    BYVAL  [flags: 1] [in]  '[VT_BSTR] (8)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_PropertyChange (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL bstrszProperty AS STRING
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             bstrszProperty = VARIANT$(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired before navigate occurs in the given WebBrowser (window or frameset element). The processing of this navigation may be modified.
        ' DispId: &H000000FA (250)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' pDisp                               DWORD     BYVAL  [flags: 1] [in]  '[VT_DISPATCH] (9)
        ' URL                                 VARIANT   BYREF  [flags: 1] [in]  '[VT_VARIANT] (12)
        ' Flags                               VARIANT   BYREF  [flags: 1] [in]  '[VT_VARIANT] (12)
        ' TargetFrameName                     VARIANT   BYREF  [flags: 1] [in]  '[VT_VARIANT] (12)
        ' PostData                            VARIANT   BYREF  [flags: 1] [in]  '[VT_VARIANT] (12)
        ' Headers                             VARIANT   BYREF  [flags: 1] [in]  '[VT_VARIANT] (12)
        ' Cancel                              LONG      BYREF  [flags: 3] [out]  '[VT_BOOL] (11)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_BeforeNavigate2 (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL ui4pDisp AS DWORD
             LOCAL vURL AS VARIANT
             LOCAL vFlags AS VARIANT
             LOCAL vTargetFrameName AS VARIANT
             LOCAL vPostData AS VARIANT
             LOCAL vHeaders AS VARIANT
             LOCAL bCancel AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             ui4pDisp = VARIANT#(@pv[6])
             vURL = @pv[5]
             vFlags = @pv[4]
             vTargetFrameName = @pv[3]
             vPostData = @pv[2]
             vHeaders = @pv[1]
             bCancel = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' A new, hidden, non-navigated WebBrowser window is needed.
        ' DispId: &H000000FB (251)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' ppDisp                              DWORD     BYREF  [flags: 3] [out]  '[VT_DISPATCH] (9)
        ' Cancel                              LONG      BYREF  [flags: 3] [out]  '[VT_BOOL] (11)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_NewWindow2 (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL ui4ppDisp AS DWORD
             LOCAL bCancel AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             ui4ppDisp = VARIANT#(@pv[1])
             bCancel = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when the document being navigated to becomes visible and enters the navigation stack.
        ' DispId: &H000000FC (252)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' pDisp                               DWORD     BYVAL  [flags: 1] [in]  '[VT_DISPATCH] (9)
        ' URL                                 VARIANT   BYREF  [flags: 1] [in]  '[VT_VARIANT] (12)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_NavigateComplete2 (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL ui4pDisp AS DWORD
             LOCAL vURL AS VARIANT
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             ui4pDisp = VARIANT#(@pv[1])
             vURL = @pv[0]
        
             ' *** Put your code here ***
             CONTROL SET TEXT hDlg, %IDC_URL, VARIANT$(vURL)
        
        '     // To get the location name:
        '     LOCAL vLocName AS VARIANT
        '     OBJECT GET oOcx.LocationName TO vLocName
        '     CONTROL SET TEXT hDlg, %IDC_URL, VARIANT$(vLocName)
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when the document being navigated to reaches ReadyState_Complete.
        ' DispId: &H00000103 (259)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' pDisp                               DWORD     BYVAL  [flags: 1] [in]  '[VT_DISPATCH] (9)
        ' URL                                 VARIANT   BYREF  [flags: 1] [in]  '[VT_VARIANT] (12)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_DocumentComplete (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL ui4pDisp AS DWORD
             LOCAL vURL AS VARIANT
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             ui4pDisp = VARIANT#(@pv[1])
             vURL = @pv[0]
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when application is quiting.
        ' DispId: &H000000FD (253)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_OnQuit (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when the window should be shown/hidden
        ' DispId: &H000000FE (254)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' Visible                             LONG      BYVAL  [flags: 1] [in]  '[VT_BOOL] (11)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_OnVisible (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL bVisible AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             bVisible = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when the toolbar  should be shown/hidden
        ' DispId: &H000000FF (255)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' ToolBar                             LONG      BYVAL  [flags: 1] [in]  '[VT_BOOL] (11)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_OnToolBar (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL bToolBar AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             bToolBar = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when the menubar should be shown/hidden
        ' DispId: &H00000100 (256)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' MenuBar                             LONG      BYVAL  [flags: 1] [in]  '[VT_BOOL] (11)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_OnMenuBar (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL bMenuBar AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             bMenuBar = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when the statusbar should be shown/hidden
        ' DispId: &H00000101 (257)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' StatusBar                           LONG      BYVAL  [flags: 1] [in]  '[VT_BOOL] (11)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_OnStatusBar (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL bStatusBar AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             bStatusBar = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when fullscreen mode should be on/off
        ' DispId: &H00000102 (258)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' FullScreen                          LONG      BYVAL  [flags: 1] [in]  '[VT_BOOL] (11)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_OnFullScreen (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL bFullScreen AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             bFullScreen = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when theater mode should be on/off
        ' DispId: &H00000104 (260)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' TheaterMode                         LONG      BYVAL  [flags: 1] [in]  '[VT_BOOL] (11)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_OnTheaterMode (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL bTheaterMode AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             bTheaterMode = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when the host window should allow/disallow resizing
        ' DispId: &H00000106 (262)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' Resizable                           LONG      BYVAL  [flags: 1] [in]  '[VT_BOOL] (11)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_WindowSetResizable (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL bResizable AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             bResizable = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when the host window should change its Left coordinate
        ' DispId: &H00000108 (264)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' Left                                LONG      BYVAL  [flags: 1] [in]  '[VT_I4] (3)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_WindowSetLeft (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL i4Left AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             i4Left = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when the host window should change its Top coordinate
        ' DispId: &H00000109 (265)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' Top                                 LONG      BYVAL  [flags: 1] [in]  '[VT_I4] (3)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_WindowSetTop (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL i4Top AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             i4Top = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when the host window should change its width
        ' DispId: &H0000010A (266)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' Width                               LONG      BYVAL  [flags: 1] [in]  '[VT_I4] (3)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_WindowSetWidth (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL i4Width AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             i4Width = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when the host window should change its height
        ' DispId: &H0000010B (267)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' Height                              LONG      BYVAL  [flags: 1] [in]  '[VT_I4] (3)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_WindowSetHeight (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL i4Height AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             i4Height = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when the WebBrowser is about to be closed by script
        ' DispId: &H00000107 (263)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' IsChildWindow                       LONG      BYVAL  [flags: 1] [in]  '[VT_BOOL] (11)
        ' Cancel                              LONG      BYREF  [flags: 3] [out]  '[VT_BOOL] (11)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_WindowClosing (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL bIsChildWindow AS LONG
             LOCAL bCancel AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             bIsChildWindow = VARIANT#(@pv[1])
             bCancel = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired to request client sizes be converted to host window sizes
        ' DispId: &H0000010C (268)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' CX                                  LONG      BYREF  [flags: 3] [out]  '[VT_I4] (3)
        ' CY                                  LONG      BYREF  [flags: 3] [out]  '[VT_I4] (3)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_ClientToHostWindow (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL i4CX AS LONG
             LOCAL i4CY AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             i4CX = VARIANT#(@pv[1])
             i4CY = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired to indicate the security level of the current web page contents
        ' DispId: &H0000010D (269)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' SecureLockIcon                      LONG      BYVAL  [flags: 1] [in]  '[VT_I4] (3)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_SetSecureLockIcon (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL i4SecureLockIcon AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             i4SecureLockIcon = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired to indicate the File Download dialog is opening
        ' DispId: &H0000010E (270)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' Cancel                              LONG      BYREF  [flags: 3] [out]  '[VT_BOOL] (11)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_FileDownload (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL bCancel AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             bCancel = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when a binding error occurs (window or frameset element).
        ' DispId: &H0000010F (271)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' pDisp                               DWORD     BYVAL  [flags: 1] [in]  '[VT_DISPATCH] (9)
        ' URL                                 VARIANT   BYREF  [flags: 1] [in]  '[VT_VARIANT] (12)
        ' Frame                               VARIANT   BYREF  [flags: 1] [in]  '[VT_VARIANT] (12)
        ' StatusCode                          VARIANT   BYREF  [flags: 1] [in]  '[VT_VARIANT] (12)
        ' Cancel                              LONG      BYREF  [flags: 3] [out]  '[VT_BOOL] (11)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_NavigateError (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL ui4pDisp AS DWORD
             LOCAL vURL AS VARIANT
             LOCAL vFrame AS VARIANT
             LOCAL vStatusCode AS VARIANT
             LOCAL bCancel AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             ui4pDisp = VARIANT#(@pv[4])
             vURL = @pv[3]
             vFrame = @pv[2]
             vStatusCode = @pv[1]
             bCancel = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when a print template is instantiated.
        ' DispId: &H000000E1 (225)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' pDisp                               DWORD     BYVAL  [flags: 1] [in]  '[VT_DISPATCH] (9)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_PrintTemplateInstantiation (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL pDisp AS DWORD
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             pDisp = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when a print template destroyed.
        ' DispId: &H000000E2 (226)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' pDisp                               DWORD     BYVAL  [flags: 1] [in]  '[VT_DISPATCH] (9)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_PrintTemplateTeardown (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL pDisp AS DWORD
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             pDisp = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when a page is spooled. When it is fired can be changed by a custom template.
        ' DispId: &H000000E3 (227)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' pDisp                               DWORD     BYVAL  [flags: 1] [in]  '[VT_DISPATCH] (9)
        ' nPage                               VARIANT   BYREF  [flags: 1] [in]  '[VT_VARIANT] (12)
        ' fDone                               VARIANT   BYREF  [flags: 1] [in]  '[VT_VARIANT] (12)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_UpdatePageStatus (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL ui4pDisp AS DWORD
             LOCAL vnPage AS VARIANT
             LOCAL vfDone AS VARIANT
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             ui4pDisp = VARIANT#(@pv[2])
             vnPage = @pv[1]
             vfDone = @pv[0]
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' Fired when the global privacy impacted state changes
        ' DispId: &H00000110 (272)
        ' --------------------------------------------------------------------------------------------
        ' Parameters:
        ' bImpacted                           LONG      BYVAL  [flags: 1] [in]  '[VT_BOOL] (11)
        ' --------------------------------------------------------------------------------------------
          FUNCTION ShellWebBrowser_PrivacyImpactedStateChange (BYVAL pUnk AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
        
             LOCAL pv AS VARIANT PTR
             LOCAL bbImpacted AS LONG
        
             ' // Parameters in DISPPARAMS are zero based and in reverse order.
             pv = pdispparams.VariantArgs
             bbImpacted = VARIANT#(@pv[0])
        
             ' *** Put your code here ***
        
             FUNCTION = %S_OK
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        ' --------------------------------------------------------------------------------------------
        ' HRESULT Invoke([in] I4 dispidMember, [in] *GUID riid, [in] UI4 lcid, [in] UI2 wFlags, [in] *DISPPARAMS pdispparams, [out] *VARIANT pvarResult, [out] *EXCEPINFO pexcepinfo, [out] *UINT puArgErr)
        ' --------------------------------------------------------------------------------------------
        
          FUNCTION ShellWebBrowser_IDispatch_Invoke (BYVAL pUnk AS DWORD, BYVAL dispidMember AS LONG, BYREF riid AS GUID, _
          BYVAL lcid AS DWORD, BYVAL wFlags AS WORD, BYREF pdispparams AS DISPPARAMS, BYREF pvarResult AS VARIANT, _
          BYREF pexcepinfo AS EXCEPINFO, BYREF puArgErr AS DWORD) AS DWORD
        
             FUNCTION = %S_OK
        
             IF VARPTR(pdispparams) THEN
        
                SELECT CASE AS LONG dispidMember
        
                   CASE &H66  ' (102)  ' // StatusTextChange
                      FUNCTION = ShellWebBrowser_StatusTextChange(pUnk, pdispparams)
        
                   CASE &H6C  ' (108)  ' // ProgressChange
                      FUNCTION = ShellWebBrowser_ProgressChange(pUnk, pdispparams)
        
                   CASE &H69  ' (105)  ' // CommandStateChange
                      FUNCTION = ShellWebBrowser_CommandStateChange(pUnk, pdispparams)
        
                   CASE &H6A  ' (106)  ' // DownloadBegin
                      FUNCTION = ShellWebBrowser_DownloadBegin(pUnk, pdispparams)
        
                   CASE &H68  ' (104)  ' // DownloadComplete
                      FUNCTION = ShellWebBrowser_DownloadComplete(pUnk, pdispparams)
        
                   CASE &H71  ' (113)  ' // TitleChange
                      FUNCTION = ShellWebBrowser_TitleChange(pUnk, pdispparams)
        
                   CASE &H70  ' (112)  ' // PropertyChange
                      FUNCTION = ShellWebBrowser_PropertyChange(pUnk, pdispparams)
        
                   CASE &HFA  ' (250)  ' // BeforeNavigate2
                      FUNCTION = ShellWebBrowser_BeforeNavigate2(pUnk, pdispparams)
        
                   CASE &HFB  ' (251)  ' // NewWindow2
                      FUNCTION = ShellWebBrowser_NewWindow2(pUnk, pdispparams)
        
                   CASE &HFC  ' (252)  ' // NavigateComplete2
                      FUNCTION = ShellWebBrowser_NavigateComplete2(pUnk, pdispparams)
        
                   CASE &H103  ' (259)  ' // DocumentComplete
                      FUNCTION = ShellWebBrowser_DocumentComplete(pUnk, pdispparams)
        
                   CASE &HFD  ' (253)  ' // OnQuit
                      FUNCTION = ShellWebBrowser_OnQuit(pUnk, pdispparams)
        
                   CASE &HFE  ' (254)  ' // OnVisible
                      FUNCTION = ShellWebBrowser_OnVisible(pUnk, pdispparams)
        
                   CASE &HFF  ' (255)  ' // OnToolBar
                      FUNCTION = ShellWebBrowser_OnToolBar(pUnk, pdispparams)
        
                   CASE &H100  ' (256)  ' // OnMenuBar
                      FUNCTION = ShellWebBrowser_OnMenuBar(pUnk, pdispparams)
        
                   CASE &H101  ' (257)  ' // OnStatusBar
                      FUNCTION = ShellWebBrowser_OnStatusBar(pUnk, pdispparams)
        
                   CASE &H102  ' (258)  ' // OnFullScreen
                      FUNCTION = ShellWebBrowser_OnFullScreen(pUnk, pdispparams)
        
                   CASE &H104  ' (260)  ' // OnTheaterMode
                      FUNCTION = ShellWebBrowser_OnTheaterMode(pUnk, pdispparams)
        
                   CASE &H106  ' (262)  ' // WindowSetResizable
                      FUNCTION = ShellWebBrowser_WindowSetResizable(pUnk, pdispparams)
        
                   CASE &H108  ' (264)  ' // WindowSetLeft
                      FUNCTION = ShellWebBrowser_WindowSetLeft(pUnk, pdispparams)
        
                   CASE &H109  ' (265)  ' // WindowSetTop
                      FUNCTION = ShellWebBrowser_WindowSetTop(pUnk, pdispparams)
        
                   CASE &H10A  ' (266)  ' // WindowSetWidth
                      FUNCTION = ShellWebBrowser_WindowSetWidth(pUnk, pdispparams)
        
                   CASE &H10B  ' (267)  ' // WindowSetHeight
                      FUNCTION = ShellWebBrowser_WindowSetHeight(pUnk, pdispparams)
        
                   CASE &H107  ' (263)  ' // WindowClosing
                      FUNCTION = ShellWebBrowser_WindowClosing(pUnk, pdispparams)
        
                   CASE &H10C  ' (268)  ' // ClientToHostWindow
                      FUNCTION = ShellWebBrowser_ClientToHostWindow(pUnk, pdispparams)
        
                   CASE &H10D  ' (269)  ' // SetSecureLockIcon
                      FUNCTION = ShellWebBrowser_SetSecureLockIcon(pUnk, pdispparams)
        
                   CASE &H10E  ' (270)  ' // FileDownload
                      FUNCTION = ShellWebBrowser_FileDownload(pUnk, pdispparams)
        
                   CASE &H10F  ' (271)  ' // NavigateError
                      FUNCTION = ShellWebBrowser_NavigateError(pUnk, pdispparams)
        
                   CASE &HE1  ' (225)  ' // PrintTemplateInstantiation
                      FUNCTION = ShellWebBrowser_PrintTemplateInstantiation(pUnk, pdispparams)
        
                   CASE &HE2  ' (226)  ' // PrintTemplateTeardown
                      FUNCTION = ShellWebBrowser_PrintTemplateTeardown(pUnk, pdispparams)
        
                   CASE &HE3  ' (227)  ' // UpdatePageStatus
                      FUNCTION = ShellWebBrowser_UpdatePageStatus(pUnk, pdispparams)
        
                   CASE &H110  ' (272)  ' // PrivacyImpactedStateChange
                      FUNCTION = ShellWebBrowser_PrivacyImpactedStateChange(pUnk, pdispparams)
        
                END SELECT
        
             END IF
        
          END FUNCTION
        ' --------------------------------------------------------------------------------------------
        
        
          DECLARE FUNCTION AtlAxWinInit LIB "ATL.DLL" ALIAS "AtlAxWinInit" () AS LONG
        ' *********************************************************************************************
          DECLARE FUNCTION AtlAxWinTerm () AS LONG
        ' *********************************************************************************************
          FUNCTION AtlAxWinTerm () AS LONG
            UnregisterClass ("AtlAxWin", GetModuleHandle(BYVAL %NULL))
          END FUNCTION
        ' *********************************************************************************************
        ' **********************************************************************************************
          DECLARE FUNCTION AtlAxGetControl LIB "ATL.DLL" ALIAS "AtlAxGetControl" _
             ( _
             BYVAL hWnd AS DWORD, _   ' [in] A handle to the window that is hosting the control.
             BYREF pp AS DWORD _      ' [out] The IUnknown of the control being hosted.
          ) AS DWORD
        ' *********************************************************************************************
        
        ' *********************************************************************************************
        ' Puts the address of an object in a variant and marks it as containing a dispatch variable
        ' *********************************************************************************************
          SUB AtlMakeDispatch ( _
             BYVAL lpObj AS DWORD, _                        ' Address of the object instance
             BYREF vObj AS VARIANT _                        ' Variant to contain this address
             ) EXPORT
        
             LOCAL lpvObj AS VARIANTAPI PTR                 ' Pointer to a VARIANTAPI structure
             LET vObj = EMPTY                               ' Make sure is empty to avoid memory leaks
             lpvObj = VARPTR(vObj)                          ' Get the VARIANT address
             @lpvObj.vt = %VT_DISPATCH                      ' Mark it as containing a dispatch variable
             @lpvObj.vd.pdispVal = lpObj                    ' Set the dispatch pointer address
        
          END SUB
        ' *********************************************************************************************
        
        ' *********************************************************************************************
        ' Main dialog callback
        ' *********************************************************************************************
          CALLBACK FUNCTION MainDlgProc()
        
             LOCAL rc AS RECT
             LOCAL r AS LONG
             LOCAL x AS LONG
             LOCAL y AS LONG
             LOCAL xx AS LONG
             LOCAL yy AS LONG
        
        
             SELECT CASE CBMSG
        
                CASE %WM_SIZE
                   GetClientRect CBHNDL, rc
                   x = rc.nLeft
                   y = rc.nTop
                   xx = rc.nRight - rc.nLeft
                   yy = rc.nBottom - rc.nTop - 32
                   MoveWindow hOcx, x, y, xx, yy, %TRUE
        
                CASE %WM_DESTROY
                   PostQuitMessage 0
        
                CASE %WM_COMMAND
                   SELECT CASE CBCTL
                      CASE %IDCANCEL
                         IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                            DIALOG END CBHNDL, 0
                         END IF
                      CASE %IDC_BTNAVG
                         IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                            LOCAL strUrl AS STRING, vVar AS VARIANT
                            CONTROL GET TEXT CBHNDL, %IDC_URL TO strUrl
                            vVar = strUrl
                            OBJECT CALL oOcx.Navigate(vVar)
                         END IF
                      CASE %IDC_BTBACK
                         IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                            OBJECT CALL oOcx.GoBack
                         END IF
                      CASE %IDC_BTFRWD
                         IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                            OBJECT CALL oOcx.GoForward
                         END IF
                   END SELECT
        
             END SELECT
        
          END FUNCTION
        ' *********************************************************************************************
        
        ' *********************************************************************************************
        ' Main
        ' *********************************************************************************************
          FUNCTION PBMAIN
        
             LOCAL hInst AS DWORD
             LOCAL hr AS DWORD
             LOCAL OcxName AS ASCIIZ * 255
             LOCAL pUnk AS DWORD
             LOCAL vVar AS VARIANT
             LOCAL uMsg AS tagMsg
             LOCAL dwCookie AS DWORD
        
             OcxName = "Shell.Explorer"
        
             AtlAxWinInit   ' // Initializes ATL
        
             DIALOG NEW 0, "A Web Browser in a DDT dialog",,, 528, 334, %WS_OVERLAPPEDWINDOW, 0 TO hDlg
             CONTROL ADD "AtlAxWin", hDlg, %ID_OCX, OcxName, 0, 0, 0, 0, %WS_VISIBLE OR %WS_CHILD
             CONTROL HANDLE hDlg, %ID_OCX TO hOcx
             CONTROL ADD LABEL, hDlg, %IDC_LABEL1, "URL", 226, 322, 16, 12
             CONTROL ADD TEXTBOX, hDlg, %IDC_URL, "", 250, 320, 210, 14
             CONTROL ADD BUTTON, hDlg, %IDC_BTNAVG, "&Navigate", 470, 320, 46, 14, %WS_TABSTOP OR %BS_DEFAULT
             CONTROL ADD BUTTON, hDlg, %IDC_BTBACK, "&Back", 5, 320, 46, 14, %WS_TABSTOP
             CONTROL ADD BUTTON, hDlg, %IDC_BTFRWD, "&Forward", 58, 320, 46, 14, %WS_TABSTOP
             CONTROL SET TEXT hDlg, %IDC_URL, "http://www.powerbasic.com"
        
             AtlAxGetControl(hOcx, pUnk)
             AtlMakeDispatch(pUnk, vVar)
             SET oOcx = vVar
        
             '// Subscribe to the WebBroser events
             hr = ShellWebBrowser_SetEvents(OBJPTR(oOcx), dwCookie)
        
             SetFocus(hOcx)
             DIALOG SHOW MODAL hDlg, CALL MainDlgProc TO hr
        
             ' // Unsubscribe from the WebBrowser events
             hr = ShellWebBrowser_ReleaseEvents(OBJPTR(oOcx), dwCookie)
        
             AtlAxWinTerm   ' // Uninitializes ATL
             SET oOcx = NOTHING
        
          END FUNCTION
        ' *********************************************************************************************

        ------------------




        [This message has been edited by JOSE ROCA (edited August 08, 2003).]

        Comment


        • #5
          New version of the first example. I have made the dialog modeless to
          be able to pass the keystrokes to the WebBrowser control for processing,
          otherwise the main dialog will eat them and shortcuts like Ctrl-C
          won't work.
          Code:
            #DIM ALL
            #INCLUDE "win32api.inc"
          
            %WM_FORWARDMSG = &H37F ' (895)
          
            %ID_OCX     = 1001
            %IDC_URL    = 1010
            %IDC_BTNAVG = 1011
            %IDC_BTBACK = 1012
            %IDC_BTFRWD = 1013
            %IDC_LABEL1 = 1014
          
            GLOBAL hDlg AS DWORD
            GLOBAL hOcx AS DWORD
            GLOBAL oOcx AS DISPATCH
          
          
            DECLARE FUNCTION AtlAxWinInit LIB "ATL.DLL" ALIAS "AtlAxWinInit" () AS LONG
          ' *********************************************************************************************
            DECLARE FUNCTION AtlAxWinTerm () AS LONG
          ' *********************************************************************************************
            FUNCTION AtlAxWinTerm () AS LONG
              UnregisterClass ("AtlAxWin", GetModuleHandle(BYVAL %NULL))
            END FUNCTION
          ' *********************************************************************************************
          ' **********************************************************************************************
            DECLARE FUNCTION AtlAxGetControl LIB "ATL.DLL" ALIAS "AtlAxGetControl" _
               ( _
               BYVAL hWnd AS DWORD, _   ' [in] A handle to the window that is hosting the control.
               BYREF pp AS DWORD _      ' [out] The IUnknown of the control being hosted.
            ) AS DWORD
          ' *********************************************************************************************
          
          ' *********************************************************************************************
          ' Puts the address of an object in a variant and marks it as containing a dispatch variable
          ' *********************************************************************************************
            SUB AtlMakeDispatch ( _
               BYVAL lpObj AS DWORD, _                        ' Address of the object instance
               BYREF vObj AS VARIANT _                        ' Variant to contain this address
               ) EXPORT
          
               LOCAL lpvObj AS VARIANTAPI PTR                 ' Pointer to a VARIANTAPI structure
               LET vObj = EMPTY                               ' Make sure is empty to avoid memory leaks
               lpvObj = VARPTR(vObj)                          ' Get the VARIANT address
               @lpvObj.vt = %VT_DISPATCH                      ' Mark it as containing a dispatch variable
               @lpvObj.vd.pdispVal = lpObj                    ' Set the dispatch pointer address
          
            END SUB
          ' *********************************************************************************************
          
          ' *********************************************************************************************
          ' Main dialog callback
          ' *********************************************************************************************
            CALLBACK FUNCTION MainDlgProc()
          
               LOCAL rc AS RECT
               LOCAL r AS LONG
               LOCAL x AS LONG
               LOCAL y AS LONG
               LOCAL xx AS LONG
               LOCAL yy AS LONG
          
          
               SELECT CASE CBMSG
          
                  CASE %WM_SIZE
                     GetClientRect CBHNDL, rc
                     x = rc.nLeft
                     y = rc.nTop
                     xx = rc.nRight - rc.nLeft
                     yy = rc.nBottom - rc.nTop - 32
                     MoveWindow hOcx, x, y, xx, yy, %TRUE
          
                  CASE %WM_DESTROY
                     PostQuitMessage 0
          
                  CASE %WM_COMMAND
                     SELECT CASE CBCTL
                        CASE %IDCANCEL
                           IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                              DIALOG END CBHNDL, 0
                           END IF
                        CASE %IDC_BTNAVG
                           IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                              LOCAL strUrl AS STRING, vVar AS VARIANT
                              CONTROL GET TEXT CBHNDL, %IDC_URL TO strUrl
                              vVar = strUrl
                              OBJECT CALL oOcx.Navigate(vVar)
                           END IF
                        CASE %IDC_BTBACK
                           IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                              OBJECT CALL oOcx.GoBack
                           END IF
                        CASE %IDC_BTFRWD
                           IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                              OBJECT CALL oOcx.GoForward
                           END IF
                     END SELECT
          
               END SELECT
          
            END FUNCTION
          ' *********************************************************************************************
          
          ' *********************************************************************************************
          ' Main
          ' *********************************************************************************************
            FUNCTION PBMAIN
          
               LOCAL hInst AS DWORD
               LOCAL hr AS DWORD
               LOCAL OcxName AS ASCIIZ * 255
               LOCAL pUnk AS DWORD
               LOCAL vVar AS VARIANT
               LOCAL uMsg AS tagMsg
               LOCAL dwCookie AS DWORD
          
               OcxName = "Shell.Explorer"
          
               AtlAxWinInit   ' // Initializes ATL
          
               DIALOG NEW 0, "A Web Browser in a DDT dialog",,, 528, 334, %WS_OVERLAPPEDWINDOW, 0 TO hDlg
               CONTROL ADD "AtlAxWin", hDlg, %ID_OCX, OcxName, 0, 0, 0, 0, %WS_VISIBLE OR %WS_CHILD
               CONTROL HANDLE hDlg, %ID_OCX TO hOcx
               CONTROL ADD LABEL, hDlg, %IDC_LABEL1, "URL", 226, 322, 16, 12
               CONTROL ADD TEXTBOX, hDlg, %IDC_URL, "", 250, 320, 210, 14
               CONTROL ADD BUTTON, hDlg, %IDC_BTNAVG, "&Navigate", 470, 320, 46, 14, %WS_TABSTOP OR %BS_DEFAULT
               CONTROL ADD BUTTON, hDlg, %IDC_BTBACK, "&Back", 5, 320, 46, 14, %WS_TABSTOP
               CONTROL ADD BUTTON, hDlg, %IDC_BTFRWD, "&Forward", 58, 320, 46, 14, %WS_TABSTOP
               CONTROL SET TEXT hDlg, %IDC_URL, "http://www.powerbasic.com"
          
               AtlAxGetControl(hOcx, pUnk)
               AtlMakeDispatch(pUnk, vVar)
               SET oOcx = vVar
          
               SetFocus(hOcx)
               DIALOG SHOW MODELESS hDlg, CALL MainDlgProc TO hr
          
               WHILE GetMessage(uMsg, %NULL, 0, 0)
                  '// Pass keyboard messages to the ancestor
                  '// Returns 0 if the message was not processed, nonzero if it was
                  IF SendMessage(hOcx, %WM_FORWARDMSG, 0, VARPTR(uMsg)) = 0 THEN
                     IF IsDialogMessage(hDlg, uMsg) = %FALSE THEN
                        TranslateMessage uMsg
                        DispatchMessage uMsg
                     END IF
                  END IF
               WEND
          
               AtlAxWinTerm   ' // Uninitializes ATL
               SET oOcx = NOTHING
          
            END FUNCTION
          ' *********************************************************************************************

          ------------------

          Comment


          • #6

            I changed my password and I'm not longer allowed to edit my original post.

            With the PBWin 8.x compiler, when the "home made" dispatch variant goes
            out of scope, is set to empty or you assign a new value to it, the
            reference counter is decreased, so we need to increment the count with
            IUnknown_AddRef to keep the reference count balanced.

            Just replace the AtlMakeDispatch procedure with the following:

            Code:
            ' ********************************************************************************************
            ' The IUnknown::AddRef method increments the reference count for an interface on an object. It
            ' should be called for every new copy of a pointer to an interface on a given object.
            ' ********************************************************************************************
            FUNCTION IUnknown_AddRef (BYVAL pthis AS DWORD PTR) AS DWORD
                LOCAL DWRESULT AS DWORD
                IF ISFALSE pthis THEN EXIT FUNCTION
                CALL DWORD @@pthis[1] USING IUnknown_AddRef(pthis) TO DWRESULT
                FUNCTION = DWRESULT
            END FUNCTION
            ' ********************************************************************************************
            
            ' *********************************************************************************************
            ' Puts the address of an object in a variant and marks it as containing a dispatch variable
            ' *********************************************************************************************
            SUB AtlMakeDispatch (BYVAL lpObj AS DWORD, BYREF vObj AS VARIANT) EXPORT
               LOCAL lpvObj AS VARIANTAPI PTR                 ' Pointer to a VARIANTAPI structure
               LET vObj = EMPTY                               ' Make sure is empty to avoid memory leaks
               lpvObj = VARPTR(vObj)                          ' Get the VARIANT address
               @lpvObj.vt = %VT_DISPATCH                      ' Mark it as containing a dispatch variable
               @lpvObj.vd.pdispVal = lpObj                    ' Set the dispatch pointer address
               IUnknown_AddRef lpObj                          ' Increment the reference counter
            END SUB
            ' *********************************************************************************************

            ------------------
            Website: http://com.it-berater.org
            SED Editor, TypeLib Browser, Wrappers for ADO, DAO, ODBC, CDOEX, MSXML, WMI, MSAGENT, Flash Player, Task Scheduler, Accesibility, Structured Storage, WinHTTP, Microsoft ActiveX Controls (Data Binding, ADODC, Flex Grid, Hierarchical Flex Grid, Masked Edit Control, DataList, DataCombo, MAPI, INET, MCI, Winsock, Common Dialog, MSChart, Outlook View Control), and Microsoft Scripting Components.

            [This message has been edited by José Roca (edited September 06, 2005).]
            Forum: http://www.jose.it-berater.org/smfforum/index.php

            Comment


            • #7
              delete

              Sorry, questions don't go here
              Last edited by Lawrence Rudner; 26 Oct 2007, 11:28 AM. Reason: Wrong forum

              Comment


              • #8
                Browser -- Supercool

                engine translated:

                Dear Jóse Roca,

                I am not so mighty for the English language how I should be in order to take part in this forum and use a program, that probably produces vien garbage, for it.

                The browser is a good matter, because it takes advantage of the whole screen and fades out of stuff much useless, now and then has become only the disadvantage I in the reared mode another URL what then doesn't work inputs, because input field and the buttons onward and backwards vanished. And one also should be able print. - That would be total-mega-super.

                I compiled your browser and would pass him/it on gladly to my friends of our computer club.

                http://www.computermuseum.fh-kiel.de

                Dear greetingses from Kiel
                Detlev Wulff

                Comment


                • #9
                  Hi José

                  I like your code very much and have been using it many times. Thank you.

                  However, using PBWin10.02 I get error 530 (Invalid member name/definition) for this line:

                  @lpvObj.vd.pdispVal = lpObj ' Set the dispatch pointer address

                  in SUB AtlMakeDispatch.

                  The error occurs in all the versions you have in this thread. Do you know why this error occurs? Do you have a solution to the problem? Thanks in advance.

                  Best regards,

                  Erik
                  Last edited by Erik Christensen; 25 Oct 2011, 09:57 AM.

                  Comment


                  • #10
                    José has kindly provided this change to the code, which makes it work also using PBWin10.02.

                    The previous SUB AtlMakeDispatch should be replaced by this:

                    Code:
                    ' ********************************************************************************************
                    ' The IUnknown::AddRef method increments the reference count for an interface on an object. It
                    ' should be called for every new copy of a pointer to an interface on a given object.
                    ' ********************************************************************************************
                    FUNCTION IUnknown_AddRef (BYVAL pthis AS DWORD PTR) AS DWORD
                        LOCAL DWRESULT AS DWORD
                        IF ISFALSE pthis THEN EXIT FUNCTION
                        CALL DWORD @@pthis[1] USING IUnknown_AddRef(pthis) TO DWRESULT
                        FUNCTION = DWRESULT
                    END FUNCTION
                    ' ********************************************************************************************
                    
                    ' *********************************************************************************************
                    ' Puts the address of an object in a variant and marks it as containing a dispatch variable
                    ' *********************************************************************************************
                    SUB AtlMakeDispatch (BYVAL lpObj AS DWORD, BYREF vObj AS VARIANT) EXPORT
                       LOCAL lpvObj AS VARIANTAPI PTR                 ' Pointer to a VARIANTAPI structure
                       LET vObj = EMPTY                               ' Make sure is empty to avoid memory leaks
                       lpvObj = VARPTR(vObj)                          ' Get the VARIANT address
                       @lpvObj.vt = %VT_DISPATCH                      ' Mark it as containing a dispatch variable
                       @lpvObj.pdispVal = lpObj                       ' Set the dispatch pointer address
                       IUnknown_AddRef lpObj                          ' Increment the reference counter
                    END SUB
                    ' *********************************************************************************************
                    The important change is that this line:
                    @lpvObj.vd.pdispVal = lpObj ' Set the dispatch pointer address

                    is replaced by:
                    @lpvObj.pdispVal = lpObj ' Set the dispatch pointer address

                    José, Many Thanks. Best regards, Erik

                    Comment


                    • #11
                      See this area:

                      http://www.jose.it-berater.org/smffo...hp?board=421.0
                      • MDI Web Browser
                      • HTML5: FishIE Tank
                      • WebBrowser Control: Embedding YouTube
                      • Embedding the WebBrowser Control
                      • WebBrowser Control: CCS Dock Menu New
                      • Automating Internet Explorer New
                      • How to read the statusbar contents of Internet Explorer New
                      • How to get IHTMLDocument2 from a HWND New
                      • How to get IWebBrowser2 from a HWND New
                      • Help Browser
                      • Web Browser Control: Google Map

                      Good stuff! : )
                      3.14159265358979323846264338327950
                      "Ok, yes... I like pie... um, I meant, pi."

                      Comment


                      • #12
                        The important change is that this line:
                        @lpvObj.vd.pdispVal = lpObj ' Set the dispatch pointer address

                        is replaced by:
                        @lpvObj.pdispVal = lpObj ' Set the dispatch pointer address
                        Only if used with the PB includes that come with the PB10/PBCC6 compilers.
                        Forum: http://www.jose.it-berater.org/smfforum/index.php

                        Comment


                        • #13
                          Hi Jose,
                          There are two things I'd like to do with an embedded browser:

                          1. Search within a displayed page, highlighting one or all of the found terms, with the ability to scroll to keep a found term visible. That's the most important item for me right now.

                          2. Extract all displayed text.

                          Do you have any examples of these, or if not, where would you suggest I start? I'll head over to your site to see what is available there.

                          Comment


                          • #14
                            Yippee!
                            Right off the bat, I can see that you've implemented Search in the "Help Browser" example. I can see several hours of study coming right up!

                            But first, I have to take my wife to see a movie ... then I'll see if I can extract the basic code that does what I want.

                            Thanks, Jose!

                            Comment

                            Working...
                            X