Date: 02-16-2022
Return to Index
'Compilable Example: (Jose Includes)
created by gbSnippets
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
%UseWebBrowser = 1 ' // Use the WebBrowser control
#Include Once "CWindow.inc" ' // CWindow class
Enum Equates Singular
IDC_Button = 500
IDC_WebBrowser
End Enum
Global hDlg,hBrowser As Dword, ww,hh As Long
Function PBMain() As Long
Local pWindow As IWindow
ww = 900 : hh = 900
Dialog New Pixels, 0, "PowerBASIC",300,300,400,300, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Capture OffScreen Browser", 10,10,180,20
pWindow = Class "CWindow"
pWindow.AddWebBrowserControl(hDlg, %IDC_WebBrowser, "http://www.garybeene.com",Nothing, 0, 50, ww,900)
Control Handle hDlg, %IDC_WebBrowser To hBrowser
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local hBMP,hDC_Graphic,hDC_Browser As Dword
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
'create memory DC
Graphic Bitmap New ww,hh To hBMP
Graphic Attach hBMP, 0
Graphic Get DC To hDC_Graphic
'create TextBox DC
hDC_Browser = GetWindowDC(hBrowser)
'copy control to memory DC
CopyHTMLToDC(hDC_Graphic)
'put memory bitmap on clipboard
Clipboard Reset
Clipboard Set Bitmap hBMP
'cleanup
ReleaseDC hBrowser, hDC_Browser
Graphic Bitmap End
End Select
End Select
End Function
Sub CopyHTMLtoDC(hDC As Dword)
Local pIWebBrowser2 As IWebBrowser2
Local pIHTMLDocument2 As IHTMLDocument2
Local pElement As IHTMLElement
Local pElement2 As IHTMLElement2
Local pElementRender As IHTMLElementRender
Local w,h As Long, hBrowser As Dword
hBrowser = GetDlgItem(hDlg,%IDC_WebBrowser)
pIWebBrowser2 = OC_GetDispatch(hBrowser) 'reference to webbrowser control default interface
pIHTMLDocument2 = pIWebBrowser2.Document
pElement = pIHTMLDocument2.body
pElementRender = pElement
pElementRender.DrawToDC(hDC)
End Sub
'gbs_01379
'Date: 10-17-2014
http://www.garybeene.com/sw/gbsnippets.htm