Date: 02-16-2022
Return to Index
created by gbSnippets
'Credit: Jose Roca
'Compilable Example: (Jose Includes)
#COMPILE EXE
#DIM ALL
%UNICODE = 1
' // Include files for external files
%USEWEBBROWSER = 1 ' // Use the WebBrowser control
#INCLUDE ONCE "CWindow.inc" ' // CWindow class
' // Identifier
%IDC_WEBBROWSER = 1001
%IDC_GETTEXT = 1002
' ########################################################################################
' Main
' ########################################################################################
FUNCTION PBMAIN
' // Create the dialog
LOCAL hDlg AS DWORD
DIALOG NEW PIXELS, 0, "WebBrowser", , , 600, 400, %WS_OVERLAPPEDWINDOW TO hDlg
' // Create an instance of the class
LOCAL pWindow AS IWindow
pWindow = CLASS "CWindow"
IF ISNOTHING(pWindow) THEN EXIT FUNCTION
' // Add a WebBrowser control
LOCAL bstrURL AS WSTRING
' // You can pass a URL
bstrURL = "http://www.powerbasic.com/support/pbforums/index.php"
' // Create the WebBrowser control
LOCAL nWide, nHigh AS LONG
DIALOG GET CLIENT hDlg TO nWide, nHigh
pWindow.AddWebBrowserControl(hDlg, %IDC_WEBBROWSER, bstrURL, NOTHING, 0, 0, nWide, nHigh - 50)
CONTROL SET FOCUS hDlg, %IDC_WEBBROWSER
CONTROL ADD BUTTON, hDlg, %IDC_GETTEXT, "Get text", 250, 365, 100, 25
' // Display and activate the dialog
DIALOG SHOW MODAL hDlg, CALL DlgProc
END FUNCTION
' ########################################################################################
' ========================================================================================
' Main Dialog procedure
' ========================================================================================
CALLBACK FUNCTION DlgProc() AS LONG
SELECT CASE CB.MSG
CASE %WM_COMMAND
SELECT CASE CB.CTL
CASE %IDC_GETTEXT
LOCAL pWebBrowser AS IWebBrowser2
LOCAL pHTMLDocument AS IHTMLDocument2
LOCAL bstrText AS WSTRING
pWebBrowser = OC_GetDispatch(GetDlgItem(CB.HNDL, %IDC_WEBBROWSER))
IF ISOBJECT(pWebBrowser) THEN
pHTMLDocument = pWebBrowser.Document
IF ISOBJECT(pHTMLDocument) THEN
bstrText = pHTMLDocument.body.innerText
MSGBOX bstrText
END IF
END IF
END SELECT
CASE %WM_SIZE
IF CB.WPARAM <> %SIZE_MINIMIZED THEN
' // Resize the control
LOCAL nWide, nHigh AS LONG
DIALOG GET CLIENT CB.HNDL TO nWide, nHigh
CONTROL SET SIZE CB.HNDL, %IDC_WEBBROWSER, nWide, nHigh - 50
END IF
END SELECT
END FUNCTION
'gbs_01372
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm