Jump to content

second edition Of Child Windows Capture


wolf9228
 Share

Recommended Posts

The task of the code is to take pictures of all child Windows From the parents' window easily and simply ... The code saves you from the complexities of professional screen capture ... Thank you.

ChildWindowsCapture.zip

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPISys.au3>
#include <GDIPlus.au3>
#include <WinAPIShellEx.au3>
#include <WinAPIDlg.au3>

Global $Child = "" ,$ChildArray  , $PTR_Chi , $HCallBak

OnAutoItExitRegister("ExitFunc")


$hGUI = GUICreate("", 120, 52)
$Capture = GUICtrlCreateButton("Capture", 0, 0, 120, 25)
$Exit = GUICtrlCreateButton("Exit", 0, 27, 120, 25)
GUISetState(@SW_SHOW,$hGUI)

While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE,$Exit
ExitLoop
Case $Capture
GUISetState(@SW_HIDE,$hGUI)
Sleep(100)
While 1
;VK_LBUTTON = 0x01 // Left mouse button
if _WinAPI_GetAsyncKeyState(0x01) Then
ChildWindowsCapture()
ExitLoop
EndIf
WEnd
GUISetState(@SW_SHOW,$hGUI)
EndSwitch
WEnd
GUIDelete($hGUI)
Exit

Func ExitFunc()
DllCallbackFree($HCallBak)
EndFunc

