Jump to content
Sign in to follow this  

_ScreenCapture Hidden window

Recommended Posts


is it possible to take a screenshot from a hidden / minimized window??

Share this post

Link to post
Share on other sites

No, because there exists no "window" which is only something visual what you can see only at your Monitor!

A "Window" is a collection of Controls, Forms, Lists, and many things more which looks only like a Picture at your Monitor. If the window is minimized or invisible, the graphical part doesnt exists. So it is not possible to work with that "not existing" thing. But you can send Messages to all these Controls, Forms and Lists, whether they are displayed on the screen or not. 



Share this post

Link to post
Share on other sites

The current screen capture window function in the standard install set finds the window coordinates and passes those as arguments to the proper screen capture function. As a result it will give you the right sized rectangle, only filled with whatever happens to be there at that time.

I have not tried, but I will see what happens if you take a screenshot of a region outside of the monitor, if you could I would be amazed, but it would be a sort of workaround.


Share this post

Link to post
Share on other sites

is it possible to get a single pixel color from a mini/hidden window??

Share this post

Link to post
Share on other sites

No luck I'm afraid:


$hGUI = GUICreate ("this is a test", 200, 200, @DesktopWidth + 100, @DesktopHeight + 100)
GUISetState ()

$ret = _ScreenCapture_CaptureWnd (@ScriptDir & "\Test.png", $hGUI)

GUICtrlCreateLabel ("return: " & $ret & @TAB & "Error: " & @ERROR, 2, 2, 200, 20)
GUICtrlCreatePic (@ScriptDir & "\Test.png", 2, 24, 496, 474)
WinMove ($hGUI, "", 200, 200, 500, 500)

While GUIGetMsg () <> -3
   Sleep (10)

Haven't tried any further than that. It just generates a black square.


Edited by Mat

Share this post

Link to post
Share on other sites

You can still make the window completely transparent, the frame is a little tricky I guess but you're mostly interested in the window content:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("MustDeclareVars", 1)

Global Const $PRF_CHECKVISIBLE  = 1
Global Const $PRF_NONCLIENT     = 2
Global Const $PRF_CLIENT        = 4
Global Const $PRF_ERASEBKGND    = 8
Global Const $PRF_CHILDREN      = 16
Global Const $PRF_OWNED         = 32


Local $hGUI = GUICreate("Title", 200, 200, -1, -1, -1, $WS_EX_TOOLWINDOW)

Local $Label = GUICtrlCreateLabel("Orange Label", 50, 50, 100, 100)
GUICtrlSetColor(-1, 0xFCAA24)
GUICtrlSetFont(-1, 15, 550)

WinSetTrans($hGUI, 0, 0)

Local $hDC_GUI = _WinAPI_GetDC($hGUI)
ConsoleWrite(_RGB(_GetPixel($hDC_GUI, 10, 10)) & @CRLF)
ConsoleWrite(_RGB(_GetPixel($hDC_GUI, 63, 64)) & @CRLF)
_WinAPI_ReleaseDC($hGUI, $hDC_GUI)

Local $aPos = WinGetPos($hGUI)
Local $iWidth  = $aPos[2]
Local $iHeight = $aPos[3]

$hDC_GUI = _WinAPI_GetWindowDC($hGUI)
Local $hDC_Desk = _WinAPI_GetDC(0)
Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC_GUI, $iWidth, $iHeight)

Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage)
Local $hDC = _GDIPlus_GraphicsGetDC($hGraphics)


_GDIPlus_GraphicsReleaseDC($hGraphics, $hDC)
_WinAPI_BitBlt($hDC_Desk, 0, 0, $iWidth, $iHeight, $hDC_GUI, 0, 0, 0xCC0020)

_WinAPI_ReleaseDC(0, $hDC_Desk)
_WinAPI_ReleaseDC($hGUI, $hDC_GUI)

WinSetTrans($hGUI, 0, 255)



Func _GetPixel($hDC, $iX, $iY)
    Local $aResult = DllCall("gdi32.dll", "int", "GetPixel", "hwnd", $hDC, "int", $iX, "int", $iY)
    If @error Or $aResult[0] = -1 Then Return SetError(1, 0, -1)
    Return $aResult[0]

Func _RGB($iGBR)
    Return "0x" & Hex(BitShift("0x" & Hex(Binary($iGBR)), 8), 6)

Manadar ran a topic about efficiently getting pixel from memory with included speed testings. It's not the same approach but priceless nonetheless.

Share this post

Link to post
Share on other sites

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
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.