Jump to content

Program ScreenCaptureEx


wolf9228
 Share

Recommended Posts

Thank you, just test it in my Windows 8 and work great. I use your old screen capture script in my XP SP3 almost every day and always save it as png.

Question, if it's possible, can you add a settings in order to capture as png, but using 256 color and B/W instead of 24 bit color.

Excuse my language.

Link to comment
Share on other sites

Still buggy.

Br, UEZ

Try this script if something goes wrong there is a problem to your PC

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GDIPlus.au3>

Global $vChildWindwos = 0,$CaptureTest = 0,$CapHHook = 0,$MouseGui = 0,$RgnGui = 0
Global $TrayWnd = WinGetHandle("[CLASS:Shell_TrayWnd]"),$MouseHHook = 0
Global $ButtonWnd = WinGetHandle("[CLASS:Button]") , $CaptureMouseTest = 0
Global $START_X , $START_Y , $IMGE_L = 0 , $IMGE_T = 0,$IMGE_W = 0 , $IMGE_H = 0
Global $InitDir1 = @MyDocumentsDir , $InitDir2 = $InitDir1 , $InitDir3 = $InitDir1
Global $InitDir4 = $InitDir1 , $InitDir5 = $InitDir1 , $InitDir6 = $InitDir1
Global $InitDir7 = $InitDir1, $InitDir8 = $InitDir1,$Num1,$Num2,$Num3,$Num4,$Num5

$ScreenGui = GUICreate("ScreenCaptureEx",230,245,(@DesktopWidth / 2) - 115, (@DesktopHeight / 2) - 123)
GUISetBkColor(15790320)
GUICtrlCreateGroup("ScreenCapture", 10, 10, 210,225)
$Button_1 = GUICtrlCreateButton("Select area by mouse", 15, 35, 200 , 30)
$Button_2 = GUICtrlCreateButton("Select Automatic", 15, 70, 200 , 30)
$Button_3 = GUICtrlCreateButton("Capture all child windows", 15, 105, 200 , 30)
$Button_4 = GUICtrlCreateButton("Exit", 15, 140, 200 , 30)
$Checkbox1 = GUICtrlCreateCheckbox("Hide taskbar", 50, 175, 130, 30)
$Checkbox2 = GUICtrlCreateCheckbox("Capture by any key", 33, 200, 167, 30)
GUISetState()

While 1
$msg = GUIGetMsg()
Select
Case $msg = $Button_1
$ShowTaskBar = Not(BitAND(GUICtrlRead($Checkbox1),$GUI_CHECKED) == $GUI_CHECKED)
$MousehBitmap = Mouse_Capture($ScreenGui,$ShowTaskBar)
if Not @error Then SaveImage($MousehBitmap)
GUISetState(@SW_SHOW,$ScreenGui)
GUISwitch($ScreenGui)
Case $msg = $Button_2
Dim $AutohBitmap = 0
$ShowTaskBar = Not(BitAND(GUICtrlRead($Checkbox1),$GUI_CHECKED) == $GUI_CHECKED)
If BitAND(GUICtrlRead($Checkbox2),$GUI_CHECKED) = $GUI_CHECKED Then
$AutohBitmap = AutoCapture($ScreenGui,1,$ShowTaskBar)
Else
$AutohBitmap = AutoCapture($ScreenGui,0,$ShowTaskBar)
EndIf
if Not @error Then SaveImage($AutohBitmap)
GUISetState(@SW_SHOW,$ScreenGui)
GUISwitch($ScreenGui)
Case $msg = $Button_3
$ShowTaskBar = Not(BitAND(GUICtrlRead($Checkbox1),$GUI_CHECKED) == $GUI_CHECKED)
If BitAND(GUICtrlRead($Checkbox2),$GUI_CHECKED) = $GUI_CHECKED Then
$ImageArray = ChildsCapture($ScreenGui,1,$ShowTaskBar)
Else
$ImageArray = ChildsCapture($ScreenGui,0,$ShowTaskBar)
EndIf
if Not @error Then ChildsSaveImage($ImageArray)
GUISetState(@SW_SHOW,$ScreenGui)
GUISwitch($ScreenGui)
Case $msg = $GUI_EVENT_CLOSE Or $msg = $Button_4
Exit
EndSelect
WEnd

