Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/30/2022 in all areas

  1. No, MozRepl only works up to FireFox 57. Use WebDriver for later versions. WebDriver UDF: Wiki: https://www.autoitscript.com/wiki/WebDriver
    2 points
  2. It is located in a subdirectory of SciTE.
    1 point
  3. Moved to the appropriate AutoIt General Help and Support forum, as the Developer General Discussion forum very clearly states: It seems to be difficult for you to pick the correct forum, so please tell us which part of this standard message is unclear to you? Moderation Team
    1 point
  4. If you're using FF57 or below, or Waterfox classic, then you can install the MozRepl plugin, that establishes a Telnet based connection on port 4242 with the browser. Then you can use: TCPStartup() Local $Socket = TCPConnect("127.0.0.1", 4242) Local $Send = TCPSend("enter javascript here")
    1 point
  5. What have you tried so far? Which extension do we talk about?
    1 point
  6. jchd

    Assign Function Abnomily

    Then make your array 2D and store the controlID (useless for labels in most use cases) and the text. Or better yet, use a Map. I've yet to see real-world code where Assign() is required or even useful.
    1 point
  7. Moved to the appropriate forum. Moderation Team
    1 point
  8. Hi Parsix, I cannot test it properly because I get "Rasdial msg = 623". I assume to establish the Ras connectivity I need to run it with real credentials. I suspect that the RasDialW call somehow blocks the SetTimer function, because the _LoadingScreen_Spinner function looks fine so far at first glance. I don't know if it possible to run the animation in a separate thread...
    1 point
  9. 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
  10. Here to get you started with Notepad though : #include <Constants.au3> #include <WinAPISysWin.au3> #include <WindowsConstants.au3> #include <GuiMenu.au3> #include <WinAPIConv.au3> Opt ("MustDeclareVars", 1) Run ("Notepad.exe") Local $iDWord = _WinAPI_MakeLong (0x200, 0x120) ; ($x, $y) Local $hWnd = WinWaitActive ("[CLASS:Notepad]") Local $hCtrl = ControlGetHandle ($hWnd, "", "Edit1") _WinAPI_PostMessage ($hCtrl, $WM_CONTEXTMENU, 0, $iDWord) Sleep (800) Local $hMenuWnd = WinGetHandle ("[CLASS:#32768]") Local $hMenu = _SendMessage($hMenuWnd, $MN_GETHMENU) If Not _GUICtrlMenu_IsMenu($hMenu) Then Exit MsgBox ($MB_SYSTEMMODAL,"","Unable to retrieve context menu handle") Local $iCount = _GUICtrlMenu_GetItemCount ($hMenu) For $i = 0 to $iCount-1 ConsoleWrite (_GUICtrlMenu_GetItemText ($hMenu, $i) & @CRLF) Next
    1 point
  11. Here a small function to mark a region on the desktop and capture that region to a bitmap handle or to the clipboard: #include-once #include <Clipboard.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WinAPIGdi.au3> #include <WindowsConstants.au3> #Region Example ;capture manual coordinates FileDelete(@ScriptDir & "\Captured.bmp") Global $hHBitmap = _WinAPI_MarkScreenRegionAndCapture(0, False, True, 0, 0, 99, 99) _WinAPI_SaveHBITMAPToFile(@ScriptDir & "\Captured.bmp", $hHBitmap) _WinAPI_DeleteObject($hHBitmap) If FileExists(@ScriptDir & "\Captured.bmp") Then ShellExecute(@ScriptDir & "\Captured.bmp") ;save the captured bitmap to a file FileDelete(@ScriptDir & "\Captured.bmp") Global $hHBitmap = _WinAPI_MarkScreenRegionAndCapture() _WinAPI_SaveHBITMAPToFile(@ScriptDir & "\Captured.bmp", $hHBitmap) _WinAPI_DeleteObject($hHBitmap) If FileExists(@ScriptDir & "\Captured.bmp") Then ShellExecute(@ScriptDir & "\Captured.bmp") ;copy captured bitmap to clipboard Switch _WinAPI_MarkScreenRegionAndCapture(1, True) Case 1 MsgBox($MB_ICONINFORMATION, "Information", "Marked region was properly captured to clipboard!", 30) Case 0 MsgBox($MB_ICONERROR, "ERROR", "An error has occured!", 30) EndSwitch #EndRegion ; #FUNCTION# ==================================================================================================================== ; Name ..........: _WinAPI_MarkScreenRegionAndCapture ; Description ...: Selected area on desktop will be captured and save to clipbord or GDI bitmap handle will be returned. ; Syntax ........: _WinAPI_MarkScreenRegionAndCapture([$iFillMode = 0[, $bClipboard = True]]) ; Parameters ....: $iFillMode - [optional] an integer value. Default is 0. ; 0: marked area filled with solid color ; 1: marked area filled with hatch pattern ($HS_DIAGCROSS) ; 2: marked area without any fill pattern / color - only red border ; $bClipboard - [optional] a boolean value. Default is False. If True then no GDI bitmap handle will be returned. ; If false then GDI bitmap handle will be returned. ; $bManual - [optional] a boolean value. Default is False. If True manual capturing is activated. ; $iX1 - [optional] an integer value. Default is 0. If $bManual is true enter the x1 screen pos. ; $iY1 - [optional] an integer value. Default is 0. If $bManual is true enter the Y1 screen pos. ; $iX2 - [optional] an integer value. Default is 0. If $bManual is true enter the x2 screen pos. ; $iY2 - [optional] an integer value. Default is 0. If $bManual is true enter the y2 screen pos. ; Return values .: 0 / 1 / -1 / GDI bitmap handle ; Author ........: UEZ ; Version .......: 0.92 build 2017-01-22 ; Modified ......: ; Remarks .......: Do not forget to dispose returned GDI bitmap handle for non clipboard mode using _WinAPI_DeleteObject! ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _WinAPI_MarkScreenRegionAndCapture($iFillMode = 0, $bClipboard = False, $bManual = False, $iX1 = 0, $iY1 = 0, $iX2 = 0, $iY2 = 0) If @OSBuild > 6299 Then ;https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx DllCall("Shcore.dll", "long", "PROCESS_DPI_AWARENESS", 1) ;PROCESS_SYSTEM_DPI_AWARE = 1 (https://msdn.microsoft.com/en-us/library/windows/desktop/dn280512(v=vs.85).aspx) Else DllCall("User32.dll", "bool", "SetProcessDPIAware") EndIf Local $iOld = AutoItSetOption("MouseCoordMode", 1) If Not $bManual Then Local Const $hDesktop = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]") Local Const $aFullScreen = WinGetPos($hDesktop) ;should work also on multi screens Local Const $iW = $aFullScreen[2], $iH = $aFullScreen[3] Local Const $hGUI_Screencapture = GUICreate("", $iW, $iH, $aFullScreen[0], $aFullScreen[1], $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED)) GUISetState(@SW_SHOW, $hGUI_Screencapture) Local Const $hDC = _WinAPI_GetDC($hGUI_Screencapture) Local Const $hGfxDC = _WinAPI_CreateCompatibleDC($hDC) Local Const $hBitmapGDI = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) Local $hObjOld = _WinAPI_SelectObject($hGfxDC, $hBitmapGDI) Local $tSize = DllStructCreate($tagSIZE) $tSize.x = $iW $tSize.y = $iH Local $tSource = DllStructCreate($tagPOINT) Local $tBlend = DllStructCreate($tagBLENDFUNCTION) $tBlend.Alpha = 0xFF $tBlend.Format = 1 Local $tDest = DllStructCreate($tagPOINT), $pPoint = DllStructGetPtr($tDest) $tDest.x = $aFullScreen[0] $tDest.y = $aFullScreen[1] Local Const $hPen = _WinAPI_CreatePen($PS_SOLID, 1, 0x0000FF) Local Const $hPen_Orig = _WinAPI_SelectObject($hGfxDC, $hPen) Local $hBrush, $iAlpha2, $iFlag $iFillMode = $iFillMode > 2 ? 2 : $iFillMode < 0 ? 0 : $iFillMode Switch $iFillMode Case 0 $hBrush = _WinAPI_CreateBrushIndirect($BS_SOLID, 0x808080) $iAlpha2 = 0xA0 $iFlag = $ULW_ALPHA Case 1 $hBrush = _WinAPI_CreateBrushIndirect($BS_HATCHED, 0x808000, $HS_DIAGCROSS) $iAlpha2 = 0x30 $iFlag = $ULW_ALPHA Case 2 $hBrush = _WinAPI_CreateBrushIndirect($BS_HOLLOW, 0x000000) $iAlpha2 = 0xFF ;not needed $iFlag = $ULW_COLORKEY EndSwitch Local $hBrush_Orig = _WinAPI_SelectObject($hGfxDC, $hBrush) Else If Not BitOr($iX1, $iX2, $iY1, $iY2) Then Return SetError(4, 0, 0) EndIf Local $aMPos[5], $aMPos_old[4], $tRECT = _WinAPI_CreateRect(0, 0, 0, 0) Do If $bManual Then $aMPos[2] = 1 Else GUISetCursor(16, 1, $hGUI_Screencapture) $aMPos = GUIGetCursorInfo($hGUI_Screencapture) $aMPos_old[0] = $aMPos[0] $aMPos_old[1] = $aMPos[1] $aMPos_old[2] = MouseGetPos(0) $aMPos_old[3] = MouseGetPos(1) EndIf Switch $aMPos[2] Case 0 ;display crosshair _WinAPI_BitBlt($hGfxDC, 0, 0, $iW, $iH, $hGfxDC, 0, 0, $CAPTUREBLT) _WinAPI_DrawLine($hGfxDC, $tDest.x, $aMPos[1], $iW, $aMPos[1]) _WinAPI_DrawLine($hGfxDC, $aMPos[0], $tDest.y, $aMPos[0], $iH) _WinAPI_UpdateLayeredWindow($hGUI_Screencapture, $hDC, $tDest, $tSize, $hGfxDC, $tSource, 0, $tBlend, $ULW_COLORKEY) Case 1 ;capture selected region If Not $bManual Then $tBlend.Alpha = $iAlpha2 While $aMPos[2] ;mark region GUISetCursor(14, 1, $hGUI_Screencapture) ;WinGetHandle(AutoItWinGetTitle())) $aMPos = GUIGetCursorInfo($hGUI_Screencapture) _WinAPI_BitBlt($hGfxDC, 0, 0, $iW, $iH, $hGfxDC, 0, 0, $CAPTUREBLT) ;clear bitmap ;draw rectangle $tRECT.Left = $aMPos_old[0] $tRECT.Top = $aMPos_old[1] $tRECT.Right = $aMPos[0] $tRECT.Bottom = $aMPos[1] _WinAPI_Rectangle($hGfxDC, $tRECT) If $iFillMode <> 2 Then _WinAPI_InvertRect($hGfxDC, $tRECT) _WinAPI_UpdateLayeredWindow($hGUI_Screencapture, $hDC, $tDest, $tSize, $hGfxDC, $tSource, 0, $tBlend, $iFlag) Sleep(10) WEnd _WinAPI_SelectObject($hGfxDC, $hObjOld) _WinAPI_ReleaseDC($hGUI_Screencapture, $hDC) _WinAPI_DeleteDC($hGfxDC) _WinAPI_DeleteObject($hBitmapGDI) _WinAPI_SelectObject($hGfxDC, $hPen_Orig) _WinAPI_DeleteObject($hPen) _WinAPI_SelectObject($hGfxDC, $hBrush_Orig) _WinAPI_DeleteObject($hBrush) GUIDelete($hGUI_Screencapture) ;capture region $aMPos[0] = MouseGetPos(0) $aMPos[1] = MouseGetPos(1) Else $aMPos_old[2] = $iX1 $aMPos_old[3] = $iY1 $aMPos[0] = $iX2 $aMPos[1] = $iY2 EndIf Local Const $hDC_Region = _WinAPI_GetDC(0) Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Region) Local Const $iW_Region = Abs($aMPos[0] - $aMPos_old[2]) + 1, $iH_Region = Abs($aMPos[1] - $aMPos_old[3]) + 1 Local $hHBitmap_Captured = _WinAPI_CreateCompatibleBitmap($hDC_Region, $iW_Region, $iH_Region) $hObjOld = _WinAPI_SelectObject($hMemDC, $hHBitmap_Captured) _WinAPI_BitBlt($hMemDC, 0, 0, $iW_Region, $iH_Region, $hDC_Region, _ $aMPos[0] > $aMPos_old[2] ? $aMPos_old[2] : $aMPos[0], _ $aMPos[1] > $aMPos_old[3] ? $aMPos_old[3] : $aMPos[1], BitOR($SRCCOPY, $CAPTUREBLT)) Local $hHBitmap_Clipboard = _WinAPI_CopyImage($hHBitmap_Captured, 0, 0, 0, BitOR($LR_COPYDELETEORG, $LR_COPYRETURNORG)) _WinAPI_SelectObject($hHBitmap_Captured, $hObjOld) _WinAPI_DeleteDC($hHBitmap_Captured) _WinAPI_ReleaseDC(0, $hDC_Region) AutoItSetOption("MouseCoordMode", $iOld) If $bClipboard Then ;put captured region to clipboard If Not _ClipBoard_Open(0) Then _WinAPI_DeleteObject($hHBitmap_Clipboard) Return SetError(1, 0, 0) EndIf If Not _ClipBoard_Empty() Then _WinAPI_DeleteObject($hHBitmap_Clipboard) Return SetError(2, 0, 0) EndIf Local Const $hCP = _ClipBoard_SetDataEx($hHBitmap_Clipboard, $CF_BITMAP) If Not $hCP Or @error Then _WinAPI_DeleteObject($hHBitmap_Clipboard) Return SetError(3, 0, 0) EndIf _ClipBoard_Close() _WinAPI_DeleteObject($hHBitmap_Clipboard) Return 1 Else Return $hHBitmap_Clipboard EndIf EndSwitch Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _WinAPI_SelectObject($hGfxDC, $hObjOld) _WinAPI_ReleaseDC($hGUI_Screencapture, $hDC) _WinAPI_DeleteDC($hGfxDC) _WinAPI_DeleteObject($hBitmapGDI) _WinAPI_SelectObject($hGfxDC, $hPen_Orig) _WinAPI_DeleteObject($hPen) GUIDelete($hGUI_Screencapture) AutoItSetOption("MouseCoordMode", $iOld) Return -1 EndSwitch Until False EndFunc ;==>_WinAPI_MarkScreenRegionAndCapture Might be useful... Download: _WinAPI_MarkScreenRegionAndCapture.au3 (same as above in the code box) Tested only on Win10 x64 but should work also on other Window versions. If not please reply.
    1 point
  12. I have lot's of images like this http://postimg.org/image/uz24d8z27/ http://postimg.org/image/5isx6mc61/ i would like to crop the page number (the arabic number on the top of the page) so it would be something like this ... any ideas ?
    1 point
  13. KaFu

    Web Screenshot

    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
    1 point
  14. KaFu

    Web Screenshot

    Just remembered this one and tried to make it work without AutoItObject, requires Beta to run properly . #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 Global $dtagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _ "AddRef dword();" & _ "Release dword();" Global Const $gh_AU3Obj_ole32dll = DllOpen("ole32.dll") 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 Const $DVASPECT_CONTENT = 1 Local $tIID_IViewObject2 = _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) _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) $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 ;==>WebCapture Func _CLSIDFromString($sString) Local $tCLSID = DllStructCreate("dword;word;word;byte[8]") Local $aResult = DllCall($gh_AU3Obj_ole32dll, 'long', 'CLSIDFromString', 'wstr', $sString, 'ptr', DllStructGetPtr($tCLSID)) If @error Then Return SetError(1, @error, 0) If $aResult[0] <> 0 Then Return SetError(2, $aResult[0], 0) Return $tCLSID EndFunc ;==>_CLSIDFromString
    1 point
  15. Here an modified example from here: #include <GDIplus.au3> #include <GUIConstantsEx.au3> #Include <Memory.au3> Opt("MustDeclareVars", 1) _GDIPlus_Startup() Global $hStream, $nMsg Global $sUrls = "http://www.autoitscript.com/autoit3/files/graphics/autoit9_wall_1280x1024.jpg|http://autoit-script.ru/autoit_rv_ua/files/Pictures/autoit_builder_wall_1024x768.jpg|" & _ "http://www.autoitscript.com/autoit3/files/graphics/autoit_matrix_wall_1920x1200.jpg|http://alex-imka.de/autoit/1.jpg|http://alex-imka.de/autoit/3.jpg" Global $aURLS = StringSplit($sUrls, "|", 2) Global $s = InetRead($aURLS[Random(0, UBound($aURLS) - 1, 1)]) Global $hMem = _MemGlobalAllocFromBinary($s) Global $hImage = _GDIPlus_ImageLoadFromHGlobal($hMem) Global $iWidth = Int(@DesktopWidth * 0.75) Global $iHeight = Int(@DesktopHeight * 0.75) Global $hWnd = GUICreate("Display image from internet", $iWidth, $iHeight) GUISetState(@SW_SHOW) Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd) _GDIPlus_GraphicsDrawImageRect ($hGraphics, $hImage, 0, 0, $iWidth, $iHeight);copy bitmap to GUI GUISetState() GUIRegisterMsg(0x0014, "WM_ERASEBKGND") Global $timer = TimerInit() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _GDIPlus_BitmapDispose($hImage) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() GUIDelete($hWnd) Exit EndSwitch If TimerDiff($timer) > 5000 Then _GDIPlus_BitmapDispose($hImage) $s = InetRead($aURLS[Random(0, UBound($aURLS) - 1, 1)]) $hMem = _MemGlobalAllocFromBinary($s) $hImage = _GDIPlus_ImageLoadFromHGlobal($hMem) _GDIPlus_GraphicsDrawImageRect ($hGraphics, $hImage, 0, 0, $iWidth, $iHeight) $timer = TimerInit() EndIf WEnd Func WM_ERASEBKGND($hWnd, $uMsgm, $wParam, $lParam) _GDIPlus_GraphicsDrawImageRect ($hGraphics, $hImage, 0, 0, $iWidth, $iHeight) Return True EndFunc ;==>WM_ERASEBKGND ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_ImageLoadFromHGlobal ; Description ...: Creates an Image object based on movable HGlobal memory block ; Syntax.........: _GDIPlus_ImageLoadFromHGlobal($hGlobal) ; Parameters ....: $hGlobal - Handle of a movable HGlobal memory block ; Return values .: Success - Pointer to a new Image object ; Failure - 0 and either: ; |@error and @extended are set if DllCall failed: ; | -@error = 1 if could not create IStream ; | -@error = 2 if DLLCall to create image failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; Author ........: ProgAndy ; Modified.......: ; Remarks .......: After you are done with the object, call _GDIPlus_ImageDispose to release the object resources. ; The HGLOBAL will be owned by the image and freed automatically when the image is disposed. ; Related .......: _GDIPlus_ImageLoadFromStream, _GDIPlus_ImageDispose ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _GDIPlus_ImageLoadFromHGlobal($hGlobal) Local $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $hGlobal, "bool", True, "ptr*", 0) If @error Or $aResult[0] <> 0 Or $aResult[3] = 0 Then Return SetError(1, @error, 0) Local $hBitmap = _GDIPlus_BitmapCreateFromStream($aResult[3]) Local $error = @error Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr") Local $aCall = DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $aResult[3], "dword", 8 + 8 * @AutoItX64, "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) If $error Then Return SetError(2, $error, 0) Return $hBitmap EndFunc ;==>_GDIPlus_ImageLoadFromHGlobal ; #FUNCTION# ==================================================================================================================== ; Name...........: _MemGlobalAllocFromBinary ; Description ...: Greates a movable HGLOBAL memory block from binary data ; Syntax.........: _MemGlobalAllocFromBinary($bBinary) ; Parameters ....: $bBinary - Binary data ; Return values .: Success - Handle of a new movable HGLOBAL ; Failure - 0 and set @error: ; |1 - no data ; |2 - could not allocate memory ; |3 - could not set data to memory ; Author ........: ProgAndy ; Modified.......: ; Remarks .......: ; Related .......: _MemGlobalAlloc, _MemGlobalFree, _MemGlobalLock ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _MemGlobalAllocFromBinary(Const $bBinary) Local $iLen = BinaryLen($bBinary) If $iLen = 0 Then Return SetError(1, 0, 0) Local $hMem = _MemGlobalAlloc($iLen, $GMEM_MOVEABLE) If @error Or Not $hMem Then Return SetError(2, 0, 0) DllStructSetData(DllStructCreate("byte[" & $iLen & "]", _MemGlobalLock($hMem)), 1, $bBinary) If @error Then _MemGlobalUnlock($hMem) _MemGlobalFree($hMem) Return SetError(3, 0, 0) EndIf _MemGlobalUnlock($hMem) Return $hMem EndFunc ;==>_MemGlobalAllocFromBinary ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_BitmapCreateFromStream ; Description ...: Creates a Bitmap object based on an IStream COM interface ; Syntax.........: _GDIPlus_BitmapCreateFromStream($pStream) ; Parameters ....: $pStream - Pointer to an IStream COM interface ; Return values .: Success - Returns a handle to a new Bitmap object ; Failure - 0 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; Remarks .......: After you are done with the object, call _GDIPlus_ImageDispose to release the object resources ; Related .......: _GDIPlus_ImageDispose, _WinAPI_CreateStreamOnHGlobal ; Link ..........; @@MsdnLink@@ GdipCreateBitmapFromStream ; Example .......; Yes ; =============================================================================================================================== Func _GDIPlus_BitmapCreateFromStream($pStream) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $pStream, "int*", 0) If @error Then Return SetError(@error, @extended, 0) Return $aResult[2] EndFunc ;==>_GDIPlus_BitmapCreateFromStream Might be helpful for you. Br, UEZ
    1 point
  16. I have made some updates to incoperate the supplied script with my own. Give it a run and see if it meets your needs. I tested it with disabled buttons on the Calculate program verifying it against the AutoIt info tool. Changes: Uses a different method to get the control handle and has added control highlighting. This can be removed it not required. ; =============================================================================== ;~ This script gets the control under the mouse pointer (active or inactive) ;~ The information then can be used with in conjunction with control functions. ;~ Requires AutoIt v3.3.6.0 or later to run and to view apps maximized. ;~ Big thanks to SmOke_N and Valik their help in creating it. ; =============================================================================== #include <WinAPI.au3> #include <Array.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <Misc.au3> AutoItSetOption("MustDeclareVars", 1) Opt("GuiOnEventMode", 1) ;~ AutoItSetOption("MouseCoordMode", 1) AdlibRegister("_Mouse_Control_GetInfoAdlib", 10) HotKeySet("^!x", "MyExit") ; Press Ctrl+Alt+x to stop the script HotKeySet("{ESC}", "MyExit") ;~ #AutoIt3Wrapper_run_debug_mode=Y Global $ahGUI[4] Global $Frame_Color = 0xff0000;0xFF0000 Global $Frame_Width = 2 Global $pos1 = MouseGetPos() Global $pos2 = MouseGetPos() ; must be initialized Global $appHandle = 0 Global $dll = DllOpen("user32.dll") While 1 Sleep(0xFFFFFFF) WEnd ; =============================================================================== ;~ Retrieves the information of a Control located under the mouse and displayes it in a tool tip next to the mouse. ;~ Function uesd ;~ _Mouse_Control_GetInfo() ;~ GetDlgCtrlID ; =============================================================================== Func _Mouse_Control_GetInfoAdlib() Local $Last_hControl = 0 Local $aCtrlPos[4], $aNewCtrlPos[4] $pos1 = MouseGetPos() If $pos1[0] <> $pos2[0] Or $pos1[1] <> $pos2[1] Then ; has the mouse moved? Local $a_info = _Mouse_Control_GetInfo() Local $aDLL = DllCall('User32.dll', 'int', 'GetDlgCtrlID', 'hwnd', $a_info[0]) ; get the ID of the control If @error Then Return ToolTip("Handle = " & $a_info[0] & @CRLF & _ "Class = " & $a_info[1] & @CRLF & _ "ID = " & $aDLL[0] & @CRLF & _ "Mouse X Pos = " & $a_info[2] & @CRLF & _ "Mouse Y Pos = " & $a_info[3] & @CRLF & _ "ClassNN = " & $a_info[4] & @CRLF & _ ; optional "Parent Hwd = " & _WinAPI_GetAncestor($appHandle, $GA_ROOT)) $pos2 = MouseGetPos() ; Highlighting If $a_info[0] <> 0 And $Last_hControl <> $a_info[0] And Not IsHighLight_GUIs($a_info[0]) Then If Not _IsPressed("1") Then $Last_hControl = $a_info[0] $aCtrlPos = WinGetPos($a_info[0]) GUISquareDelete() GUICreateSquare($aCtrlPos[0], $aCtrlPos[1], $aCtrlPos[2], $aCtrlPos[3]) EndIf Else $aNewCtrlPos = WinGetPos($a_info[0]) For $n = 0 To 3 If $aCtrlPos[$n] <> $aNewCtrlPos[$n] Then GUISquareDelete() $a_info[0] = 0 $Last_hControl = 0 ExitLoop EndIf Next EndIf EndIf EndFunc ;==>_Mouse_Control_GetInfoAdlib ; =============================================================================== ;~ Retrieves the information of a Control located under the mouse. ;~ Uses Windows functions WindowFromPoint and GetClassName to retrieve the information. ;~ Functions used ;~ WindowFromPoint() ;~ _ControlGetClassnameNN() ;~ Returns ;~ [0] = Control Handle of the control ;~ [1] = The Class Name of the control ;~ [2] = Mouse X Pos (converted to Screen Coord) ;~ [3] = Mouse Y Pos (converted to Screen Coord) ;~ [4] = ClassNN ; =============================================================================== Func _Mouse_Control_GetInfo() Local $client_mpos = $pos1 ; gets client coords because of "MouseCoordMode" = 2 Local $a_mpos Local $point, $cHwnd, $pos, $size ;~ Call to removed due to offset issue $a_mpos = _ClientToScreen($appHandle, $client_mpos[0], $client_mpos[1]) ; $a_mpos now screen coords $a_mpos = $client_mpos ;~ $appHandle = GetHoveredHwnd($client_mpos[0], $client_mpos[1]) ; Uses the mouse to do the equivalent of WinGetHandle() Local $h_control = WindowFromPoint($a_mpos) $appHandle = _WinAPI_GetAncestor($h_control, $GA_ROOT) If @error Then Return SetError(2, 0, 0) Local $t_class = DllStructCreate("char[260]") DllCall("User32.dll", "int", "GetClassName", "hwnd", $h_control, "ptr", DllStructGetPtr($t_class), "int", 260) Local $a_ret[5] = [$h_control, DllStructGetData($t_class, 1), $a_mpos[0], $a_mpos[1], "none"] Local $sClassNN = _ControlGetClassnameNN($a_ret[0]) ; optional, will run faster without it $a_ret[4] = $sClassNN Return $a_ret EndFunc ;==>_Mouse_Control_GetInfo ; =============================================================================== ; Retrives the a handle to a control or window. ; Created by martin in an unknown thread ; Params ; $point - the mouse coords ; =============================================================================== Func WindowFromPoint($point) Local $cHwnd, $hwnd, $pos, $size $point = MouseGetPos() $hwnd = DllCall($dll, "hwnd", "WindowFromPoint", "int", $point[0], "int", $point[1]) If $hwnd[0] <> 0 Then $pos = WinGetPos($hwnd[0]) If @error Then Return 0 $size = WinGetClientSize($hwnd[0]) If @error Then Return 0 $pos[0] += (($pos[2] - $size[0]) / 2) $pos[1] += (($pos[3] - $size[1]) - (($pos[2] - $size[0]) / 2)) $cHwnd = DllCall($dll, "hwnd", "RealChildWindowFromPoint", "hwnd", $hwnd[0], _ "int", $point[0] - $pos[0], "int", $point[1] - $pos[1]) If $cHwnd[0] <> 0 Then $hwnd[0] = $cHwnd[0] EndIf Return $hwnd[0] EndFunc ;==>WindowFromPoint ; =============================================================================== ; Retrieves the Handle of GUI/Application the mouse is over. ; Similar to WinGetHandle except it used the current mouse position ; Taken from http://www.autoitscript.com/forum/index.php?showtopic=444962 ; Changed to take params to allow only one set of coords to be used. ; Params ;~ $i_xpos - x position of the mouse - usually from MouseGetPos(0) ;~ $i_ypos - x position of the mouse - usually from MouseGetPos(1) ; =============================================================================== Func GetHoveredHwnd($i_xpos, $i_ypos) Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", $i_xpos, "long", $i_ypos) If IsArray($iRet) Then $appHandle = $iRet[0] Return HWnd($iRet[0]) Else Return SetError(1, 0, 0) EndIf EndFunc ;==>GetHoveredHwnd ; =============================================================================== ;~ Gets the ClassNN of a control (Classname and Instance Count). This is checked with ControlGetHandle ;~ The instance is really a way to uniquely identify classes with the same name ;~ Big thanks to Valik for writing the function, taken from - http://www.autoitscript.com/forum/index.php?showtopic=97662 ;~ Param ;~ $hControl - the control handle from which you want the ClassNN ;~ Returns ;~ the ClassNN of the given control ; =============================================================================== Func _ControlGetClassnameNN($hControl) If Not IsHWnd($hControl) Then Return SetError(1, 0, "") Local Const $hParent = _WinAPI_GetAncestor($appHandle, $GA_ROOT) ; get the Window handle, this is set in GetHoveredHwnd() If Not $hParent Then Return SetError(2, 0, "") Local Const $sList = WinGetClassList($hParent) ; list of every class in the Window Local $aList = StringSplit(StringTrimRight($sList, 1), @LF, 2) _ArraySort($aList) ; improves speed Local $nInstance, $sLastClass, $sComposite For $i = 0 To UBound($aList) - 1 If $sLastClass <> $aList[$i] Then ; set up the first occurrence of a unique classname $sLastClass = $aList[$i] $nInstance = 1 EndIf $sComposite = $sLastClass & $nInstance ;build the ClassNN for testing with ControlGetHandle. ClassNN = Class & ClassCount ;if ControlGetHandle(ClassNN) matches the given control return else look at the next instance of the classname If ControlGetHandle($hParent, "", $sComposite) = $hControl Then Return $sComposite EndIf $nInstance += 1 ; count the number of times the class name appears in the list Next Return SetError(3, 0, "") EndFunc ;==>_ControlGetClassnameNN ; =============================================================================== ;~ Creates a read square around the control ; =============================================================================== Func GUICreateSquare($X, $Y, $W, $H) $X -= $Frame_Width $Y -= $Frame_Width $W += $Frame_Width $H += $Frame_Width $ahGUI[0] = GUICreate("", $W, $Frame_Width, $X, $Y, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW) GUISetBkColor($Frame_Color) $ahGUI[1] = GUICreate("", $Frame_Width, $H, $X, $Y, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW) GUISetBkColor($Frame_Color) $ahGUI[2] = GUICreate("", $Frame_Width, $H, $X + $W, $Y, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW) GUISetBkColor($Frame_Color) $ahGUI[3] = GUICreate("", $W + $Frame_Width, $Frame_Width, $X, $Y + $H, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW) GUISetBkColor($Frame_Color) For $i = 0 To 3 GUISetState(@SW_SHOW, $ahGUI[$i]) Next EndFunc ;==>GUICreateSquare ; =============================================================================== ;~ Removed the read square around the control created by GUICreateSquare ; =============================================================================== Func GUISquareDelete() For $i = 0 To 3 If IsHWnd($ahGUI[$i]) Then GUIDelete($ahGUI[$i]) Next $ahGUI = "" Dim $ahGUI[4] EndFunc ;==>GUISquareDelete ; =============================================================================== ;~ Determines if the control is highlighted ; =============================================================================== Func IsHighLight_GUIs($hCtrl) For $i = 0 To 3 If $ahGUI[$i] = $hCtrl Then Return True Next Return False EndFunc ;==>IsHighLight_GUIs Func MyExit() ; stops the script ConsoleWrite("Script Stoppted By User" & @CR) DllClose($dll) Exit EndFunc ;==>MyExit
    1 point
×
×
  • Create New...