获取指定窗体客户区域设备场景的句柄
#Include <WinAPIEx.au3>
_WinAPI_GetDCEx ( $hWnd, $hRgn, $iFlags )
$hWnd | 要获取场景的窗体的句柄. 如果为0, 函数以全屏幕作为DC. 如果$iFlags参数为$DCX_INTERSECTRGN或$DCX_EXCLUDERGN, 系统假设一个区域的宿主并在不再需要时自动删除. 在此情况下, 应用程序在成功调用_WinAPI_GetDCEx()后不使用或删除区域 |
$hRgn | 可与DC可见区域结合的剪切区域 |
$iFlags | 指定如何创建DC. 可为一个或多哥下列值: $DCX_WINDOW - 返回对应于窗口矩形的DC而不是客户端的矩形 $DCX_CACHE - 从缓存中返回DC $DCX_PARENTCLIP - 使用父窗口的可见区域 $DCX_CLIPSIBLINGS - 不包括由$hWnd确定的窗口的同级窗口的可见区域 $DCX_CLIPCHILDREN - 不包括由$hWnd确定的窗口的子窗口的可见区域 $DCX_NORESETATTRS - 释放DC时不将DC重置为默认设置 $DCX_LOCKWINDOWUPDATE - 即使调用LockWindowUpdate已生效仍然允许绘图. 用于跟踪绘制. $DCX_EXCLUDERGN - 由$hRgn指定的裁剪区域排除在返回DC的可见区域外 $DCX_INTERSECTRGN - 由$hRgn指定的裁剪区域与返回DC的可见区域相交 $DCX_INTERSECTUPDATE - 保留不使用 $DCX_VALIDATE - 保留不使用 |
成功: | 返回指定窗体设备场景的句柄 |
失败: | 返回 0设置@error 标记非0 |
在MSDN中搜索
#Include <APIConstants.au3>
#include <GUIConstantsEx.au3>
#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
Global $hFont = _WinAPI_CreateFont(16, 0, 0, 0, $FW_BOLD, 0, 0, 0, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_PITCH, $ANTIALIASED_QUALITY, 'Arial')
Global $hForm, $hDll, $pDll, $hProc, $Dwm = False
If (_WinAPI_GetVersion() > '5.2') And (_WinAPI_DwmIsCompositionEnabled()) Then
If MsgBox(35, 'DWM', 'This example works only if a Desktop Window Manager (DWM) composition is disabled.' & @CR & @CR & 'Do you want to disable DWM?') = 6 Then
_WinAPI_DwmEnableComposition(0)
$Dwm = True
Else
Exit
EndIf
EndIf
OnAutoItExitRegister('OnAutoItExit')
; 创建 GUI
$hForm = GUICreate('', 400, 400)
; 注册窗口过程
$hDll = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;long;ptr')
$pDll = DllCallbackGetPtr($hDll)
$hProc = _WinAPI_SetWindowLongEx($hForm, $GWL_WNDPROC, $pDll)
GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func _WinProc($hWnd, $iMsg, $wParam, $lParam)
Local $Res = _WinAPI_CallWindowProc($hProc, $hWnd, $iMsg, $wParam, $lParam)
Switch $iMsg
Case $WM_NCACTIVATE, $WM_NCPAINT
Local $hDC, $hSv
Switch $iMsg
Case $WM_NCACTIVATE
$hDC = _WinAPI_GetWindowDC($hWnd)
Case $WM_NCPAINT
$hDC = _WinAPI_GetDCEx($hWnd, $wParam, BitOR($DCX_WINDOW, $DCX_INTERSECTRGN))
EndSwitch
$hSv = _WinAPI_SelectObject($hDC, $hFont)
_WinAPI_SetTextColor($hDC, 0x00FFFF)
_WinAPI_SetBkMode($hDC, $TRANSPARENT)
_WinAPI_TextOut($hDC, 25, 8, 'MyGUI')
_WinAPI_SelectObject($hDC, $hSv)
_WinAPI_ReleaseDC($hWnd, $hDC)
EndSwitch
Return $Res
EndFunc ;==>_WinProc
Func OnAutoItExit()
_WinAPI_SetWindowLongEx($hForm, $GWL_WNDPROC, $hProc)
DllCallbackFree($hDll)
If $Dwm Then
_WinAPI_DwmEnableComposition(1)
EndIf
EndFunc ;==>OnAutoItExit