Func ChildsSaveImage($ImageArray)
Local $Save_Error = 1 , $ImageExit  = ""
$SGui = GUICreate("Save",310,100,(@DesktopWidth - 155) / 2, (@DesktopHeight - 50) / 2)
GUISetBkColor(15790320)
GUICtrlCreateGroup("Save Image", 10, 10, 280, 80)
$SButton_1 = GUICtrlCreateButton("BMP", 15, 33, 50 , 50)
$SButton_2 = GUICtrlCreateButton("PNG", 70, 33, 50 , 50)
$SButton_3 = GUICtrlCreateButton("GIF", 125, 33, 50 , 50)
$SButton_4 = GUICtrlCreateButton("JPG", 180, 33, 50 , 50)
$SButton_5 = GUICtrlCreateButton("Skip", 235, 33, 50 , 50)
GUISetState(@SW_SHOW,$SGui)
GUISwitch($SGui)
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $SButton_1
$var = FileSelectFolder("Choose a folder.","",1 + 2 + 4,$InitDir5)
$Save_Error = @error
If Not($Save_Error) Then
$InitDir5 = $var
$ImageExit = ".BMP"
ExitLoop
EndIf
Case $msg = $SButton_2
$var = FileSelectFolder("Choose a folder.","",1 + 2 + 4,$InitDir6)
$Save_Error = @error
If Not ($Save_Error) Then
$InitDir6 = $var
$ImageExit = ".PNG"
ExitLoop
EndIf
Case $msg = $SButton_3
$var = FileSelectFolder("Choose a folder.","",1 + 2 + 4,$InitDir7)
$Save_Error = @error
If Not ($Save_Error) Then
$InitDir7 = $var
$ImageExit = ".GIF"
ExitLoop
EndIf
Case $msg = $SButton_4
$var = FileSelectFolder("Choose a folder.","",1 + 2 + 4,$InitDir8)
$Save_Error = @error
If Not ($Save_Error) Then
$InitDir8 = $var
$ImageExit = ".JPG"
ExitLoop
EndIf
Case $msg = $SButton_5
ExitLoop
EndSelect
WEnd
GUIDelete($SGui)
if Not($Save_Error) Then
_GDIPlus_Startup ()
For $i = 0 To UBound($ImageArray) - 1
$hBmp = $ImageArray[$i]
$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
_GDIPlus_ImageSaveToFile($hBitmap,$var & "\" & String($hBmp & $ImageExit))
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteObject($hBmp)
Next
_GDIPlus_ShutDown ()
Else
For $i = 0 To UBound($ImageArray) - 1
$hBmp = $ImageArray[$i]
_WinAPI_DeleteObject($hBmp)
Next
EndIf
EndFunc

Func SaveImage($hBmp)
Local $Save_Error = 1
$SGui = GUICreate("Save",310,100,(@DesktopWidth - 155) / 2, (@DesktopHeight - 50) / 2)
GUISetBkColor(15790320)
GUICtrlCreateGroup("Save Image", 10, 10, 280, 80)
$SButton_1 = GUICtrlCreateButton("BMP", 15, 33, 50 , 50)
$SButton_2 = GUICtrlCreateButton("PNG", 70, 33, 50 , 50)
$SButton_3 = GUICtrlCreateButton("GIF", 125, 33, 50 , 50)
$SButton_4 = GUICtrlCreateButton("JPG", 180, 33, 50 , 50)
$SButton_5 = GUICtrlCreateButton("Skip", 235, 33, 50 , 50)
GUISetState(@SW_SHOW,$SGui)
GUISwitch($SGui)
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $SButton_1
$var = FileSaveDialog("Choose a name.",$InitDir1,"IMAGE(*.BMP)",2,"Untitled" & $Num1,$SGui)
$Save_Error = @error
If Not ($Save_Error) Then
$InitDir1 = ""
$Split = StringSplit($var,"\")
For $J = 1 To $Split[0] - 1
$InitDir1 &= $Split[$J] & "\"
Next
If StringUpper(StringRight($var,4)) <> ".BMP" Then $var &= ".BMP"
$Num1 += 1
ExitLoop
EndIf
Case $msg = $SButton_2
$var = FileSaveDialog("Choose a name.",$InitDir2,"IMAGE(*.PNG)",2,"Untitled" & $Num2,$SGui)
$Save_Error = @error
If Not ($Save_Error) Then
$InitDir2 = ""
$Split = StringSplit($var,"\")
For $J = 1 To $Split[0] - 1
$InitDir2 &= $Split[$J] & "\"
Next
If StringUpper(StringRight($var,4)) <> ".PNG" Then $var &= ".PNG"
$Num2 += 1
ExitLoop
EndIf
Case $msg = $SButton_3
$var = FileSaveDialog("Choose a name.",$InitDir3,"IMAGE(*.GIF)",2,"Untitled" & $Num3,$SGui)
$Save_Error = @error
If Not ($Save_Error) Then
$InitDir3 = ""
$Split = StringSplit($var,"\")
For $J = 1 To $Split[0] - 1
$InitDir3 &= $Split[$J] & "\"
Next
If StringUpper(StringRight($var,4)) <> ".GIF" Then $var &= ".GIF"
$Num3 += 1
ExitLoop
EndIf
Case $msg = $SButton_4
$var = FileSaveDialog("Choose a name.",$InitDir4,"IMAGE(*.JPG)",2,"Untitled" & $Num4,$SGui)
$Save_Error = @error
If Not ($Save_Error) Then
$InitDir4 = ""
$Split = StringSplit($var,"\")
For $J = 1 To $Split[0] - 1
$InitDir4 &= $Split[$J] & "\"
Next
If StringUpper(StringRight($var,4)) <> ".JPG" Then $var &= ".JPG"
$Num4 += 1
ExitLoop
EndIf
Case $msg = $SButton_5
ExitLoop
EndSelect
WEnd
GUIDelete($SGui)
if Not($Save_Error) Then
_GDIPlus_Startup ()
$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
_GDIPlus_ImageSaveToFile($hBitmap,$var)
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_ShutDown ()
_WinAPI_DeleteObject($hBmp)
Else
_WinAPI_DeleteObject($hBmp)
EndIf
EndFunc

Func Mouse_Capture($DialogWin,$ShowTaskBar = True)
If Not($ShowTaskBar) Then ShowTaskBar(False)
if ($DialogWin) Then
$Return = GUISetState(@SW_HIDE,$DialogWin)
if ($Return = 0) Then Return SetError(1,0,0)
EndIf
$MouseGui = GUICreate("",0,0,0,0,BitOR($WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS) , _
BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE,$DS_MODALFRAME))
GUISetBkColor(0xFF0000,$MouseGui)
Local $HMod = _WinAPI_GetModuleHandle(0)
if ($HMod = 0) Then
GUIDelete($MouseGui)
Return SetError(2,0,0)
EndIf
$CaptureMouseTest = 0
$RegMouseProc = DllCallbackRegister("CaptureLowLevelMouseProc","long","int;wparam;lparam")
if ($RegMouseProc = 0) Then
GUIDelete($MouseGui)   
Return SetError(3,0,0)
EndIf
$MouseHHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL,DllCallbackGetPtr($RegMouseProc),$HMod)
if ($MouseHHook = 0) Then
GUIDelete($MouseGui)
DllCallbackFree($RegMouseProc)
Return SetError(4,0,0)
EndIf
Local $hBmp = 0
While 1
if $CaptureMouseTest = 2 Then
GUIDelete($MouseGui)
Sleep(300)
$hBmp = BitmapCreateFromPos($IMGE_L,$IMGE_T,$IMGE_W,$IMGE_H)
ExitLoop
EndIf
WEnd
If Not($ShowTaskBar) Then ShowTaskBar(True)
_WinAPI_UnhookWindowsHookEx($MouseHHook)
DllCallbackFree($RegMouseProc)
Return $hBmp
EndFunc


Func CaptureLowLevelMouseProc($nCode,$wParam,$lParam)
If $nCode < 0 Then _
Return _WinAPI_CallNextHookEx($MouseHHook, $nCode, $wParam, $lParam)

Select
Case $wParam == $WM_LBUTTONDOWN And $CaptureMouseTest = 0
$POINT = DllStructCreate($tagPOINT,$lParam)
$START_X =  DllStructGetData($POINT,1)
$START_Y =  DllStructGetData($POINT,2)
$CaptureMouseTest = 1
Return 1

Case $wParam == $WM_MOUSEMOVE And $CaptureMouseTest = 1
$POINT = DllStructCreate($tagPOINT,$lParam)
$MOVE_X = DllStructGetData($POINT,1)
$MOVE_Y = DllStructGetData($POINT,2)
if $START_X >= $MOVE_X Then
$L = $MOVE_X
$R = $START_X
Else
$R = $MOVE_X
$L = $START_X
EndIf
if $START_Y >= $MOVE_Y Then
$B = $START_Y
$T = $MOVE_Y
Else
$T = $START_Y
$B = $MOVE_Y
EndIf
Local $BorderSize = 3
$vL = ($L + $BorderSize)
$vT = ($T + $BorderSize)
$vR = ($R - $BorderSize)
$vB = ($B - $BorderSize)
$vW = ($vR - $vL)
$vH = ($vB - $vT)
Global $IMGE_L = $vL , $IMGE_T = $vT , $IMGE_W = $vW, $IMGE_H = $vH
MouseDrawGuiRgn($BorderSize,$L,$T,$R,$B)
Case $wParam == $WM_LBUTTONUP And $CaptureMouseTest = 1
$CaptureMouseTest = 2
Return 1
EndSelect

Return _WinAPI_CallNextHookEx($MouseHHook, $nCode, $wParam, $lParam)
EndFunc

Func MouseDrawGuiRgn($BorderSize,$L,$T,$R,$B)
Local $W = $R - $L , $H = $B - $T
Local $hREG1 = _WinAPI_CreateRectRgn(0,0,$W,$H)
Local $hREG2 = _WinAPI_CreateRectRgn($BorderSize,$BorderSize,($W - $BorderSize),($H - $BorderSize))
Local $hREG3 = _WinAPI_CreateRectRgn(0, 0, 0, 0)
_WinAPI_CombineRgn($hREG3,$hREG1,$hREG2,$RGN_DIFF)
_WinAPI_DeleteObject($hREG1)
_WinAPI_DeleteObject($hREG2)
_WinAPI_SetWindowRgn($MouseGui,$hREG3)
_WinAPI_DeleteObject($hREG3)
_WinAPI_SetWindowPos($MouseGui,0,$L,$T,$R,$B,BitOR($SWP_NOACTIVATE,$SWP_SHOWWINDOW))
Sleep(20)
EndFunc

Func ChildsCapture($DialogWin,$Flage = 0,$ShowTaskBar = True)
If Not($ShowTaskBar) Then ShowTaskBar(False)
if ($DialogWin) Then
$Return = GUISetState(@SW_HIDE,$DialogWin)
if ($Return = 0) Then Return SetError(1,0,0)
EndIf
Local $HMod = _WinAPI_GetModuleHandle(0)
if ($HMod = 0) Then Return SetError(2,0,0)
$CaptureTest = 0
Switch $Flage
Case 0
$RegProc = DllCallbackRegister("CaptureMouseProc","long","int;wparam;lparam")
if ($RegProc = 0) Then Return SetError(3,0,0)
$CapHHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL,DllCallbackGetPtr($RegProc),$HMod)
if ($CapHHook = 0) Then
DllCallbackFree($RegProc)
Return SetError(4,0,0)
EndIf
Case 1
$RegProc = DllCallbackRegister("CaptureKeyboardProc","long","int;wparam;lparam")
if ($RegProc = 0) Then Return SetError(5,0,0)
$CapHHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL,DllCallbackGetPtr($RegProc),$HMod)
if ($CapHHook = 0) Then
DllCallbackFree($RegProc)
Return SetError(6,0,0)
EndIf
Case Else
Return SetError(7,0,0)
EndSwitch
Local $hBmps = 0
While 1
$HwndsArray = WinFromPos()
if Not @error Then
$Windwo = $HwndsArray[0]
$RootOwner = $HwndsArray[1]
$IsChildWindo = $HwndsArray[2]
$ViewerSize = GetWindoViewerSize($RootOwner)
if Not @error Then
DrawGuiRgn($ViewerSize)
if ($CaptureTest) Then
GUIDelete($RgnGui)
Sleep(300)
$ChildWindwos = GetChildWindows($RootOwner)
if IsArray($ChildWindwos) Then
Local $hBmps[UBound($ChildWindwos) + 1]
For $i = 0 To UBound($ChildWindwos) - 1
$ChildWindwo = $ChildWindwos[$i][0]
$iViewerSize = GetWindoViewerSize($ChildWindwo)
if Not @error Then
$L = $iViewerSize[0]
$T = $iViewerSize[1]
$R = $iViewerSize[2]
$B = $iViewerSize[3]
$W = $R - $L
$H = $B - $T
$hBmp = BitmapCreateFromPos($L,$T,$W,$H)
$hBmps[$i] = $hBmp
Else
$hBmps[$i] = 0
EndIf
Next
$L = $ViewerSize[0]
$T = $ViewerSize[1]
$R = $ViewerSize[2]
$B = $ViewerSize[3]
$W = $R - $L
$H = $B - $T
$hBmp = BitmapCreateFromPos($L,$T,$W,$H)
$hBmps[$i] = $hBmp
ExitLoop
Else
$L = $ViewerSize[0]
$T = $ViewerSize[1]
$R = $ViewerSize[2]
$B = $ViewerSize[3]
$W = $R - $L
$H = $B - $T
$hBmp = BitmapCreateFromPos($L,$T,$W,$H)
$hBmps[0] = $hBmp
ExitLoop
EndIf
EndIf
EndIf
EndIf
WEnd
If Not($ShowTaskBar) Then ShowTaskBar(True)
_WinAPI_UnhookWindowsHookEx($CapHHook)
DllCallbackFree($RegProc)
Return $hBmps
EndFunc

Func AutoCapture($DialogWin,$Flage = 0,$ShowTaskBar = True)
If Not($ShowTaskBar) Then ShowTaskBar(False)
if ($DialogWin) Then
$Return = GUISetState(@SW_HIDE,$DialogWin)
if ($Return = 0) Then Return SetError(1,0,0)
EndIf
Local $HMod = _WinAPI_GetModuleHandle(0)
if ($HMod = 0) Then Return SetError(2,0,0)
$CaptureTest = 0
Switch $Flage
Case 0
$RegProc = DllCallbackRegister("CaptureMouseProc","long","int;wparam;lparam")
if ($RegProc = 0) Then Return SetError(3,0,0)
$CapHHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL,DllCallbackGetPtr($RegProc),$HMod)
if ($CapHHook = 0) Then
DllCallbackFree($RegProc)
Return SetError(4,0,0)
EndIf
Case 1
$RegProc = DllCallbackRegister("CaptureKeyboardProc","long","int;wparam;lparam")
if ($RegProc = 0) Then Return SetError(5,0,0)
$CapHHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL,DllCallbackGetPtr($RegProc),$HMod)
if ($CapHHook = 0) Then
DllCallbackFree($RegProc)
Return SetError(6,0,0)
EndIf
Case Else
Return SetError(7,0,0)
EndSwitch
Local $hBmp = 0
While 1
$HwndsArray = WinFromPos()
if Not @error Then
$Windwo = $HwndsArray[0]
$RootOwner = $HwndsArray[1]
$IsChildWindo = $HwndsArray[2]
$ViewerSize = GetWindoViewerSize($Windwo)
if Not @error Then
DrawGuiRgn($ViewerSize)
if ($CaptureTest) Then
if (WinExists($RgnGui)) Then
GUIDelete($RgnGui)
Sleep(300)
EndIf
Local $L = $ViewerSize[0], $T = $ViewerSize[1]
Local $R = $ViewerSize[2], $B = $ViewerSize[3]
Local $W = $R - $L , $H = $B - $T
$hBmp = BitmapCreateFromPos($L,$T,$W,$H)
ExitLoop
EndIf
EndIf
EndIf
WEnd
If Not($ShowTaskBar) Then ShowTaskBar(True)
_WinAPI_UnhookWindowsHookEx($CapHHook)
DllCallbackFree($RegProc)
Return $hBmp
EndFunc

