Thanks for your code - it really helped me understanding a lot of things about GDI...
Still I got some problems with it -
what I'm trying to do:
I want to make screenshots of a certain window every ** minutes and save these images as *.png.
This kind of works, except:
- The code I'm using doesn't make a shot of the actual window, but of the desktop at the window coordinates. So if this window isn't the top/active one, the images I get are from the windows overlapping the one I want.
- Sometimes the screen area seems to be messed up - although I'm giving the right coordinates (nL, nT, nW, nH), they sometimes(!) don't seem to fit...
I think my problem either lies in the definition of hDC or mDC, not sure so...
I also tried to create the hBM not as CompatibleBitmap but as CreateDIBSection, but the result is absolutely the same, CreateCompatibleBitmap just seems to be the easieer way. Instead of your "PrintWindow" I'm using "BitBlt" as shown in this thread (<!-- m -->http://www.autohotke...topic18146.html
<!-- m -->) to copy the color values - this could of course be the reason for mixing up coordinates, but I looked all commands up in the MS GDI help, and it seems to be used the right way...
I know the window doesn't have to be minimized, but I thought just being in the back should work (another funny bug is, when part of the window is off the screen - then the image is all black).
Sorry for bothering, just can't figure it out on my own...
Thanks for your help!
WinGet, id, ID
hDC := DllCall("GetDC", UInt, id)
WinGetPos, nL, nT, nW, nH, ahk_id %id%
WinGetTitle, this_title, ahk_id %id%
mDC := DllCall("gdi32.dll\CreateCompatibleDC", "Uint", hDC)
hBM := DllCall( "gdi32.dll\CreateCompatibleBitmap" , "uint", hDC, "int", nW, "int", nH )
DllCall("gdi32.dll\SelectObject", "Uint", mDC, "Uint", hBM)
DllCall("BitBlt", "Uint", mDC, "int", 0, "int", 0, "int", nW, "int", nH, "Uint", hDC, "int", nL, "int", nT, "Uint", 0x40000000 | 0x00CC0020)
sFile = %this_title%_%time%.png
Convert(hBM, sFile) ;Function for saving image as png
DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)
DllCall("DeleteDC", "Uint", mDC)
DllCall("DeleteObject", "Uint", hBM)