Jump to content

Recommended Posts

Posted

Example in still contained some AutoItObject leftovers, here's a more cleaned up version.

#include <IE.au3>
#include <WinAPI.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>

; Runs fine with Beta 3.3.9.5+
If Int(StringReplace(@AutoItVersion, ".", "")) <= 3381 Then
    MsgBox(0, "Exit", "Requires AutoIt version > 3.3.8.1, try with Beta")
    Exit
EndIf

_WebCaptureTest("http://funk.eu", "Test1.png")

Func _WebCaptureTest($Url, $ImageName)
    Local $hBmp = _WebCapture($Url, 1280)
    _ScreenCapture_SaveImage($ImageName, $hBmp, True)
EndFunc   ;==>_WebCaptureTest

Func _WebCapture($Url, $WebWidth = 1024)

    Local $oIE = ObjCreate("Shell.Explorer.2")
    Local $hGUI = GUICreate("", $WebWidth, 768, -1, -1)
    Local $cObj = GUICtrlCreateObj($oIE, 0, 0, $WebWidth, 768)

    _IELoadWaitTimeout(20000) ; 20 sec
    _IENavigate($oIE, $Url)
    _IELoadWait($oIE)

    Local $oDocument = $oIE.document
    Local $oBody = $oIE.document.body
    Local $oHtml = $oIE.document.documentElement

    $oBody.scroll = "no"
    $oBody.style.borderStyle = "none"
    $oHtml.style.overflow = 'hidden'
    $oBody.style.overflow = 'hidden'

    Local $oIViewObject2 = ObjCreateInterface($oDocument, "{00000127-0000-0000-C000-000000000046}", "Draw hresult(dword;long;ptr;ptr;dword;dword;ptr;ptr;int;dword);")

    If @error Then Return SetError(1, 0, 0)

    Local $BodyWidth = $oBody.scrollWidth
    Local $BodyHeight = $oBody.scrollHeight
    Local $RootWidth = $oHtml.scrollWidth
    Local $RootHeight = $oHtml.scrollHeight

    Local $Width = $BodyWidth
    Local $Height = $RootHeight
    If $BodyHeight > $Height Then $Height = $BodyHeight

    $oIE.width = $Width
    $oIE.height = $Height

    Local $hDC = _WinAPI_GetDC(0)
    Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $Width, $Height)
    _WinAPI_SelectObject($hMemDC, $hBmp)

    Local $sRECT = DllStructCreate($tagRECT)
    DllStructSetData($sRECT, "Top", 0)
    DllStructSetData($sRECT, "Left", 0)
    DllStructSetData($sRECT, "Right", $Width)
    DllStructSetData($sRECT, "Bottom", $Height)

    Local Const $DVASPECT_CONTENT = 1
    $oIViewObject2.Draw($DVASPECT_CONTENT, -1, 0, 0, Number($hDC), Number($hMemDC), Number(DllStructGetPtr($sRECT)), 0, 0, 0)

    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_ReleaseDC(0, $hDC)

    GUICtrlDelete($cObj)
    GUIDelete($hGUI)
    $oIViewObject2 = 0
    $oIE = 0

    Return $hBmp
EndFunc   ;==>_WebCapture
Posted (edited)

^^You can clean that up further more. Those Number() calls aren't necessary and mehod definition should be something like this:

"Draw hresult(dword;long;ptr;ptr;handle;handle;struct*;struct*;bool;ulong_ptr);"

Then you don't even need DllStructGetPtr(), you just pass struct for 7th param and you are sure method definition is correct for both x64 and x86.

Edited by trancexx

♡♡♡

.

eMyvnE

Posted (edited)

Nice :). How about the clean-up I perform at the end of the function?

GUICtrlDelete($cObj)
GUIDelete($hGUI)
$oIViewObject2 = 0
$oIE = 0

When I set the GUI to visible I see it still exists after the function has finished, thus I assume a GUIDelete is appropriate. Is it advisable to delete the controls manually? And also the Objects, are those cleaned by the garbage collector?

#include <IE.au3>
#include <WinAPI.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>

; Runs fine with Beta 3.3.9.5+
If Int(StringReplace(@AutoItVersion, ".", "")) <= 3381 Then
    MsgBox(0, "Exit", "Requires AutoIt version > 3.3.8.1, try with Beta")
    Exit
EndIf

_WebCaptureTest("http://funk.eu", "Test1.png")