Func DrawGuiRgn($ViewerSize)
if UBound($ViewerSize) < 4 Then Return False
Local $L = $ViewerSize[0], $T = $ViewerSize[1]
Local $R = $ViewerSize[2], $B = $ViewerSize[3]
$RgnGui = GUICreate("",0,0,0,0,BitOR($WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS) , _
BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE,$DS_MODALFRAME))
GUISetBkColor(0xFF0000,$RgnGui)
Local $W = $R - $L , $H = $B - $T
Local $hREG1 = _WinAPI_CreateRectRgn(0,0,$W,$H)
Local $hREG2 = _WinAPI_CreateRectRgn(4,4,$W - 4,$H - 4)
Local $hREG3 = _WinAPI_CreateRectRgn(0, 0, 0, 0)
_WinAPI_CombineRgn($hREG3,$hREG1,$hREG2,$RGN_DIFF)
_WinAPI_DeleteObject($hREG1)
_WinAPI_DeleteObject($hREG2)
_WinAPI_SetWindowRgn($RgnGui,$hREG3)
_WinAPI_DeleteObject($hREG3)
Sleep(300)
_WinAPI_SetWindowPos($RgnGui,0,$L,$T,$R,$B,BitOR($SWP_NOACTIVATE,$SWP_SHOWWINDOW))
Sleep(300)
GUIDelete($RgnGui)
Sleep(300)
Return True
EndFunc

