name22

Capture Client Area from Window

Oct 31st, 2012
142
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <WinAPI.au3>
  2. #include <GDIPlus.au3>
  3. #include <Array.au3>
  4.  
  5. $hWnd = GUICreate("Test", 400, 400)
  6. $cButton1 = GUICtrlCreateButton("Test", 50, 50, 50, 25)
  7. $cEdit = GUICtrlCreateEdit("AutoIt rocks!!", 50, 70, 200, 200)
  8. GUISetState()
  9.  
  10. Sleep(500)
  11.  
  12. $hBMP = _ScreenCapture_CaptureWndEx($hWnd, -1, -1)
  13.  
  14. _GDIPlus_Startup()
  15. $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
  16. _GDIPlus_ImageSaveToFile($hBitmap, @DesktopDir & "\Test.png")
  17. _GDIPlus_BitmapDispose($hBitmap)
  18. _GDIPlus_Shutdown()
  19.  
  20. _WinAPI_DeleteObject($hBMP)
  21.  
  22. Do
  23. Until GUIGetMsg() = -3
  24.  
  25. Func _ScreenCapture_CaptureWndEx($hWnd, $iWidth = -1, $iHeight = -1)
  26.     If $iWidth = -1 Then $iWidth = _WinAPI_GetClientWidth($hWnd)
  27.     If $iHeight = -1 Then $iHeight = _WinAPI_GetClientHeight($hWnd)
  28.  
  29.     Local $hDDC = _WinAPI_GetDC($hWnd)
  30.     Local $hCDC = _WinAPI_CreateCompatibleDC($hDDC)
  31.     Local $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iWidth, $iHeight)
  32.     _WinAPI_SelectObject($hCDC, $hBMP)
  33.     _WinAPI_BitBlt($hCDC, 0, 0, $iWidth, $iHeight, $hDDC, 0, 0, 0x00CC0020)
  34.  
  35.     _WinAPI_ReleaseDC($hWnd, $hDDC)
  36.     _WinAPI_DeleteDC($hCDC)
  37.     Return $hBMP
  38. EndFunc
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×