Func _WebCaptureTest($Url, $ImageName)
    Local $hBmp = _WebCapture($Url, 1280)
    _ScreenCapture_SaveImage($ImageName, $hBmp, True)
EndFunc   ;==>_WebCaptureTest

Func _WebCapture($Url, $WebWidth = 1024)

    Local $oIE = ObjCreate("Shell.Explorer.2")
    Local $hGUI = GUICreate("", $WebWidth, 768, -1, -1)
    Local $cObj = GUICtrlCreateObj($oIE, 0, 0, $WebWidth, 768)

    _IELoadWaitTimeout(20000) ; 20 sec
    _IENavigate($oIE, $Url)
    _IELoadWait($oIE)

    Local $oDocument = $oIE.document
    Local $oBody = $oIE.document.body
    Local $oHtml = $oIE.document.documentElement

    $oBody.scroll = "no"
    $oBody.style.borderStyle = "none"
    $oHtml.style.overflow = 'hidden'
    $oBody.style.overflow = 'hidden'

    Local $oIViewObject2 = ObjCreateInterface($oDocument, "{00000127-0000-0000-C000-000000000046}", "Draw hresult(dword;long;ptr;ptr;handle;handle;struct*;struct*;bool;ulong_ptr);")

    If @error Then Return SetError(1, 0, 0)

    Local $BodyWidth = $oBody.scrollWidth
    Local $BodyHeight = $oBody.scrollHeight
    Local $RootWidth = $oHtml.scrollWidth
    Local $RootHeight = $oHtml.scrollHeight

    Local $Width = $BodyWidth
    Local $Height = $RootHeight
    If $BodyHeight > $Height Then $Height = $BodyHeight

    $oIE.width = $Width
    $oIE.height = $Height

    Local $hDC = _WinAPI_GetDC(0)
    Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $Width, $Height)
    _WinAPI_SelectObject($hMemDC, $hBmp)

    Local $sRECT = DllStructCreate($tagRECT)
    DllStructSetData($sRECT, "Top", 0)
    DllStructSetData($sRECT, "Left", 0)
    DllStructSetData($sRECT, "Right", $Width)
    DllStructSetData($sRECT, "Bottom", $Height)

    $oIViewObject2.Draw(1, -1, 0, 0, $hDC, $hMemDC, $sRECT, 0, 0, 0)

    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_ReleaseDC(0, $hDC)

    GUIDelete($hGUI)

    Return $hBmp
EndFunc   ;==>_WebCapture

Edit: Added trancexx remarks from the next post, thanks a lot :)...

Edited by KaFu
Posted (edited)

  On 1/6/2013 at 12:07 PM, 'KaFu said:

Nice :). How about the clean-up I perform at the end of the function?

GUICtrlDelete($cObj)
    GUIDelete($hGUI)
    $oIViewObject2 = 0
    $oIE = 0

When I set the GUI to visible I see it still exists after the function has finished, thus I assume a GUIDelete is appropriate. Is it advisable to delete the controls manually? And also the Objects, are those cleaned by the garbage collector?

Objecs are released for sure, yes. You don't have to reassign variables unless there is some super important order of destroying that needs to be followed.

As for the GUI, I would expect that all the resources are released when the main window is destroyed.

Edited by trancexx

♡♡♡

.

eMyvnE

  • 1 month later...
Posted (edited)

KaFu i have two question about your script:

  • Why don't you make directly:
Func _WebCapture($Url, $ImageName, $WebWidth = 1024)
;the script
Return _ScreenCapture_SaveImage($ImageName, $hBmp, True) ;Return $hBmp
  • I don't want to use the BETA because it's a beta lol, which #include i need to "import" in the stable version? Or what i need to modify for use it?
Edited by OliverA

I'M QUIT FROM THIS FORUM!

  Reveal hidden contents
It was fun until it lasted, hope on my future way i can't find people that offend without any reason ( i was called lazy and parasitic, and everyone agreed...United we stand, divided we fall ) just for fun because don't have anything to do in the life, without knowing anything about the person who write, noone forced to post, noone forced to help.

From the top of the from their very great superiority they not go down to my level, that people can not spread the knowledge but you have to learn by yourself.

In what way? It's easy...just search on google

For that people, wish you the best way,

Oliver Astone

Posted

Hi Oliver,