Func GetWindoViewerSize($Windwo)
$Rect = _WinAPI_GetWindowRect($Windwo)
if @error Then Return SetError(1,0,0)
Local $Left = DllStructGetData($Rect,1) , $Top = DllStructGetData($Rect,2)
Local $Right = DllStructGetData($Rect,3) , $Bottom = DllStructGetData($Rect,4)
Local $jRight = @DesktopWidth , $jBottom = @DesktopHeight
if $Bottom > $jBottom Then $Bottom = $jBottom
If $Right > $jRight Then $Right = $jRight
if $Left < 0 Then $Left = 0
if $Top < 0 Then $Top = 0
if ($Right - $Left) <= 0 Or ($Bottom - $Top) <= 0 Then Return SetError(2,0,0)
Local $IsChildWindwoOfTaskBar = False
$QChildWindwos = GetChildWindows($TrayWnd)
if Not IsArray($QChildWindwos) Then Return SetError(3,0,0)
For $i = 0 To UBound($QChildWindwos) - 1
if $QChildWindwos[$i][0] = $Windwo Then $IsChildWindwoOfTaskBar = True
Next
if (Not($IsChildWindwoOfTaskBar) And $Windwo <> $TrayWnd And $Windwo <> $ButtonWnd) Then
$Rect = _WinAPI_GetWindowRect($TrayWnd)
if @error Then Return SetError(4,0,0)
$iLeft = DllStructGetData($Rect,1)
$iTop = DllStructGetData($Rect,2)
$iRight = DllStructGetData($Rect,3)
$iBottom = DllStructGetData($Rect,4)
Select
Case $iLeft = 0 And $iBottom = @DesktopHeight And $iRight = @DesktopWidth
if ($Bottom > $iTop) Then $Bottom = $iTop
Case $iLeft = 0 And $iTop = 0 And $iRight = @DesktopWidth
if ($Top < $iBottom) Then $Top = $iBottom
Case $iLeft = 0 And $iTop = 0 And $iBottom = @DesktopHeight
if ($Left < $iRight) Then $Left = $iRight
Case $iTop = 0 And $iRight = @DesktopWidth And $iBottom = @DesktopHeight
if ($Right > $iLeft) Then $Right = $iLeft
EndSelect
if ($Right - $Left) <= 0 Or ($Bottom - $Top) <= 0 Then Return SetError(5,0,0)
EndIf
Local $ViewerSize[4]
$ViewerSize[0] = $Left
$ViewerSize[1] = $Top
$ViewerSize[2] = $Right
$ViewerSize[3] = $Bottom
Return $ViewerSize
EndFunc

