Jump to content

screenshot to a incative window


Recommended Posts

For minimized windows you cannot take a screen afaik but from inactive even windows which are behind others.

;coded by UEZ 2012
#include <Array.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>


$aWinlist = GetAllWindow()

For $i = 0 To UBound($aWinlist) - 1
    $hWnd = $aWinlist[$i][1]
    If Not WinActive($hWnd) Then ExitLoop
Next
If $i = UBound($aWinlist) Then Exit MsgBox(0, "Info", "No inactive window found", 10)

_GDIPlus_Startup()
$hBitmap = Capture_Window($hWnd, 300, 200)
_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "Test.jpg")
_GDIPlus_BitmapDispose($hBitmap)
ShellExecute(@ScriptDir & "Test.jpg")
_GDIPlus_Shutdown()
Exit

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

Func GetAllWindow() ;code by Authenticity - modified by UEZ
    Local $aWin = WinList(), $aWindows[1][4]
    Local $iStyle, $iEx_Style, $iCounter = 0
    Local $i, $hWnd_state, $aWinPos

    For $i = 1 To $aWin[0][0]
        $iEx_Style = BitAND(_WinAPI_GetWindowLong($aWin[$i][1], $GWL_EXSTYLE), $WS_EX_TOOLWINDOW)
        $iStyle = BitAND(WinGetState($aWin[$i][1]), 2)
        If $iEx_Style <> -1 And Not $iEx_Style And $iStyle Then
            $aWinPos = WinGetPos($aWin[$i][1])
            If $aWinPos[2] > 1 And $aWinPos[3] > 1 Then
                $aWindows[$iCounter][0] = $aWin[$i][0]
                $aWindows[$iCounter][1] = $aWin[$i][1]
                $aWindows[$iCounter][2] = $aWinPos[2]
                $aWindows[$iCounter][3] = $aWinPos[3]
                $iCounter += 1
            EndIf
            ReDim $aWindows[$iCounter + 1][4]
        EndIf
    Next
    ReDim $aWindows[$iCounter][4]
    Return $aWindows
EndFunc   ;==>GetAllWindow

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

oh thanks... is good ;)

one more question, is posible to set another function when is pressed minimize button

eg:

Press Minimize button from a window (no matter what)

Window is hided (@SW_HIDE)

Thanks again !

Link to comment
Share on other sites

Something like this?

$hMain = GUICreate('Example')
GUISetState(@SW_SHOW,$hMain)

While True
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case -3            ; Close (X Button)
            Exit
        Case -4            ; Minimize (_ Button)
            GUISetState(@SW_HIDE,$hMain)
    EndSwitch
    Sleep(10)
WEnd
Link to comment
Share on other sites

Something like this?

$hMain = GUICreate('Example')
GUISetState(@SW_SHOW,$hMain)

While True
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case -3         ; Close (X Button)
            Exit
        Case -4         ; Minimize (_ Button)
            GUISetState(@SW_HIDE,$hMain)
    EndSwitch
    Sleep(10)
WEnd

No.. i mean a window (eg : a Explorer Window (C:Program Files) or Browser Window) not a autoit window

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