I use "Return $hBmp" because not everyone might want to directly save the image to disk (e.g. add address overlay, timestamp, create a composite image). If you don't want to use the Beta, you have to use the example from the first post utilizing the AutoItObject UDF instead, your choice :) (the current Beta contains changes in the COM interface, which is a pre-requisite to use this without the AutoItObject UDF).

Regards

  • 5 months later...
Posted (edited)

  On 1/11/2011 at 7:45 PM, JohnOne said:

I wonder if I'm missing something here, the webcap works fine but the elementcap I cant seen to get working.

I get an error from malkeys example

Anyidea what Ive got going on here, I mean I can see that whatever $oIHTMLElementRender is, is isnt an object. But the code is over my head.

 

IE9, IE10 fails DrawToDC call

Local $tIID_IHTMLElementRender = _AutoItObject_CLSIDFromString("{3050F669-98B5-11CF-BB82-00AA00BDCE0B}")

It would be not found the class id {3050F669-98B5-11CF-BB82-00AA00BDCE0B}

not work on ie9, 10

post-81822-0-82751200-1377660837_thumb.j

Edited by COBAY
  • 1 year later...
Posted

Thank to all participant in this thread.
For me this is the next step to make XML > XSL > HTML > PDF converter.

mLipok

 

btw.
Works on IE 11.0.9600.17801
and Au3.3.10.2 and Au3.3.13.20

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 3 years later...
Posted

Not sure if anyone else ran into a problem but it seems like the _GDIPlus_EncodersGetCLSID does not seem to be working as expected. I Ran the example in the help file and got something like this.

  Codec GUID ............: {557CF400-1A04-11D3-9A73-0000F81EF32E}
  File format GUID ......: {B96B3CAB-0728-11D3-9D7B-0000F81EF32E}
  Codec name ............: 0x4275696C742D696E20424D5020436F64656300
  Codec Dll file name ...: 
  Codec file format .....: 0x424D5000
  File name extensions ..: 0x2A2E424D503B2A2E4449423B2A2E524C4500
  Mime type .............: 0x696D6167652F626D7000
  Flags .................: 0x0000000000010007
  Version ...............: 1
  Signature count .......: 1
  Signature size ........: 2
  Signature pattern ptr .: 0x0317E982
  Signature mask ptr ....: 0x0317E984
  Parameter list size ...: 0

 

File name extensions should be more like (BMP, JPG, TIF, etc.) but now its in hex format. I had to change my __ScreenCapture_SaveImage function to know what $sCLSID to use and it worked after that.

No problem can withstand the assault of sustained thinking.Voltaire

_Array2HTMLTable()_IEClassNameGetCollection()_IEquerySelectorAll()

Posted
  On 7/19/2018 at 8:50 PM, uncommon said:

Not sure if anyone else ran into a problem but it seems like the _GDIPlus_EncodersGetCLSID does not seem to be working as expected. I Ran the example in the help file and got something like this.

  Codec GUID ............: {557CF400-1A04-11D3-9A73-0000F81EF32E}
  File format GUID ......: {B96B3CAB-0728-11D3-9D7B-0000F81EF32E}
  Codec name ............: 0x4275696C742D696E20424D5020436F64656300
  Codec Dll file name ...: 
  Codec file format .....: 0x424D5000
  File name extensions ..: 0x2A2E424D503B2A2E4449423B2A2E524C4500
  Mime type .............: 0x696D6167652F626D7000
  Flags .................: 0x0000000000010007
  Version ...............: 1
  Signature count .......: 1
  Signature size ........: 2
  Signature pattern ptr .: 0x0317E982
  Signature mask ptr ....: 0x0317E984
  Parameter list size ...: 0

 

File name extensions should be more like (BMP, JPG, TIF, etc.) but now its in hex format. I had to change my __ScreenCapture_SaveImage function to know what $sCLSID to use and it worked after that.

Expand  

There is a "bug" in _WinAPI_WideCharToMultiByte() .

 

Look here: 

 

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

  • 11 months later...
Posted

 I  have taken the screenshot, but please help me to integrate with html report in selenium. it is not coming/ showing in html report

  • 6 months later...
Posted (edited)

Here's an update from my side:

; https://www.autoitscript.com/forum/topic/124002-web-screenshot/?do=findComment&comment=1043557

#include <IE.au3>
#include <WinAPI.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>

_WebCaptureTest("https://funk.eu", "funk.eu.png")

ShellExecute(@ScriptDir & "\funk.eu.png")