Func CaptureMouseProc($nCode,$wParam,$lParam)
If $nCode < 0 Then _
Return _WinAPI_CallNextHookEx($CapHHook, $nCode, $wParam, $lParam)
if ($wParam == $WM_LBUTTONDOWN And $CaptureTest = 0) Then
$CaptureTest = 1
Return 1
EndIf
if ($wParam == $WM_LBUTTONUP And $CaptureTest = 1) Then Return 1
Return _WinAPI_CallNextHookEx($CapHHook, $nCode, $wParam, $lParam)
EndFunc

Func CaptureKeyboardProc($nCode,$wParam,$lParam)
If $nCode < 0 Then _
Return _WinAPI_CallNextHookEx($CapHHook, $nCode, $wParam, $lParam)
if ($wParam = $WM_KEYDOWN And $CaptureTest = 0) Then
$CaptureTest = 1
Return 1
EndIf
if ($wParam == $WM_KEYUP And $CaptureTest = 1) Then Return 1
Return _WinAPI_CallNextHookEx($CapHHook, $nCode, $wParam, $lParam)
EndFunc

Func ShowTaskBar($BOOL)
if ($BOOL = True) Then
_WinAPI_ShowWindow($TrayWnd,@SW_SHOW)
if ($ButtonWnd) Then _WinAPI_ShowWindow($ButtonWnd,@SW_SHOW)
Else
_WinAPI_ShowWindow($TrayWnd,@SW_HIDE)
if ($ButtonWnd) Then _WinAPI_ShowWindow($ButtonWnd,@SW_HIDE)
EndIf
EndFunc

