Jump to content

Recommended Posts

Posted
#include <IE.au3>
#include <ScreenCapture.au3>

$sUrl = 'https://youtube.com'
;Local $oIE = _IECreate ($sUrl, 1);    works here
Local $oIE =  _IECreate ($sUrl, 1, 0);  not working here
_IELoadWait($oIE)
WinActivate(_IEPropertyGet($oIE, 'hwnd'))
$hWnd = _IEPropertyGet($oIE, 'hwnd')
_ScreenCapture_CaptureWnd('C:\1.jpg', $hWnd, 0, 0, 800, 800)

 

Posted

Uez, thank you. There is a lot of superfluous in the code.
Here is the best solution if someone is looking:
1. Make the window visible and hidden behind the program form.
2. I take a screenshot of an inactive window.

#include <GDIPlus.au3>
#include <WinAPIEx.au3>
#include <APIConstants.au3>

$iHandle = WinGetHandle('[CLASS:Notepad]')

_GDIPlus_Startup()
$hBitmap = Capture_Window($iHandle)
_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\Test.jpg")
_GDIPlus_BitmapDispose($hBitmap)
;ShellExecute(@ScriptDir & "\Test.jpg")
_GDIPlus_Shutdown()

Func Capture_Window($hWnd)
    Local $hDC_Capture = _WinAPI_GetWindowDC($hWnd)
    Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture)
    Local $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, _WinAPI_GetWindowWidth($hWnd), _WinAPI_GetWindowHeight($hWnd))
    Local $hObjectOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
    DllCall("user32.dll", "int", "PrintWindow", "hwnd", $hWnd, "handle", $hMemDC, "int", 0)
    Local $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
    _WinAPI_SelectObject($hMemDC, $hObjectOld)
    _WinAPI_DeleteObject($hHBitmap)
    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_ReleaseDC($hWnd, $hDC_Capture)
    Return $hBmp
EndFunc

 

Posted

Even in yours, you got superfluous code :

#include <WinAPIGdi.au3>
#include <ScreenCapture.au3>

Local $hWnd = WinGetHandle("[CLASS:Notepad]")
Capture_Window($hWnd, 650, 500)
ShellExecute("test.jpg")

Func Capture_Window($hWnd, $w, $h)
  Local $hDC_Capture = _WinAPI_GetDC($hWnd)
  Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture)
  Local $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $w, $h)
  Local $hObject = _WinAPI_SelectObject($hMemDC, $hHBitmap)
  _WinAPI_PrintWindow($hWnd, $hMemDC)
  _ScreenCapture_SaveImage("test.jpg", $hHBitmap)
  _WinAPI_DeleteDC($hMemDC)
  _WinAPI_ReleaseDC($hWnd, $hDC_Capture)
  _WinAPI_DeleteObject($hHBitmap)
EndFunc   ;==>Capture_Window

:)

Posted

The solution UEZ posted takes a screenshot invisibly and not only in the background, but of course is limited to webpages, which seems to be the intention of the OP.

Here's my latest update on the code provided originally by ward:

 

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...