Func _WebCaptureTest($Url, $ImageName)
    Local $hBmp = _WebCapture($Url, 1280)
    _ScreenCapture_SaveImage($ImageName, $hBmp, True)
EndFunc   ;==>_WebCaptureTest

Func _WebCapture($Url, $WebWidth = 1024)

    Local $oIE = ObjCreate("Shell.Explorer.2")
    Local $hGUI = GUICreate("", $WebWidth, 768, -1, -1)
    Local $cObj = GUICtrlCreateObj($oIE, 0, 0, $WebWidth, 768)

    _IELoadWaitTimeout(20000) ; 20 sec
    _IENavigate($oIE, $Url)
    _IELoadWait($oIE)

    Local $oDocument = $oIE.document
    Local $oBody = $oIE.document.body
    Local $oHtml = $oIE.document.documentElement

    $oBody.scroll = "no"
    $oBody.style.borderStyle = "none"
    $oHtml.style.overflow = 'hidden'
    $oBody.style.overflow = 'hidden'

    Local $oIViewObject2 = ObjCreateInterface($oDocument, "{00000127-0000-0000-C000-000000000046}", "Draw hresult(dword;long;ptr;ptr;handle;handle;struct*;struct*;bool;ulong_ptr);")

    If @error Then Return SetError(1, 0, 0)

    Local $BodyWidth = $oBody.scrollWidth
    Local $BodyHeight = $oBody.scrollHeight
    Local $RootWidth = $oHtml.scrollWidth
    Local $RootHeight = $oHtml.scrollHeight

    Local $Width = $BodyWidth
    Local $Height = $RootHeight
    If $BodyHeight > $Height Then $Height = $BodyHeight

    $oIE.width = $Width
    $oIE.height = $Height

    Local $hDC = _WinAPI_GetDC(0)
    Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $Width, $Height)
    _WinAPI_SelectObject($hMemDC, $hBmp)

    Local $sRECT = DllStructCreate($tagRECT)
    DllStructSetData($sRECT, "Top", 0)
    DllStructSetData($sRECT, "Left", 0)
    DllStructSetData($sRECT, "Right", $Width)
    DllStructSetData($sRECT, "Bottom", $Height)

    $oIViewObject2.Draw(1, -1, 0, 0, $hDC, $hMemDC, $sRECT, 0, 0, 0)

    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_ReleaseDC(0, $hDC)

    GUIDelete($hGUI)

    Return $hBmp
EndFunc   ;==>_WebCapture

 

Edited by KaFu
Posted
  On 1/8/2020 at 9:54 AM, KaFu said:

Here's an update from my side:

Expand  

Works well, thanks for sharing. :)

I love how it captures the whole page, beyond what you see in the visible portion in your browser (without scrolling).

I did a little edit at the start of your script, just to make testing for me a bit easier.

#include <IE.au3>
#include <WinAPI.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>
#include <Date.au3>

Global $http, $image, $imgpth

;$http = "https://funk.eu"
$http = "https://www.autoitscript.com/forum/topic/124002-web-screenshot/page/2/"
$image = StringSplit($http, "/", 1)
$image = $image[$image[0]]
If $image = "" Then
    $image = StringReplace(_Now(), "/", "-")
    $image = StringReplace($image, ":", "_")
EndIf
$image = $image & ".png"
$imgpth = @ScriptDir & "\" & $image

_WebCaptureTest($http, $image)

ShellExecute($imgpth)

Exit

I am also pondering adding a Splash in, due to the delay ... certainly on my PC.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

  Reveal hidden contents

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted

@KaFu you should release the bitmap handle when done in function _WebCaptureTest():

 

Func _WebCaptureTest($Url, $ImageName)
    Local $hBmp = _WebCapture($Url, 1280)
    _ScreenCapture_SaveImage($ImageName, $hBmp, True)
    _WinAPI_DeleteObject($hBmp)
EndFunc   ;==>_WebCaptureTest

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted
  On 1/8/2020 at 1:34 PM, KaFu said:

@UEZ The "True" in _ScreenCapture_SaveImage() will do just that 😉.

Expand  

Well, it seems that I've overseen the 3rd parameter ($bFreeBmp) ... :whistle:

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

Pondering further, it seems to me that because the resulting image can have odd dimensions when it comes to height, that a split option based on user's screen height might be a nice additional option to have via a parameter... keeping the original image file as well of course.

As an example, my capture of this page when I did it, was 1276 (w) x 14692 (h).