Func WinFromPos()
Local $MoPos = 0 , $HwndsArray[3]
While Not IsArray($MoPos)
$MoPos = MouseGetPos()
WEnd
$tPoint = DllStructCreate("int;int")
DllStructSetData($tPoint,1,$MoPos[0])
DllStructSetData($tPoint,2,$MoPos[1])
$PointHwnd = _WinAPI_WindowFromPoint($tPoint)
if ($PointHwnd = 0) Then Return SetError(1,0,0)
$RootOwner = _WinAPI_GetAncestor($PointHwnd,$GA_ROOTOWNER)
if ($RootOwner = 0) Then Return SetError(2,0,0)
$ChildWindwos = GetChildWindows($RootOwner)
if IsArray($ChildWindwos) Then
For $i = UBound($ChildWindwos) - 1 To 0 Step - 1
$ML = $MoPos[0]
$MT = $MoPos[1]
$ChildWindwo = $ChildWindwos[$i][0]
$L = $ChildWindwos[$i][1]
$T = $ChildWindwos[$i][2]
$W = $ChildWindwos[$i][3]
$H = $ChildWindwos[$i][4]
if ($ML >= $L ) And ($ML <= ($L + $W)) _
And ($MT >= $T ) And ($MT <= ($T + $H))  Then
$HwndsArray[0] = $ChildWindwo
$HwndsArray[1] = $RootOwner
$HwndsArray[2] = True ; IsChildWindo
Return $HwndsArray
EndIf
Next
EndIf
$HwndsArray[0] = $PointHwnd
$HwndsArray[1] = $RootOwner
$HwndsArray[2] = False ; IsChildWindo
Return $HwndsArray
EndFunc

Func GetChildWindows($HWND)
$vChildWindwos = 0
$RegChildProc = DLLCallbackRegister("EnumChildProc","int","hwnd;int")
$ChildProcPtr = DllCallbackGetPtr($RegChildProc)
DllCall("user32.dll","BOOL","EnumChildWindows","hwnd",$HWND,"ptr",$ChildProcPtr,"int",0)
DllCallbackFree($RegChildProc)
Return $vChildWindwos
EndFunc

Func EnumChildProc($HWND,$lParam)
Local $EndTest = False
For $i = 0 To UBound($vChildWindwos) - 1
if $HWND = $vChildWindwos[$i][0] Then $EndTest = True
Next
if $EndTest = False Then
if Not IsArray($vChildWindwos) Then
Dim $vChildWindwos[1][5]
Else
ReDim $vChildWindwos[UBound($vChildWindwos) + 1][5]
EndIf
$Rect = _WinAPI_GetWindowRect($HWND)
$Left = DllStructGetData($Rect,1)
$Top = DllStructGetData($Rect,2)
$Right = DllStructGetData($Rect,3)
$Bottom = DllStructGetData($Rect,4)
$L = $Left
$T = $Top
$W =  $Right - $Left
$H = $Bottom - $Top
$vChildWindwos[UBound($vChildWindwos) - 1][0] = $HWND
$vChildWindwos[UBound($vChildWindwos) - 1][1] = $L
$vChildWindwos[UBound($vChildWindwos) - 1][2] = $T
$vChildWindwos[UBound($vChildWindwos) - 1][3] = $W
$vChildWindwos[UBound($vChildWindwos) - 1][4] = $H
Return True
Else
Return False
EndIf
EndFunc

Func BitmapCreateFromPos($L,$T,$W,$H)
$DC = _WinAPI_GetWindowDC(0)
$CompatibleDC = _WinAPI_CreateCompatibleDC($DC)
$hBmp = _WinAPI_CreateCompatibleBitmap($DC,$W,$H)
_WinAPI_SelectObject($CompatibleDC,$hBmp)
_WinAPI_BitBlt($CompatibleDC,0,0,$W,$H,$DC,$L,$T,$SRCCOPY)
_WinAPI_ReleaseDC(0,$DC)
_WinAPI_DeleteDC($CompatibleDC)
Return $hBmp
EndFunc

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

 

Link to comment
Share on other sites

