Posts: 858
Threads: 196
Joined: Apr 2005
Is possible to capture a screenshot of a Web site like
http://www.nirsoft.net/utils/web_site_screenshot.html using QM?
Posts: 12,097
Threads: 142
Joined: Dec 2002
Should be easy to create simplest code. But will need time to add more features, such as auto-size. And to test with many pages... Better use the nirsoft command line program.
Posts: 858
Threads: 196
Joined: Apr 2005
Posts: 858
Threads: 196
Joined: Apr 2005
Posts: 12,097
Threads: 142
Joined: Dec 2002
I don't think that any of these codes work reliably, with any page, with scrolling pages. If don't want to spend several days converting these codes and trying to make them work reliably enough, use the commandline program or try to find some good library (COM or .NET), or use some online service.
Posts: 858
Threads: 196
Joined: Apr 2005
I just performed a test on the AutoIt code and it works correctly ...
It seems to use IHTMLElementRender to generate an image of an accessible object.
Posts: 12,097
Threads: 142
Joined: Dec 2002
Code for IHTMLElementRender.
Macro
Macro151
HtmlDoc d.SetOptions(2)
d.InitFromWeb("http://www.quickmacros.com/")
__MemBmp b.Create(1000 1000)
MSHTML.IHTMLElementRender r=+d.d.body
MSHTML._RemotableHandle* workaround=+b.dc ;;DrawToDC is declared incorrectly in the type library
r.DrawToDC(workaround)
str sFile.expandpath("$temp$\1.bmp")
SaveBitmap b.bm sFile
run sFile
;Don't ask me how to get web page dimensions, how to capture whole scrolling page, etc.
Posts: 858
Threads: 196
Joined: Apr 2005
Posts: 858
Threads: 196
Joined: Apr 2005
12-19-2018, 05:09 PM
(This post was last modified: 12-19-2018, 05:34 PM by Lucas.)
I tried to create the Web2Image function to capture an HTML element without success.
Error (RT) in <open ": 4709: / 840"> Macro53: 0x80004002, Interface not supported.
Can you create the function?
Macro
Macro53
int w=wait(3 WV win("Nueva pestaña - Internet Explorer" "IEFrame"))
Htm e=htm("DIV" "" "" w "0" 46 0x20 3)
__MemBmp b.Create(1000 1000)
MSHTML.IHTMLElementRender r=+e.el.document
MSHTML._RemotableHandle* workaround=+b.dc ;;DrawToDC is declared incorrectly in the type library
r.DrawToDC(workaround)
str sFile.expandpath("$temp$\1.bmp")
SaveBitmap b.bm sFile
run sFile
Posts: 12,097
Threads: 142
Joined: Dec 2002
MSHTML.IHTMLDocument2 d=e.el.document
MSHTML.IHTMLElementRender r=+d.body
But does not work too. Works when the web browser control is in the same process, like in the autoit code.
Posts: 858
Threads: 196
Joined: Apr 2005
12-19-2018, 07:45 PM
(This post was last modified: 12-19-2018, 08:53 PM by Lucas.)
any workaround?
Posts: 12,097
Threads: 142
Joined: Dec 2002
Macro
Macro173
int w=win("- Internet Explorer" "IEFrame")
int c=child("" "Internet Explorer_Server" w)
Htm e=htm("BODY" "" "" c "0" 0 0x30)
MSHTML.IHTMLElement2 e2=+e.el
int wid(e2.scrollWidth) hei(e2.scrollHeight)
out F"{wid} {hei}"
;if has scrollbar, temporarily resize to show whole page; later restore; not implemented.
;RECT r; GetWindowRect(c &r)
;if wid>r.right-r.left or hei>r.bottom-r.top
,;...
__MemBmp b.Create(wid hei)
PrintWindow(c b.dc PW_CLIENTONLY)
;restore if resized
;...
str sFile.expandpath("$temp$\1.bmp")
SaveBitmap b.bm sFile
run sFile
Posts: 858
Threads: 196
Joined: Apr 2005
Posts: 726
Threads: 99
Joined: Mar 2018
Is there any new progress in webpage screenshots?
I need to save the entire page of a URL as a PNG image. I can only take a small part of it using the code below. I very much hope to continue to enhance and improve it. Thank you very much.
Macro
Macro8
;http://www.quickmacros.com/forum/showthread.php?tid=6246&highlight=service
int w=win("- Internet Explorer" "IEFrame")
int c=child("" "Internet Explorer_Server" w)
Htm e=htm("BODY" "" "" c "0" 0 0x30)
MSHTML.IHTMLElement2 e2=+e.el
int wid(e2.scrollWidth) hei(e2.scrollHeight)
out F"{wid} {hei}"
;if has scrollbar, temporarily resize to show whole page; later restore; not implemented.
;RECT r; GetWindowRect(c &r)
;if wid>r.right-r.left or hei>r.bottom-r.top
,;...
__MemBmp b.Create(wid hei)
PrintWindow(c b.dc PW_CLIENTONLY)
;restore if resized
;...
str sFile.expandpath("$temp$\1.bmp")
SaveBitmap b.bm sFile
run sFile
Posts: 726
Threads: 99
Joined: Mar 2018
When the page is loaded, I want to intercept the entire page in the dialog. How do I handle it?
Macro
Macro9
\Dialog_Editor
str controls = "3"
str ax3SHD
ax3SHD="https://www.msn.com"
if(!ShowDialog("" &sub.DialogProcedure &controls)) ret
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 600 280 "Dialog"
;3 ActiveX 0x54030000 0x0 0 0 600 282 "SHDocVw.WebBrowser"
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""
#sub DialogProcedure
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,SHDocVw.WebBrowser we3
,we3._getcontrol(id(3 hDlg))
,we3._setevents("sub.we3")
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#sub we3_DocumentComplete
function IDispatch'pDisp `&URL ;;SHDocVw.IWebBrowser2'we3
out "webComplete"
HtmlDoc d.SetOptions(2)
d.InitFromWeb("https://www.msn.com")
__MemBmp b.Create(1000 6000)
MSHTML.IHTMLElementRender r=+d.d.body
MSHTML._RemotableHandle* workaround=+b.dc ;;DrawToDC is declared incorrectly in the type library
r.DrawToDC(workaround)
str sFile.expandpath("$temp$\1.bmp")
SaveBitmap b.bm sFile
run sFile
Posts: 726
Threads: 99
Joined: Mar 2018
05-09-2019, 01:54 AM
(This post was last modified: 05-09-2019, 01:57 AM by win.)
Strange, the following code, the link to qm is OK, invalid for other links
Can provide the easiest way to intercept the entire page of a link and save it as a PNG image?
Macro
Macro16
HtmlDoc d.SetOptions(2)
;d.InitFromWeb("http://www.quickmacros.com/") ;; ok
d.InitFromWeb("https://www.msn.cn/zh-cn") ;;not ok
__MemBmp b.Create(1000 1000)
MSHTML.IHTMLElementRender r=+d.d.body
MSHTML._RemotableHandle* workaround=+b.dc ;;DrawToDC is declared incorrectly in the type library
r.DrawToDC(workaround)
str sFile.expandpath("$temp$\1.bmp")
SaveBitmap b.bm sFile
run sFile
Posts: 726
Threads: 99
Joined: Mar 2018
I found a good solution, please use QM to execute the following powershell script 
$ie = New-Object -ComObject InternetExplorer.Application
$ie.Visible = $true;
$Yourwebpage = $ie.navigate('www.msn.com')
while($Yourwebpage.Busy){Start-Sleep -Seconds 5}
#capturing the screenshot
$file = "C:\Users\xyz\Desktop\abc\$(Get-Date -Format dd-MM-yyyy-hhmm).bmp"
Add-Type -AssemblyName System.Windows.Forms
Add-type -AssemblyName System.Drawing
$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
$width = $Screen.width
$Height = $Screen.Height
$Left = $Screen.Left
$Right = $Screen.Right
$Top = $Screen.Top
$Bottom = $Screen.Bottom
$bitmap = New-Object System.Drawing.Bitmap $width, $Height
$Graphics = [System.Drawing.Graphics]::FromImage($bitmap)
$Graphics.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size)
$bitmap.Save($File)
Write-Output "Screenshot saved to:"
Write-Output $File