That takes some zooming in to see detail .... depending on your viewer program.

Of course, splitting to a series of separate image files could be the job of a companion program, but would be nice to be all-in-one.

Maybe our resident graphic's expert UEZ could whip up something.

I might even dabble myself ... if I get some time and feel like getting my head around the maths.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

  Reveal hidden contents

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted

Something like this?

; https://www.autoitscript.com/forum/topic/124002-web-screenshot/?do=findComment&comment=1043557

#include <IE.au3>
#include <WinAPI.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>

_WebCaptureTest("https://funk.eu", "funk.eu.png", 1000)

ShellExecute(@ScriptDir & "\funk.eu.png")

Func _WebCaptureTest($Url, $ImageName, $iMaxHeight = 0)
    Local $hBmp = _WebCapture($Url, 1280)
    _ScreenCapture_SaveImage($ImageName, $hBmp, False)

    If $iMaxHeight <> 0 Then
        _GDIPlus_Startup()
        Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
        Local $iX = _GDIPlus_ImageGetWidth($hImage)
        Local $iY = _GDIPlus_ImageGetHeight($hImage)
        Local $i_Pics = Ceiling($iY / $iMaxHeight)
        Local $i_Offset = 0, $hBmp_Clone, $iHeight_to_Clone = $iY
        For $i = 1 To $i_Pics
            If $iMaxHeight > $iHeight_to_Clone Then $iMaxHeight = $iHeight_to_Clone
            $hBmp_Clone = _GDIPlus_BitmapCloneArea($hImage, 0, 0 + $i_Offset, $iX, $iMaxHeight)
            _GDIPlus_ImageSaveToFile($hBmp_Clone, StringTrimRight($ImageName, 4) & "_" & $i & StringRight($ImageName, 4))
            _GDIPlus_ImageDispose($hBmp_Clone)
            $iHeight_to_Clone -= $iMaxHeight
            $i_Offset += $iMaxHeight
        Next
        _GDIPlus_ImageDispose($hImage)
        _GDIPlus_Shutdown()
    EndIf

    _WinAPI_DeleteObject($hBmp)

EndFunc   ;==>_WebCaptureTest

Func _WebCapture($Url, $WebWidth = 1024)

    Local $oIE = ObjCreate("Shell.Explorer.2")
    Local $hGUI = GUICreate("", $WebWidth, 768, -1, -1)
    Local $cObj = GUICtrlCreateObj($oIE, 0, 0, $WebWidth, 768)

    _IELoadWaitTimeout(20000) ; 20 sec
    _IENavigate($oIE, $Url)
    _IELoadWait($oIE)

    Local $oDocument = $oIE.document
    Local $oBody = $oIE.document.body
    Local $oHtml = $oIE.document.documentElement

    $oBody.scroll = "no"
    $oBody.style.borderStyle = "none"
    $oHtml.style.overflow = 'hidden'
    $oBody.style.overflow = 'hidden'

    Local $oIViewObject2 = ObjCreateInterface($oDocument, "{00000127-0000-0000-C000-000000000046}", "Draw hresult(dword;long;ptr;ptr;handle;handle;struct*;struct*;bool;ulong_ptr);")

    If @error Then Return SetError(1, 0, 0)

    Local $BodyWidth = $oBody.scrollWidth
    Local $BodyHeight = $oBody.scrollHeight
    Local $RootWidth = $oHtml.scrollWidth
    Local $RootHeight = $oHtml.scrollHeight

    Local $Width = $BodyWidth
    Local $Height = $RootHeight
    If $BodyHeight > $Height Then $Height = $BodyHeight

    $oIE.width = $Width
    $oIE.height = $Height

    Local $hDC = _WinAPI_GetDC(0)
    Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $Width, $Height)
    _WinAPI_SelectObject($hMemDC, $hBmp)

    Local $sRECT = DllStructCreate($tagRECT)
    DllStructSetData($sRECT, "Top", 0)
    DllStructSetData($sRECT, "Left", 0)
    DllStructSetData($sRECT, "Right", $Width)
    DllStructSetData($sRECT, "Bottom", $Height)

    $oIViewObject2.Draw(1, -1, 0, 0, $hDC, $hMemDC, $sRECT, 0, 0, 0)

    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_ReleaseDC(0, $hDC)

    GUIDelete($hGUI)

    Return $hBmp
EndFunc   ;==>_WebCapture

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...