#DIM ALL #INCLUDE "win32api.inc" %WM_FORWARDMSG = &H37F ' (895) %ID_OCX = 1001 GLOBAL hOcx AS DWORD ' ********************************************************************************************* DECLARE FUNCTION AtlAxWinInit LIB "ATL.DLL" ALIAS "AtlAxWinInit" () AS LONG ' ********************************************************************************************* ' ********************************************************************************************** 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 ' ********************************************************************************************* ' 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 ' ********************************************************************************************* ' 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 + 20 y = rc.nTop + 25 xx = rc.nRight - rc.nLeft - 40 yy = rc.nBottom - rc.nTop - 44 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 END SELECT END SELECT END FUNCTION ' ********************************************************************************************* ' ********************************************************************************************* ' Main ' ********************************************************************************************* FUNCTION PBMAIN LOCAL oOcx AS DISPATCH LOCAL hDlg AS DWORD LOCAL hr AS DWORD LOCAL OcxName AS ASCIIZ * 255 LOCAL pUnk AS DWORD LOCAL uMsg AS tagMsg LOCAL vVar AS VARIANT LOCAL vRes AS VARIANT LOCAL s AS STRING OcxName = "Shell.Explorer" AtlAxWinInit ' // Initializes ATL DIALOG NEW 0, "HTML document test",,, 528, 334, %WS_OVERLAPPEDWINDOW, 0 TO hDlg CONTROL ADD "AtlAxWin", hDlg, %ID_OCX, OcxName, 0, 0, 0, 0, %WS_VISIBLE OR %WS_CHILD OR %WS_BORDER ' // Get the handle of the control CONTROL HANDLE hDlg, %ID_OCX TO hOcx ' // Get the interface pointer of the WebBrowser control AtlAxGetControl(hOcx, pUnk) ' // Make a dispatch variant from it to be able to use PB automation AtlMakeDispatch(pUnk, vVar) SET oOcx = vVar ' // Make an Html form s="-- Testing moving to link on the same page --" _ +"Move to the next link on this side.
.
.
.
.
.
.
.
.
." _ +"
.
.
.
.
.
.
.
.
.
.
.
.
" _ +"This is the next link.
.
.
.
.
.
.
.
.
.
.
.
." _ +"
.
.
.
.
.
.
.
.
.
.
.
.
" _ +"This is the end of the page" ' ' save the html-string ' LOCAL CurrentPath AS ASCIIZ * %MAX_PATH LOCAL hFile AS LONG ' GetModuleFileName GetModuleHandle(""), CurrentPath, %MAX_PATH ' Get current Path & file name CurrentPath = LEFT$(CurrentPath,INSTR(-1, CurrentPath, ANY "\:/")-1) ' Get just the path without the file name hFile = FREEFILE OPEN CurrentPath+"\test.htm" FOR OUTPUT AS #hFile PRINT #hFile, s CLOSE #hFile ' ' make the link to the file and navigate to this link ' vVar = CurrentPath + "\test.htm" OBJECT CALL oOcx.Navigate(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 SET oOcx = NOTHING END FUNCTION ' *********************************************************************************************