Func ChildWindowsCapture()
$tPointSt = DllStructCreate("int;int")
$Pos = MouseGetPos()
DllStructSetData($tPointSt,1,$Pos[0])
DllStructSetData($tPointSt,2,$Pos[1])
$Pwin = _WinAPI_WindowFromPoint($tPointSt)
$Handle = _WinAPI_GetAncestor($Pwin,$GA_ROOT)
_GDIPlus_Startup ()
$hBitmap = BitmapCreate($Handle)
$WindowArray = GetChildWindows($Handle)
$UBound = UBound($WindowArray) - 1
For $i = 0 To $UBound
$WindowArray[$i] = BitmapCreateFromControlHWND($WindowArray[$i])
Next
$chGUI = GUICreate("SaveImages",(120 * 5) + (3 * 5),25)
$PMB = GUICtrlCreateButton("BMP",0,0,120,25)
$JPG = GUICtrlCreateButton("JPG",120 + 3,0,120,25)
$GIF = GUICtrlCreateButton("GIF",120 + 120 + 3 + 3,0,120,25)
$PNG = GUICtrlCreateButton("PNG",120 + 120 + 120 + 3 + 3 + 3,0,120,25)
$OUT = GUICtrlCreateButton("OUT",120 + 120 + 120 + 120 + 3 + 3 + 3 + 3,0,120,25)
GUISetState(@SW_SHOW,$chGUI)
Local $Type = "" , $sPath = ""
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE,$OUT
For $i = 0 To $UBound
_GDIPlus_BitmapDispose($WindowArray[$i])
Next
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_ShutDown ()
GUIDelete($chGUI)
Return
Case $PMB
$Type = ".bmp"
$sPath = _WinAPI_BrowseForFolderDlg("","Choose Folder",0x00000040);0x00000040,BIF_NEWDIALOGSTYLE
if $sPath == "" Then ContinueLoop
DirCreate($sPath & "\Images")
GUIDelete($chGUI)
ExitLoop
Case $JPG
$Type = ".jpg"
$sPath = _WinAPI_BrowseForFolderDlg("","Choose Folder",0x00000040);0x00000040,BIF_NEWDIALOGSTYLE
if $sPath == "" Then ContinueLoop
DirCreate($sPath & "\Images")
GUIDelete($chGUI)
ExitLoop
Case $GIF
$Type = ".gif"
$sPath = _WinAPI_BrowseForFolderDlg("","Choose Folder",0x00000040);0x00000040,BIF_NEWDIALOGSTYLE
if $sPath == "" Then ContinueLoop
DirCreate($sPath & "\Images")
GUIDelete($chGUI)
ExitLoop
Case $PNG
$Type = ".png"
$sPath = _WinAPI_BrowseForFolderDlg("","Choose Folder",0x00000040);0x00000040,BIF_NEWDIALOGSTYLE
if $sPath == "" Then ContinueLoop
DirCreate($sPath & "\Images")
GUIDelete($chGUI)
ExitLoop
EndSwitch
WEnd
For $i = 0 To $UBound
_GDIPlus_ImageSaveToFile($WindowArray[$i], $sPath & "\Images\" & $WindowArray[$i] & $Type)
_GDIPlus_BitmapDispose($WindowArray[$i])
Next
_GDIPlus_ImageSaveToFile($hBitmap, $sPath & "\Images\" & $hBitmap & $Type)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_ShutDown ()
EndFunc

Func  GetChildWindows($hWndParent)
If Not ($PTR_Chi) Then $PTR_Chi = RegisterEnumChildProc("CALLBACK_EnumChildProc")
EnumChildWindows($hWndParent , $PTR_Chi)
Return $ChildArray
EndFunc

Func  EnumChildWindows($hWndParent,$lpEnumFunc)
Local $lParam = 0
Global $Child = ""
Global $ChildArray = 0
Dim $ChildArray[1]
$BOOL = DllCall("user32.dll","int","EnumChildWindows","hwnd",$hWndParent,"ptr",$lpEnumFunc,"int",$lParam)
if Not @error Then Return SetError(@error,"",$BOOL[0])
Return SetError(@error,"",False)
EndFunc

Func RegisterEnumChildProc($lpEnumFunc)
$HCallBak = DLLCallbackRegister ($lpEnumFunc, "int", "hwnd;int")
Return DllCallbackGetPtr($HCallBak)
EndFunc


Func CALLBACK_EnumChildProc($hwnd,$lParam)
if Not StringInStr($Child,$hwnd) Then
$Child &= $hwnd & "|"
ReDim $ChildArray[UBound($ChildArray) + 1]
$ChildArray[UBound($ChildArray) - 1] = $hwnd
Return True
Else
Return False
EndIf
EndFunc

Func BitmapCreateFromControlHWND($HWND)
Local $Width = _WinAPI_GetWindowWidth($hWnd)
Local $Height =_WinAPI_GetWindowHeight($hWnd)
$DC = _WinAPI_GetDC($HWND)
$CompatibleDC = _WinAPI_CreateCompatibleDC($DC)
$hBitmap = _WinAPI_CreateCompatibleBitmap($DC,$Width, $Height)
_WinAPI_SelectObject($CompatibleDC, $hBitmap)
_WinAPI_BitBlt($CompatibleDC, 0, 0, $Width, $Height, $DC, 0, 0,$SRCCOPY)
_WinAPI_DeleteDC($CompatibleDC)
_WinAPI_ReleaseDC($HWND,$DC)
$yhBitmap = _GDIPlus_BitmapCreateFromHBITMAP ($hBitmap)
_WinAPI_DeleteObject ($hBitmap)
Return $yhBitmap
EndFunc

Func BitmapCreate($hWnd)
$Rect = _WinAPI_GetWindowRect($hWnd)
Local $IMGE_L = DllStructGetData($Rect,1)
Local $IMGE_T = DllStructGetData($Rect,2)
Local $IMGE_W = DllStructGetData($Rect,3) - $IMGE_L
Local $IMGE_H = DllStructGetData($Rect,4) - $IMGE_T
$Dwin = _WinAPI_GetDesktopWindow()
$DC = _WinAPI_GetDC($Dwin)
$CompatibleDC = _WinAPI_CreateCompatibleDC($DC)
$hBitmap = _WinAPI_CreateCompatibleBitmap($DC,$IMGE_W,$IMGE_H)
_WinAPI_SelectObject($CompatibleDC, $hBitmap)
_WinAPI_BitBlt($CompatibleDC,0,0,$IMGE_W,$IMGE_H,$DC,$IMGE_L,$IMGE_T,$SRCCOPY)
_WinAPI_DeleteDC($CompatibleDC)
_WinAPI_ReleaseDC($Dwin,$DC)
$yhBitmap = _GDIPlus_BitmapCreateFromHBITMAP ($hBitmap)
_WinAPI_DeleteObject ($hBitmap)
Return $yhBitmap
EndFunc

 

Edited by wolf9228

صرح السماء كان هنا

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...