@wolf9228: still same problem and it is not related to my PC that the marking of an area is not working properly. See here: Short AVI taken with AutoIt Windows Screenshooter.

I can watch the Avi using KMPlayer. I used Cinepak Codec by Radius.

Btw, marking screen with AutoIt Windows Screenshooter works properly on multi monitor environment, thus it is not a PC problem! ;)

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

@wolf9228: still same problem and it is not related to my PC that the marking of an area is not working properly. See here: Short AVI taken with AutoIt Windows Screenshooter.

I can watch the Avi using KMPlayer. I used Cinepak Codec by Radius.

Btw, marking screen with AutoIt Windows Screenshooter works properly on multi monitor environment, thus it is not a PC problem! ;)

Br,

UEZ

On my device and other devices the program running successfully

notice

You can not capture these images using the Screenshooter program

Posted Image

Posted Image

Posted Image

Thank UEZ

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

 

Link to comment
Share on other sites

The problem is not the capturing, it works properly, rather the retangle for marking any area on the desktop as you can see on the short avi.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

The problem is not the capturing, it works properly, rather the retangle for marking any area on the desktop as you can see on the short avi.

Br,

UEZ

In other words, you can not select the previous windows using _WinAPI_WindowFromPoint(ByRef $tPoint) function

I think that the error caused by the sleep function

old code

Func MouseDrawGuiRgn($BorderSize,$L,$T,$R,$B)
Local $W = $R - $L , $H = $B - $T
Local $hREG1 = _WinAPI_CreateRectRgn(0,0,$W,$H)
Local $hREG2 = _WinAPI_CreateRectRgn($BorderSize,$BorderSize,($W - $BorderSize),($H - $BorderSize))
Local $hREG3 = _WinAPI_CreateRectRgn(0, 0, 0, 0)
_WinAPI_CombineRgn($hREG3,$hREG1,$hREG2,$RGN_DIFF)
_WinAPI_DeleteObject($hREG1)
_WinAPI_DeleteObject($hREG2)
_WinAPI_SetWindowRgn($MouseGui,$hREG3)
_WinAPI_DeleteObject($hREG3)
_WinAPI_SetWindowPos($MouseGui,0,$L,$T,$R,$B,BitOR($SWP_NOACTIVATE,$SWP_SHOWWINDOW))
Sleep(20)
EndFunc

New code

Func MouseDrawGuiRgn($BorderSize,$L,$T,$R,$B)
Local $W = $R - $L , $H = $B - $T
Local $hREG1 = _WinAPI_CreateRectRgn(0,0,$W,$H)
Local $hREG2 = _WinAPI_CreateRectRgn($BorderSize,$BorderSize,($W - $BorderSize),($H - $BorderSize))
Local $hREG3 = _WinAPI_CreateRectRgn(0, 0, 0, 0)
_WinAPI_CombineRgn($hREG3,$hREG1,$hREG2,$RGN_DIFF)
_WinAPI_DeleteObject($hREG1)
_WinAPI_DeleteObject($hREG2)
_WinAPI_SetWindowRgn($MouseGui,$hREG3)
_WinAPI_DeleteObject($hREG3)
_WinAPI_SetWindowPos($MouseGui,0,$L,$T,$R,$B,BitOR($SWP_NOACTIVATE,$SWP_SHOWWINDOW))
EndFunc

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

 

Link to comment
Share on other sites

No, this is not an issue with sleep but with negative values for $L and $T.

This works also on multi monitor:

Func MouseDrawGuiRgn($BorderSize, $L, $T, $R, $B)
    Local $W = $R - $L, $H = $B - $T
    Local $hREG1 = _WinAPI_CreateRectRgn(0, 0, $W, $H)
    Local $hREG2 = _WinAPI_CreateRectRgn($BorderSize, $BorderSize, ($W - $BorderSize), ($H - $BorderSize))
    Local $hREG3 = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    _WinAPI_CombineRgn($hREG3, $hREG1, $hREG2, $RGN_DIFF)
    _WinAPI_DeleteObject($hREG1)
    _WinAPI_DeleteObject($hREG2)
    _WinAPI_SetWindowRgn($MouseGui, $hREG3)
    _WinAPI_DeleteObject($hREG3)
    Local $iDeltaX = ($L < 0) * (-1 * $L)
    Local $iDeltaY = ($T < 0) * (-1 * $T)
    _WinAPI_SetWindowPos($MouseGui, 0, $L, $T, $R + $iDeltaX, $B + $iDeltaY, BitOR($SWP_NOACTIVATE, $SWP_SHOWWINDOW))
    Sleep(10)
EndFunc   ;==>MouseDrawGuiRgn

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

No, this is not an issue with sleep but with negative values for $L and $T.

This works also on multi monitor:

