UDF > WinAPIEx > System > Windows >


_WinAPI_SetWindowDisplayAffinity

Enregistre le paramètre d'affinité d'affichage en mode noyau sur la fenêtre spécifiée

#include <WinAPISysWin.au3>
_WinAPI_SetWindowDisplayAffinity ( $hWnd, $iAffinity )

Paramètres

$hWnd Handle de la fenêtre.
$iAffinity Le paramètre d'affinité d'affichage. Ce paramètre indique où les contenus de la fenêtre peuvent afficher.
Définissez cette valeur à $WDA_MONITOR pour afficher les contenus de la fenêtre seulement sur un moniteur.
Définissez cette valeur à $WDA_NONE pour enlever l'affinité moniteur-seul.

Valeur de retour

Succès: Retourne True.
Échec: Retourne False.

Remarques

_WinAPI_SetWindowDisplayAffinity() est conçu pour soutenir la protection du contenu de la fenêtre. Cette fonction permet aux applications de protéger le contenu de leur propre fenêtre à l'écran contre une capture ou une copie à l'aide d'un ensemble de fonctionnalités et API d'un système d'exploitation public. Cependant, elle ne fonctionne que lorsque le Desktop Window Manager (DWM) est en train de composer le bureau.

Cette fonction nécessite Windows 7 ou une version ultérieure.

Voir aussi

Consultez SetWindowDisplayAffinity dans la librairie MSDN.

Exemple

#include <APIGdiConstants.au3>
#include <APISysConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <ScreenCapture.au3>
#include <SendMessage.au3>
#include <StaticConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPIGdiDC.au3>
#include <WinAPIHObj.au3>
#include <WinAPISys.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>

If (Number(_WinAPI_GetVersion()) < 6.1) Or (Not _WinAPI_DwmIsCompositionEnabled()) Then
    MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Erreur', 'Requiert Windows 7 ou une version ultérieure avec  les thèmes Aero installés.')
    Exit
EndIf

Global $g_iWidth = @DesktopWidth / 2, $g_iHeight = @DesktopHeight / 2

Local $hForm = GUICreate('Test '& StringReplace(@ScriptName, '.au3', '()'), $g_iWidth + 116, $g_iHeight + 51)
GUICtrlCreatePic('', 14, 14, $g_iWidth + 2, $g_iHeight + 2, -1, $WS_EX_STATICEDGE)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $g_hPic = GUICtrlGetHandle(-1)
Local  $idCheck = GUICtrlCreateCheckbox('Protect against capture of window', 14, $g_iHeight + 23, 182, 21)
Local  $idButton = GUICtrlCreateButton('Capture', $g_iWidth + 29, 13, 74, 25)
GUICtrlSetState(-1, BitOR($GUI_DEFBUTTON, $GUI_FOCUS))
GUISetState(@SW_SHOW)

Local $iMsg = GUIGetMsg()
While $iMsg <> $GUI_EVENT_CLOSE
    Switch $iMsg
        Case $idButton
            _Capture()
        Case $idCheck
            If GUICtrlRead($idCheck) = $GUI_CHECKED Then
                _WinAPI_SetWindowDisplayAffinity($hForm, $WDA_MONITOR)
            Else
                _WinAPI_SetWindowDisplayAffinity($hForm, 0)
            EndIf
    EndSwitch
    $iMsg = GUIGetMsg()
WEnd

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