Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/02/2011 in all areas

  1. Ward

    Web Screenshot

    This script demonstrate how to save the web page, or just the specified element to an image file. Two COM interface were used in the script (IViewObject2 for entire page, and IHTMLElementRender for an element) Some code was modified from IECapt. This script needs (Thanks to trancexx, she help me to solve a problem.) #Include <IE.au3> #Include <WinAPI.au3> #Include <ScreenCapture.au3> #Include <WindowsConstants.au3> #Include "AutoItObject.au3" _AutoItObject_StartUp() OnAutoItExitRegister('OnExit') WebCaptureTest("http://en.wikipedia.org/wiki/AutoIt", "Test1.png") ElementCaptureTest("http://en.wikipedia.org/wiki/AutoIt", "Test2.png") Func OnExit() _AutoItObject_Shutdown() EndFunc Func WebCaptureTest($Url, $ImageName) Local $hBmp = WebCapture($Url, 1280) _ScreenCapture_SaveImage($ImageName, $hBmp, True) EndFunc Func ElementCaptureTest($Url, $ImageName) Local $WebWidth = 1280 Local $oIE = ObjCreate("Shell.Explorer.2") GUICreate("", $WebWidth, 768, -1, -1) GUICtrlCreateObj($oIE, 0, 0 , $WebWidth, 768) _IENavigate($oIE, $Url) Local $oElement = $oIE.document.documentElement If $oElement.clientWidth = 0 Then $oElement = $oIE.document.body Local $hBmp = ElementCapture($oElement) _ScreenCapture_SaveImage($ImageName, $hBmp, True) EndFunc Func WebCapture($Url, $WebWidth = 1024) Local Const $DVASPECT_CONTENT = 1 Local $tIID_IViewObject2 = _AutoItObject_CLSIDFromString("{00000127-0000-0000-C000-000000000046}") Local $dtagIViewObject2 = $dtagIUnknown & "Draw hresult(dword;long;ptr;ptr;dword;dword;ptr;ptr;int;dword);" Local $oIE = ObjCreate("Shell.Explorer.2") GUICreate("", $WebWidth, 768, -1, -1) GUICtrlCreateObj($oIE, 0, 0 , $WebWidth, 768) _IENavigate($oIE, $url) 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 = _AutoItObject_WarpInterface($oDocument, $tIID_IViewObject2, $dtagIViewObject2) 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($DVASPECT_CONTENT, -1, 0, 0, Number($hDC), Number($hMemDC), Number(DllStructGetPtr($sRECT)), 0, 0, 0) _WinAPI_DeleteDC($hMemDC) _WinAPI_ReleaseDC(0, $hDC) Return $hBmp EndFunc Func ElementCapture($oElement, $Border = 2) If Not IsObj($oElement) Then Return SetError(1, 0, 0) If $oElement.clientWidth = 0 Or $oElement.clientHeight = 0 Then Return SetError(1, 0, 0) Local $tIID_IHTMLElementRender = _AutoItObject_CLSIDFromString("{3050F669-98B5-11CF-BB82-00AA00BDCE0B}") Local $dtagIHTMLElementRender = $dtagIUnknown & "DrawToDC hresult(hwnd);" Local $PageHeight = $oElement.scrollHeight - $Border Local $PageWidth = $oElement.scrollWidth - $Border Local $oIHTMLElementRender = _AutoItObject_WarpInterface($oElement, $tIID_IHTMLElementRender, $dtagIHTMLElementRender) Local $hDC = _WinAPI_GetDC(0) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBmp = _WinAPI_CreateSolidBitmap(0, 0xffffff, $oElement.clientWidth, $oElement.clientHeight) Local $hMemDcFull = _WinAPI_CreateCompatibleDC($hDC) Local $hBmpFull = _WinAPI_CreateSolidBitmap(0, 0xffffff, $PageWidth, $PageHeight) _WinAPI_SelectObject($hMemDc, $hBmp) _WinAPI_SelectObject($hMemDcFull, $hBmpFull) Local $DrawWidth = $oElement.clientWidth - $Border Local $DrawHeight = $oElement.clientHeight - $Border Local $CurrentX = 0 Local $CurrentY = 0 While $CurrentX < $PageWidth While $CurrentY < $PageHeight $oElement.scrollLeft = $CurrentX $oElement.scrollTop = $CurrentY $oIHTMLElementRender.DrawToDC(Number($hMemDC)) _WinAPI_BitBlt($hMemDcFull, $oElement.scrollLeft, $oElement.scrollTop, $DrawWidth, $DrawHeight, $hMemDC, $Border, $Border, $SRCCOPY) $CurrentY += $DrawHeight WEnd $CurrentY = 0 $CurrentX += $DrawWidth WEnd _WinAPI_DeleteDC($hMemDC) _WinAPI_DeleteDC($hMemDcFull) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_DeleteObject($hBmp) Return $hBmpFull EndFunc Func _AutoItObject_WarpInterface($Obj, $IID, $Tag, $fNoUnknown = False) If Not IsDllStruct($IID) Then $IID = _AutoItObject_CLSIDFromString($IID) If Not IsObj($Obj) Then Return SetError(1, 0, 0) Local $pObj = _AutoItObject_IDispatchToPtr($Obj) If Not _AutoItObject_IUnknownAddRef($Obj) Then Return SetError(1, 0, 0) Local $ObjWarpped = _AutoItObject_WrapperCreate($pObj, $dtagIUnknown, $fNoUnknown) Local $aCall = $ObjWarpped.QueryInterface(Number(DllStructGetPtr($IID)), 0) If Not IsArray($aCall) And $aCall[0] <> 0 Then Return SetError(1, 0, 0) Local $pInterface = $aCall[2] Return _AutoItObject_WrapperCreate($pInterface, $Tag) EndFunc
    1 point
  2. wraithdu

    Latest Beta

    I just tested your example on a Win7 x64 machine with AutoIt 3.3.7.21, and all 4 functions were successful. Edit: BTW, INVALID_HANDLE_VALUE should be Ptr(-1). Be careful with implied data type conversions.
    1 point
×
×
  • Create New...