Func MouseDrawGuiRgn($BorderSize, $L, $T, $R, $B)
    Local $W = $R - $L, $H = $B - $T
    Local $hREG1 = _WinAPI_CreateRectRgn(0, 0, $W, $H)
    Local $hREG2 = _WinAPI_CreateRectRgn($BorderSize, $BorderSize, ($W - $BorderSize), ($H - $BorderSize))
    Local $hREG3 = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    _WinAPI_CombineRgn($hREG3, $hREG1, $hREG2, $RGN_DIFF)
    _WinAPI_DeleteObject($hREG1)
    _WinAPI_DeleteObject($hREG2)
    _WinAPI_SetWindowRgn($MouseGui, $hREG3)
    _WinAPI_DeleteObject($hREG3)
    Local $iDeltaX = ($L < 0) * (-1 * $L)
    Local $iDeltaY = ($T < 0) * (-1 * $T)
    _WinAPI_SetWindowPos($MouseGui, 0, $L, $T, $R + $iDeltaX, $B + $iDeltaY, BitOR($SWP_NOACTIVATE, $SWP_SHOWWINDOW))
    Sleep(10)
EndFunc ;==>MouseDrawGuiRgn

Br,

UEZ

Local $iDeltaX = ($L < 0) * (-1 * $L)

Local $iDeltaY = ($T < 0) * (-1 * $T)

UEZ genius Thank Thank For mathematical equation and thank you for helping :thumbsup:

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

 

Link to comment
Share on other sites

Sure and it is very simple :)

($L < 0) means when $L variable is negative then ($L < 0) becomes True or 1.

True * (-1 * -$L) = $L -> $iDeltaX is alway positive and added to $R otherwise the retangle will move if mouse x pos will move to negative coordinate (as you can see in the avi).

If $L is positive then $iDeltaX is always 0 -> False * (-1 * $L) = 0

Analogue for $T.

Clear?

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Sure and it is very simple :)

($L < 0) means when $L variable is negative then ($L < 0) becomes True or 1.

True * (-1 * -$L) = $L -> $iDeltaX is alway positive and added to $R otherwise the retangle will move if mouse x pos will move to negative coordinate (as you can see in the avi).

If $L is positive then $iDeltaX is always 0 -> False * (-1 * $L) = 0

Analogue for $T.

Clear?

Br,

UEZ

Ok UEZ $L and $T can not be less than zero on the Code Of ScreenCaptureEx program

if so Possible In any case of Moas happen

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

 

Link to comment
Share on other sites

To illustrate the dialogue on this page

These mathematical equations are wrong

Local $iDeltaX = ($L < 0) * (-1 * $L)

Local $iDeltaY = ($T < 0) * (-1 * $T)

And also I did not take advantage from the AutoIt Windows Screenshooter. program

Thanks to all participants

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

 

Link to comment
Share on other sites

Hmm, I don't understand what you want to say! :huh2:

Why are the lines wrong? What has this to do with AutoIt Windows Screenshooter?

Br,

UEZ :huh:

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Hmm, I don't understand what you want to say! :huh2:

Why are the lines wrong? What has this to do with AutoIt Windows Screenshooter?

Br,

UEZ :huh:

You understand what I'm writing well

Dear Genius

The minimal screen x coordinate to move the mouse Is zero

The minimal screen y coordinate to move the mouse Is zero

The maximal screen x coordinate to move the mouse Is @DesktopWidth

The maximal screen y coordinate to move the mouse Is @DesktopHeight

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

 

Link to comment
Share on other sites

You understand what I'm writing well

Dear Genius

The minimal screen x coordinate to move the mouse Is zero

The minimal screen y coordinate to move the mouse Is zero

The maximal screen x coordinate to move the mouse Is @DesktopWidth

The maximal screen y coordinate to move the mouse Is @DesktopHeight

That's not true when you have a 2nd monitor which is positioned left to the main monitor. The x coordinate of the mouse will be negative! That's the reason why the retangle moves to the left when mouse is on the 2nd monitor.

I can show you this as a video tomorrow when I'm back in the office again.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

UEZ is right...

http://msdn.microsoft.com/en-us/library/dd145136%28v=vs.85%29.aspx

#include <WinApi.au3>

; The Virtual Screen
; http://msdn.microsoft.com/en-us/library/dd145136%28v=vs.85%29.aspx

; GetSystemMetrics
; http://msdn.microsoft.com/en-us/library/windows/desktop/ms724385%28v=vs.85%29.aspx
Global Const $SM_XVIRTUALSCREEN = 76 ; The coordinates for the left side of the virtual screen.
Global Const $SM_YVIRTUALSCREEN = 77 ; The coordinates for the top of the virtual screen.
Global Const $SM_CXVIRTUALSCREEN = 78 ; The width of the virtual screen, in pixels.
Global Const $SM_CYVIRTUALSCREEN = 79 ; The height of the virtual screen, in pixels.

MsgBox(0, "", _WinAPI_GetSystemMetrics($SM_XVIRTUALSCREEN) & "x" & _WinAPI_GetSystemMetrics($SM_YVIRTUALSCREEN) & @CRLF & _WinAPI_GetSystemMetrics($SM_CXVIRTUALSCREEN) & "x" & _WinAPI_GetSystemMetrics($SM_CYVIRTUALSCREEN))
Edited by KaFu
Link to comment
Share on other sites

Here a short AVI to show you the mouse coordinates when you have a second monitor to the left of the main monitor!

ScreenCaptureEx_20130307_130509_.avi

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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...