函数参考


_WinAPI_SetWindowDisplayAffinity

以内核模式存储指定窗口的亲和力设置

#Include <WinAPIEx.au3>
_WinAPI_SetWindowDisplayAffinity ( $hWnd, $iAffinity )

参数

$hWnd 窗口句柄
$iAffinity 显示亲和力设置. 该设置指定窗口内容显示的位置. 可为下列值:

$WDA_MONITOR

返回值

成功: 返回 1
失败: 返回 0并设置@error非0

注意/说明

设计_WinAPI_SetWindowDisplayAffinity()用以支持windows的内容保护特性. 该函数是应用程序可保护自己在屏幕上的窗口内容通过一系列指定的公共操作系统特性和API来捕捉或复制. 然而, 仅当桌面窗口管理器(DWM)组成桌面时工作.

最低系统支持: Windows 7

相关

详情参考

在MSDN中搜索


示例/演示


#Include <APIConstants.au3>
#include <GUIConstantsEx.au3>
#Include <ScreenCapture.au3>
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global Const $STM_SETIMAGE = 0x0172
Global Const $STM_GETIMAGE = 0x0173

If (_WinAPI_GetVersion() < '6.1') Or (Not _WinAPI_DwmIsCompositionEnabled()) Then
    MsgBox(16, 'Error', 'Require Windows 7 or later with enabled Aero theme.')
    Exit
EndIf

Global $Widht = @DesktopWidth / 2, $Height = @DesktopHeight / 2
Global $hForm, $hPic, $Msg, $Button, $Check

$hForm = GUICreate('MyGUI', $Widht + 116, $Height + 51)
GUICtrlCreatePic('', 14, 14, $Widht + 2, $Height + 2, -1, $WS_EX_STATICEDGE)
GUICtrlSetState(-1, $GUI_DISABLE)
$hPic = GUICtrlGetHandle(-1)
$Check = GUICtrlCreateCheckbox('Protect against capture of window', 14, $Height + 23, 182, 21)
$Button = GUICtrlCreateButton('Capture', $Widht + 29, 13, 74, 25)
GUICtrlSetState(-1, BitOR($GUI_DEFBUTTON, $GUI_FOCUS))
GUISetState()

While 1
    $Msg = GUiGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button
            _Capture()
        Case $Check
            If GUICtrlRead($Check) = $GUI_CHECKED Then
                _WinAPI_SetWindowDisplayAffinity($hForm, $WDA_MONITOR)
            Else
                _WinAPI_SetWindowDisplayAffinity($hForm, 0)
            EndIf
    EndSwitch
WEnd

Func _Capture()

    Local $hDC, $hSrcDC, $hSrcSv, $hDestDC, $hDestSv, $hObj, $hBitmap

    $hObj = _SendMessage($hPic, $STM_SETIMAGE, 0, 0)
    If $hObj Then
        _WinAPI_DeleteObject($hObj)
    EndIf
    $hDC = _WinAPI_GetDC($hPic)
    $hDestDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $Widht, $Height)
    $hDestSv = _WinAPI_SelectObject($hDestDC, $hBitmap)
    $hSrcDC = _WinAPI_CreateCompatibleDC($hDC)
    $hObj = _ScreenCapture_Capture('', 0, 0, -1, -1, 0)
    $hSrcSv = _WinAPI_SelectObject($hSrcDC, $hObj)
    _WinAPI_SetStretchBltMode($hDestDC, $HALFTONE)
    _WinAPI_StretchBlt($hDestDC, 0, 0, $Widht, $Height, $hSrcDC, 0, 0, @DesktopWidth, @DesktopHeight, $SRCCOPY)
    _WinAPI_ReleaseDC($hPic, $hDC)
    _WinAPI_SelectObject($hDestDC, $hDestSv)
    _WinAPI_DeleteDC($hDestDC)
    _WinAPI_SelectObject($hSrcDC, $hSrcSv)
    _WinAPI_DeleteObject($hObj)
    _WinAPI_DeleteDC($hSrcDC)
    _SendMessage($hPic, $STM_SETIMAGE, 0, $hBitmap)
    $hObj = _SendMessage($hPic, $STM_GETIMAGE)
    If $hObj <> $hBitmap Then
        _WinAPI_DeleteObject($hBitmap)
    EndIf
EndFunc   ;==>_Capture