Hi all, I created a script to take periodic screen shots of an inactive background window by using the PrintWindow command (via some code I found elsewhere on the forum). I run this script on my Windows 7 PC at home, but I am usually connected to it through Remote Desktop while at work or even while at home through my laptop. The script works well when I am connected, but the moment I disconnect (e.g. when I am headed home from the office) PrintWindow begins capturing an entirely black bitmap. I know the background app continues processing while in a disconnected state (just as the script does), so maybe it has something to do with the way the desktop window manager works? I've tried having the script reinitialize the DC/bitmap in the while loop upon detection of the black bitmap, but it didn't have any effect so I took it back out. I've enclosed the relevant snippets of code below. Normally if I didn't connect via remote desktop at all, the session would be just be a normal local PC session (console session) and would run without issue. Perhaps if there were a way my script could convert the disconnected session into a console session that would do the trick too, but I have no idea where to begin with that. Any help would be greatly appreciated. Thanks! #include <GDIPlus.au3>
#include <WinAPI.au3>
#include <ScreenCapture.au3>
$loopcounter = 0
$hWnd = WinGetHandle("TestWindow")
;Initialize the DC/bitmap
_GDIPlus_Startup()
$iWidth = _WinAPI_GetWindowWidth($hWnd)
$iHeight = _WinAPI_GetWindowHeight($hWnd)
$hDDC = _WinAPI_GetDC($hWnd)
$hCDC = _WinAPI_CreateCompatibleDC($hDDC)
$hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iWidth, $iHeight)
_WinAPI_SelectObject($hCDC, $hBMP)
While 1
$loopcounter+=1
DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "hwnd", $hCDC, "int", 0)
_ScreenCapture_SaveImage("c:\testimage" & $loopcounter & ".jpg", $hBMP)
Sleep(10000)
WEnd
_WinAPI_ReleaseDC($hWnd, $hDDC)
_WinAPI_DeleteDC($hCDC)
_WinAPI_DeleteObject($hBMP)
_GDIPlus_ShutDown ()