# Function Reference

# _WinAPI_PrintWindow

Copies a visual window into the specified device context

#include <WinAPIGdiDC.au3>
_WinAPI_PrintWindow ( $hWnd, $hDC [, $iClient = 0] )

## Parameters

$hWnd | Handle to the window that will be copied.
$hDC | Handle to the device context.
$iClient | [optional] Specifies whether copies only the client area of the window, valid values: $PW_DEFAULT (0) - The entire window is copied (Default). $PW_CLIENTONLY (1) - Only the client area of the window is copied to device context. $PW_RENDERFULLCONTENT (2) - for capturing the contents of the window that are drawn using DirectComposition.

## Return Value

Success: | True
Failure: | False

## See Also

Search PrintWindow in MSDN Library.

## Example

    #include <GUIConstantsEx.au3>
    #include <SendMessage.au3>
    #include <StaticConstants.au3>
    #include <WinAPIGdi.au3>
    #include <WinAPIGdiDC.au3>
    #include <WinAPIHObj.au3>

    _Example()

    Func _Example()
        ShellExecute(@SystemDir & '\calc.exe')
        Local $hWnd = WinWaitActive("[REGEXPCLASS:CalcFrame|ApplicationFrameWindow]", "")
        If Not $hWnd Then
            Exit
        EndIf
        Sleep(1500) ; give it time to draw - let the window draw completely - skip the window animation

        ; Create GUI
        Local $aPos = WinGetPos($hWnd)
        GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), $aPos[2] + 80, $aPos[3] + 80)
        Local $idPic = GUICtrlCreatePic('', 40, 40, $aPos[2], $aPos[3])
        Local $hPic = GUICtrlGetHandle($idPic)

        ; Create bitmap
        Local $hDC = _WinAPI_GetDC($hPic)
        Local $hDestDC = _WinAPI_CreateCompatibleDC($hDC)
        Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $aPos[2], $aPos[3])
        Local $hDestSv = _WinAPI_SelectObject($hDestDC, $hBitmap)
        Local $hSrcDC = _WinAPI_CreateCompatibleDC($hDC)
        Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $aPos[2], $aPos[3])
        Local $hSrcSv = _WinAPI_SelectObject($hSrcDC, $hBmp)
        _WinAPI_PrintWindow($hWnd, $hSrcDC, $PW_RENDERFULLCONTENT)
        _WinAPI_BitBlt($hDestDC, 0, 0, $aPos[2], $aPos[3], $hSrcDC, 0, 0, $MERGECOPY)

        _WinAPI_ReleaseDC($hPic, $hDC)
        _WinAPI_SelectObject($hDestDC, $hDestSv)
        _WinAPI_SelectObject($hSrcDC, $hSrcSv)
        _WinAPI_DeleteDC($hDestDC)
        _WinAPI_DeleteDC($hSrcDC)
        _WinAPI_DeleteObject($hBmp)

        ; Set bitmap to control
        _SendMessage($hPic, $STM_SETIMAGE, 0, $hBitmap)
        Local $hObj = _SendMessage($hPic, $STM_GETIMAGE)
        If $hObj <> $hBitmap Then
            _WinAPI_DeleteObject($hBitmap)
        EndIf

        GUISetState(@SW_SHOW)

        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

        WinClose($hWnd, "")
    EndFunc   ;==>_Example