想截取躲在后面的窗體或控件,找到了PrintWindow函數,幸運的是Autoit3也對此進行了封裝以方便使用。
於是乎,將幫助文件里的_WinAPI_PrintWindow()實例改寫了一下,以替代ScreenCapture系列函數:
#include <WinAPIGdi.au3>
#include <Clipboard.au3>
HotKeySet("q", "exam")
While 1
Sleep(100)
WEnd
Func exam()
Run(@SystemDir & '\calc.exe')
Local $hWnd = WinGetHandle("[CLASS:CalcFrame]")
If Not $hWnd Then
Exit
EndIf
PrintModule($hWnd)
EndFunc ;==>exam
Func PrintModule($hWnd)
Local $iSize=ControlGetPos("","",$hWnd)
; Create bitmap
Local $hDC = _WinAPI_GetDC($hWnd)
Local $hDestDC = _WinAPI_CreateCompatibleDC($hDC)
Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iSize[2], $iSize[3])
Local $hDestSv = _WinAPI_SelectObject($hDestDC, $hBitmap)
_WinAPI_PrintWindow($hWnd, $hDestDC)
_WinAPI_ReleaseDC($hWnd, $hDC)
_WinAPI_DeleteDC($hDestDC)
_ClipBoard_Open(0)
_ClipBoard_Empty()
_ClipBoard_SetDataEx($hBitmap, $CF_BITMAP)
_ClipBoard_Close()
_WinAPI_DeleteObject($hBitmap)
EndFunc ;==>PrintModule
示例中的$hWnd不限於窗口句柄,有點Autoit編程經驗的應該都了解。
如果想進一步截取某個窗體或控件的某一部分區域,加個GDIPlus函數將獲取到的Bitmap克隆一下就可以了。
Au3這種腳本語言學習起來主要還是靠耐心鑽研幫助文件,畢竟東西就那么多。
如有其它疑問或建議,歡迎在這方面志同道合的朋友加我微信(Z,E,,A,,,L,,S,K)交流 ^^
