Jump to content

_ScreenCapture Hidden window


marselo
 Share

Recommended Posts

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. 

ciao

Andy

Link to comment
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.

Mat

Link to comment
Share on other sites

No luck I'm afraid:

#Include<ScreenCapture.au3>

$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)
Wend

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

Mat

Edited by Mat
Link to comment
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


_GDIPlus_Startup()

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

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

WinSetTrans($hGUI, 0, 0)
GUISetState()

Sleep(1000)
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)

_SendMessage($hGUI, $WM_PAINT, $hDC, BitOR($PRF_CLIENT, $PRF_NONCLIENT))

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

_WinAPI_ReleaseDC(0, $hDC_Desk)
_WinAPI_ReleaseDC($hGUI, $hDC_GUI)
_GDIPlus_ImageDispose($hImage)
_WinAPI_DeleteObject($hBitmap)

Sleep(1000)
WinSetTrans($hGUI, 0, 255)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

GUIDelete()
_GDIPlus_Shutdown()
Exit


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]
EndFunc

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

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...