Sign in to follow this  
Followers 0
GianAutoitprogrammer

How to capture the screen like the Print Screen command....

19 posts in this topic

How to print the screen using autoit?

I know _ScreenCapture_Capture but I want to print only a region of the screen

#include <A3LScreenCap.au3>

; Capture full screen
_ScreenCap_Capture("C:\Image1.jpg")

; Capture region
_ScreenCap_Capture("C:\Image2.jpg", 0, 0, 796, 596)

But I want to print the screen selected by the user...

:unsure: i dont know how to do that!

PLEASE HELP

ME!

Share this post


Link to post
Share on other sites



GianAutoitprogrammer,

Perhaps this might help: :unsure:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <ScreenCapture.au3>
#Include <Misc.au3>

Global $iX1, $iY1, $iX2, $iY2, $aPos, $sMsg, $sBMP_Path

; Create GUI
$hMain_GUI = GUICreate("Select Rectangle", 240, 50)

$hRect_Button   = GUICtrlCreateButton("Mark Area",  10, 10, 80, 30)
$hCancel_Button = GUICtrlCreateButton("Cancel",    150, 10, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $hCancel_Button
            FileDelete(@ScriptDir & "\Rect.bmp")
            Exit
        Case $hRect_Button
            GUISetState(@SW_HIDE, $hMain_GUI)
            Mark_Rect()
            ; Capture selected area
            $sBMP_Path = @ScriptDir & "\Rect.bmp"
            _ScreenCapture_Capture($sBMP_Path, $iX1, $iY1, $iX2, $iY2, False)
            GUISetState(@SW_SHOW, $hMain_GUI)
            ; Display image
            $hBitmap_GUI = GUICreate("Selected Rectangle", $iX2 - $iX1 + 1, $iY2 - $iY1 + 1, 100, 100)
            $hPic = GUICtrlCreatePic(@ScriptDir & "\Rect.bmp", 0, 0, $iX2 - $iX1 + 1, $iY2 - $iY1 + 1)
            GUISetState()

    EndSwitch

WEnd

; -------------

Func Mark_Rect()

    Local $aMouse_Pos, $hMask, $hMaster_Mask, $iTemp
    Local $UserDLL = DllOpen("user32.dll")

    Global $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
    _GUICreateInvRect($hRectangle_GUI, 0, 0, 1, 1)
    GUISetBkColor(0)
    WinSetTrans($hRectangle_GUI, "", 50)
    GUISetState(@SW_SHOW, $hRectangle_GUI)
    GUISetCursor(3, 1, $hRectangle_GUI)

    ; Wait until mouse button pressed
    While Not _IsPressed("01", $UserDLL)
        Sleep(10)
    WEnd

    ; Get first mouse position
    $aMouse_Pos = MouseGetPos()
    $iX1 = $aMouse_Pos[0]
    $iY1 = $aMouse_Pos[1]

    ; Draw rectangle while mouse button pressed
    While _IsPressed("01", $UserDLL)

        $aMouse_Pos = MouseGetPos()

        ; Set in correct order if required
        If $aMouse_Pos[0] < $iX1 Then
            $iX_Pos = $aMouse_Pos[0]
            $iWidth = $iX1 - $aMouse_Pos[0]
        Else
            $iX_Pos = $iX1
            $iWidth = $aMouse_Pos[0] - $iX1
        EndIf
        If $aMouse_Pos[1] < $iY1 Then
            $iY_Pos = $aMouse_Pos[1]
            $iHeight = $iY1 - $aMouse_Pos[1]
        Else
            $iY_Pos = $iY1
            $iHeight = $aMouse_Pos[1] - $iY1
        EndIf

        _GUICreateInvRect($hRectangle_GUI, $iX_Pos, $iY_Pos, $iWidth, $iHeight)

        Sleep(10)

    WEnd

    ; Get second mouse position
    $iX2 = $aMouse_Pos[0]
    $iY2 = $aMouse_Pos[1]

    ; Set in correct order if required
    If $iX2 < $iX1 Then
        $iTemp = $iX1
        $iX1 = $iX2
        $iX2 = $iTemp
    EndIf
    If $iY2 < $iY1 Then
        $iTemp = $iY1
        $iY1 = $iY2
        $iY2 = $iTemp
    EndIf

    GUIDelete($hRectangle_GUI)
    DllClose($UserDLL)

EndFunc   ;==>Mark_Rect

Func _GUICreateInvRect($hWnd, $iX, $iY, $iW, $iH)

    $hMask_1 = _WinAPI_CreateRectRgn(0, 0, @DesktopWidth, $iY)
    $hMask_2 = _WinAPI_CreateRectRgn(0, 0, $iX, @DesktopHeight)
    $hMask_3 = _WinAPI_CreateRectRgn($iX + $iW, 0, @DesktopWidth, @DesktopHeight)
    $hMask_4 = _WinAPI_CreateRectRgn(0, $iY + $iH, @DesktopWidth, @DesktopHeight)

    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_2, 2)
    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_3, 2)
    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_4, 2)

    _WinAPI_DeleteObject($hMask_2)
    _WinAPI_DeleteObject($hMask_3)
    _WinAPI_DeleteObject($hMask_4)

    _WinAPI_SetWindowRgn($hWnd, $hMask_1, 1)

EndFunc

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

See ! Posted Image

Edit : @Melba23 you are too fast for me ! Posted Image

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

tnx guys! :unsure::>;)

Share this post


Link to post
Share on other sites

One more link: :unsure:

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

GianAutoitprogrammer,

Perhaps this might help: :unsure:

M23

I have a question - I tried to do it myself (but lacking skills) - is there a way to return screencapture into the clipboard rather than a file?


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

nitekram,

I have just tried to put the file into the ClipBoard with _ClipPutFile and got error = 9. :>

If you look in the UDF code then this is a fail of a "GlobalFree" call to kernel32.dll. I have no idea what that means or how to fix it, sorry. :unsure:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Quick and dirty

Opt("WinTitleMatchMode", 2)
Sleep(500)
Send("{PrintScreen}");; Put the screen on the clipboard
Run("mspaint")
WinWaitActive("Paint")
Sleep(50)
Send("^v");; paste it into MSPaint

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

The function that M23 wrote - will capture just the X1,X2,Y1,Y2 that is needed - not the whole screen. I am wanting to use his script, but be able to put it in the clipboard to be able to paste it where ever.

I did not know that there was a _ClipPutFile() function - could come in handing some day.

I was just trying to return the variable from the function _ScreenCapture_Capture(), but that does not work.

Anyone help? It would be really cool to have this, as I have people using SnagIt right now, but for what we do it would save money

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

nitekram ,

This works for me using an already opened Paint window: :>

; Add these includes
#Include <Clipboard.au3>
#Include <WinAPI.au3>

; And use this loop
While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $hCancel_Button
            Exit
        Case $hRect_Button
            GUISetState(@SW_HIDE, $hMain_GUI)
            Mark_Rect()
            ; Capture selected area to clipboard
            $hBitmap = _ScreenCapture_Capture("", $iX1, $iY1, $iX2, $iY2, False)
            _ClipBoard_Open($hMain_GUI)
            _ClipBoard_SetDataEx($hBitmap, $CF_BITMAP)
            _ClipBoard_Close()
            _WinAPI_DeleteObject($hBitmap)
            WinActivate("Untitled - Paint")
            WinWaitActive("Untitled - Paint")
            Send("^v")
    EndSwitch

WEnd

Does it work for you too? :unsure:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Does it work for you too? :unsure:

M23

I have tried with an open and unopened paint application - both gave me the same error - Error getting the Clipboard Data!

system is XP SP3

EDIT it did not paste anything, I ended up trying to paste with 'ctrl v' - that is when I got the error

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

Here an extract from

#include <Clipboard.au3>
#include <GDIPlus.au3>
#include <GDIPlusConstants.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

;coded by UEZ build 2011-02-27
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Icon=Images\Audiograbber_64x64_transparent.ico
#AutoIt3Wrapper_Res_Description=Takes a screenshot from marked area on desktop
#AutoIt3Wrapper_Res_Fileversion=0.6.5.5
#AutoIt3Wrapper_Res_LegalCopyright=UEZ 2010
#AutoIt3Wrapper_Res_Language=1033
://////=__=
;~ #AutoIt3Wrapper_Res_Comment=
://////=__=--
://////=__=
://////=__=
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_UPX_Parameters=--ultra-brute
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_Obfuscated.au3"

;~ #include <Array.au3>
Opt("MustDeclareVars", 1)
TraySetState (2)
Global $zx = 0, $zy = 0, $up = 1
Global $zoom_level = 6, $zoom_min = 2, $zoom_max = 25
Mark_Area("", True)
_Exit()

Func Mark_Area($filename = "", $execute = False, $disable_aero = False)
    If $filename <> "" And Not StringRegExp($filename, "\.(jpg|bmp|gif|png|tif)$") Then _
        _WinAPI_ShowError($filename & @CRLF & @CRLF &  "Unknown image filename extension!" & @CRLF & _
                                                       "Valid extensions are: bmp, gif, jpg, png, tif!")

    ;http://msdn.microsoft.com/en-us/library/aa969510%28VS.85%29.aspx
    Local Const $hDwmApiDll = DllOpen("dwmapi.dll")
    Local $sChkAero = DllStructCreate("int;")
    DllCall($hDwmApiDll, "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($sChkAero))
    Local $aero_on = DllStructGetData($sChkAero, 1)
    If $aero_on And $disable_aero Then DllCall($hDwmApiDll, "int", "DwmEnableComposition", "uint", False)
    $sChkAero = 0
    Sleep(500)

    Local Const $user32_dll = DllOpen("user32.dll")
    Local $w, $h, $mpos = MouseGetPos(), $pixel_color

    Local $hGUI_Cross = GUICreate("", 30, 30,  $mpos[0], $mpos[1], $WS_POPUP, BitOR($WS_DISABLED, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
    Local $hGUI_Dot = GUICreate("", 1, 1, 18, 18, BitOR($WS_POPUP, $WS_CLIPSIBLINGS), $WS_EX_TOPMOST)
    GUISetBkColor(0, $hGUI_Dot)
    GUISetState(@SW_SHOW, $hGUI_Dot)
    GUISetState(@SW_SHOW, $hGUI_Cross)
    WinSetTrans($hGUI_Cross, "", 1)

    HotKeySet("{ESC}", "_Exit")

    Local Const $zw = 256
    Local Const $zh = 256
    Local Const $lW = 40
    Local Const $lH = 40
    Local Const $dist_x = 24, $dist_y = 24
    Local $zoomW = Int($zw / $zoom_level)
    Local $zoomH = Int($zh / $zoom_level)
    Local $hGUI_Zoom = GUICreate("Zoom", $zw, $zh, $zx, $zx,BitOR($WS_POPUP,$DS_MODALFRAME), BitOR($WS_EX_OVERLAPPEDWINDOW,$WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
    GUISetState(@SW_SHOW, $hGUI_Zoom)
    Local $hDC_Zoom = _WinAPI_GetDC(0)
    Local $hGUI_ZoomDC = _WinAPI_GetDC($hGUI_Zoom)
    _WinAPI_SetBkMode($hGUI_ZoomDC, $TRANSPARENT)

    Local $hDC_Draw = _WinAPI_GetWindowDC(0)
    Local $hPen = _WinAPI_CreatePen($PS_DASHDOT, 8, 0x0000FF) ;BGR
    Local $obj_orig = _WinAPI_SelectObject($hDC_Draw, $hPen)

    GUIRegisterMsg(0x020A, "WM_MOUSEWHEEL")
    Local $aLastPos[2]
    Do
        GUISetCursor(3, 1, $hGUI_Cross)
        $mpos = MouseGetPos()
        If _IsPressed("02", $user32_dll) Then _WinAPI_DrawLine($hDC_Draw, $mpos[0] - 100 , $mpos[1] - 100 , $mpos[0]-100 , $mpos[1]-100)
        If $mpos[0] <> $aLastPos[0] Or $mpos[1] <> $aLastPos[1] Then
            $pixel_color = Hex(PixelGetColor($mpos[0], $mpos[1]), 6)
            WinMove($hGUI_Cross, "", $mpos[0] - 15, $mpos[1] - 15)
            WinMove($hGUI_Dot, "", $mpos[0], $mpos[1])
            ToolTip("Please mark area" & @CRLF & _
                    "on your desktop!" & @CRLF & _
                    "ESC to abort"& @CRLF & @CRLF & _
                    "Pixel Color: 0x" & $pixel_color, $mpos[0] + $dist_x + $zoomW / 3, $mpos[1] + $dist_y +  + $zoomH / 3)
            $aLastPos = $mpos
        EndIf
        If CheckRectCollision($zx - $lW, $zy - $lH , $zx + $zw + $lW, $zy + $zh + $lH, $mpos[0], $mpos[1]) Then
            $up *= -1
            If $up = -1 Then
                $zx = @DesktopWidth - $zw - 4
                WinMove($hGUI_Zoom, "", $zx, $zy)
            Else
                $zx = 0
                WinMove($hGUI_Zoom, "", $zx, $zy)
            EndIf
        EndIf
        _WinAPI_StretchBlt($hGUI_ZoomDC, 0, 0, $zw, $zh, $hDC_Zoom, $mpos[0] - $zoomW / 2, $mpos[1] - $zoomH / 2, $zoomW, $zoomH, $SRCCOPY)
        $zoomW = Int($zw / $zoom_level)
        $zoomH = Int($zh / $zoom_level)

        Sleep(30)
    Until _IsPressed("01", $user32_dll)
    ToolTip("")
    HotKeySet("{ESC}")
    GUIRegisterMsg(0x020A, "")
    _WinAPI_SelectObject($hDC_Draw, $obj_orig)
    _WinAPI_DeleteObject($hPen)
    _WinAPI_ReleaseDC(0, $hDC_Draw)

    $mpos = MouseGetPos()
    Local $m_startx = $mpos[0]
    Local $m_starty = $mpos[1]

    Local $hGUI = GUICreate("", 0, 0, $m_startx, $m_starty, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_STATICEDGE))
    GUISetState(@SW_SHOW, $hGUI)
    GUISetBkColor(0x0000B0)
    Local $size = 2
    Local $label, $label_text = "ScreenGrabber by UEZ'10"
    If @OSVersion = "WIN_XP" Then
        $label = GUICtrlCreateLabel($label_text, $size, $size, 0, 0, Default, $WS_EX_COMPOSITED) ;$WS_EX_COMPOSITED is not working with AERO properly
    Else
        $label = GUICtrlCreateLabel($label_text, $size, $size, 0, 0) ;$WS_EX_COMPOSITED is not working with AERO properly
    EndIf
    GUICtrlSetFont($label, 6)
    GUICtrlSetBkColor($label, 0xB0C0F0)
    WinSetTrans($hGUI, "", 0x80)

    Local  $iX1, $iY1, $aLastPos[2]
    Do
        GUISetCursor(3, 1, $hGUI)
        $mpos = MouseGetPos()
        If $mpos[0] <> $aLastPos[0] Or $mpos[1] <> $aLastPos[1] Then
            $w = Abs($mpos[0] - $m_startx ) + 1
            $h = Abs($mpos[1] - $m_starty) + 1
            If $mpos[0] < $m_startx  Then
                $iX1 = $mpos[0]
            Else
                $iX1 = $m_startx
            EndIf
            If $mpos[1] < $m_starty Then
                $iY1 = $mpos[1]
            Else
                $iY1 = $m_starty
            EndIf
            $pixel_color = Hex(PixelGetColor($mpos[0], $mpos[1]), 6)
            ToolTip($w & "x" & $h & @CRLF & "Pixel Color: 0x" & $pixel_color)
            WinMove($hGUI,"", $iX1 ,$iY1 , $w, $h)
            WinMove($hGUI_Dot, "", $mpos[0], $mpos[1])
            $aLastPos = $mpos
            GUICtrlSetPos($label, $size, $size, $w - $size * 2 - 3, $h - $size * 2 - 3)
        EndIf
        If CheckRectCollision($zx - $lW / 2, $zy - $lH / 2, $zx + $zw + $lW / 2, $zy + $zh + $lH / 2, $mpos[0], $mpos[1]) Then
            $up *= -1
            If $up = -1 Then
                $zx = @DesktopWidth - $zw - 4
                WinMove($hGUI_Zoom, "", $zx, $zy)
            Else
                $zx = 0
                WinMove($hGUI_Zoom, "", $zx, $zy)
            EndIf
        EndIf
        _WinAPI_StretchBlt($hGUI_ZoomDC, 0, 0, $zw, $zh, $hDC_Zoom, $mpos[0] - $zoomW / 2, $mpos[1] - $zoomH / 2, $zoomW, $zoomH, $SRCCOPY)
        Sleep(20)
    Until Not _IsPressed("01", $user32_dll)
    ToolTip("")
    DllClose($user32_dll)
    GUIDelete($hGUI_Cross)
    _WinAPI_ReleaseDC($hGUI_Zoom, $hGUI_ZoomDC)
    _WinAPI_ReleaseDC(0, $hDC_Zoom)
    _WinAPI_DeleteDC($hGUI_ZoomDC)
    _WinAPI_DeleteDC($hDC_Zoom)
    GUIDelete($hGUI_Zoom)
    Local $Win_Coord = WinGetPos($hGUI) ;x,y,width,height
    GUIDelete($hGUI)

    Grab_Region($Win_Coord[0], $Win_Coord[1], $Win_Coord[2], $Win_Coord[3], $filename)
    If $aero_on Then
        DllCall($hDwmApiDll, "int", "DwmEnableComposition", "uint", True)
    EndIf
    DllClose($hDwmApiDll)
    Sleep(500)
    If $filename <> "" And $execute Then ShellExecute($filename)
EndFunc

Func WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam)
    Local $wheel_Dir = _WinAPI_HiWord($wParam)
    If $wheel_Dir > 0 Then
        If $zoom_level < $zoom_max Then
            $zoom_level += 1
        EndIf
    Else
        If $zoom_level  > $zoom_min Then
            $zoom_level  -= 1
        EndIf
    EndIf
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_MOUSEWHEEL

Func Grab_Region($x, $y, $w, $h, $filename, $jpg_quality = 85)
    Local $err, $err_txt
    Local $hDC = _WinAPI_GetDC(0)
    Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    Local $memBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
    Local $hObj = _WinAPI_SelectObject($hMemDC, $memBitmap)
    _WinAPI_BitBlt($hMemDC, 0, 0, $w, $h, $hDC, $x, $y, $SRCCOPY)

    _GDIPlus_Startup()
    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($memBitmap)
    If @error Then Return SetError(1, @extended, _WinAPI_ShowError("Unable to create HBITMAP!"))
    If $filename <> "" Then
        If StringRight($filename, 3) = "jpg" Then
            Local $sCLSID = _GDIPlus_EncodersGetCLSID ("JPG")
            Local $tParams = _GDIPlus_ParamInit (1)
            Local $tData = DllStructCreate("int Quality")
            DllStructSetData($tData, "Quality", $jpg_quality) ;quality 0-100 (poor-best)
            Local $pData = DllStructGetPtr($tData)
            _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)
            Local $pParams = DllStructGetPtr($tParams)
            _GDIPlus_ImageSaveToFileEx($hBitmap, $filename, $sCLSID, $pParams)
            $tData = 0
        Else
            _GDIPlus_ImageSaveToFile($hBitmap, $filename)
        EndIf
    Else
        If Not _ClipBoard_Open(0) Then
            $err = @error
            $err_txt = "_ClipBoard_Open failed!"
        EndIf
        If Not _ClipBoard_Empty() Then
            $err = @error
            $err_txt = "_ClipBoard_Empty failed!"
        EndIf
        If Not _ClipBoard_SetDataEx($memBitmap, $CF_BITMAP) Then
            $err = @error
            $err_txt = "_ClipBoard_SetDataEx failed!"
        EndIf
        _ClipBoard_Close()
        If Not $err Then MsgBox(0, "Information", "Image grabbed to clipboard!", 10)
    EndIf
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_DeleteObject($memBitmap)
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_DeleteDC($hDC)
    If $err Then Return SetError(1, @extended, _WinAPI_ShowError($err_txt))
    Return SetError(0)
EndFunc

Func _Exit()
    Exit
EndFunc

Func _WinAPI_StretchBlt($hDestDC, $iXDest, $iYDest, $iWidthDest, $iHeightDest, $hSrcDC, $iXSrc, $iYSrc, $iWidthSrc, $iHeightSrc, $iRop)
    Local $Ret  = DllCall('gdi32.dll', 'int', 'StretchBlt', 'hwnd', $hDestDC, 'int', $iXDest, 'int', $iYDest, 'int', $iWidthDest, 'int', $iHeightDest, 'hwnd', $hSrcDC, 'int', $iXSrc, 'int', $iYSrc, 'int', $iWidthSrc, 'int', $iHeightSrc, 'dword', $iRop)
    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    Return 1
EndFunc   ;==>_WinAPI_StretchBlt

Func CheckRectCollision($iLeft, $iTop, $iRight, $iBottom, $iX, $iY )
    Local $tagRECT = "int Left;int Top;int Right;int Bottom"
    Local $tRECT = DllStructCreate($tagRECT)
    DllStructSetData($tRECT, 1, $iLeft)
    DllStructSetData($tRECT, 2, $iTop)
    DllStructSetData($tRECT, 3, $iRight)
    DllStructSetData($tRECT, 4, $iBottom)
    Local $aResult = DllCall("User32.dll", "int", "PtInRect", "ptr", DllStructGetPtr($tRECT), "int", $iX, "int", $iY)
    Return $aResult[0] <> 0
EndFunc

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Does it work for you too? :unsure:

M23

@Melba23

I'm on XPsp3 and I can paste screencapture part in PaintDotNet without problem ! Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Here an extract from

Br,

UEZ

That seems to work, I have to do some testing, but it looks like this is the ticket - thanks!

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

@ UEZ

I have done some testing - and what I am looking for is a little help in escaping out of the code. Without exiting out of the application - is there a way to just hide it until i need it again. I am trying to incorporate your code into mine, and hide or delete your code when hitting the escape key, but allowing it to reopen when called again. In your code you EXIT out of the application, any help would be greatfull.

I have tried a few things like deleting and hiding the guis in the _Exit function, but I have had no luck so far.

Thanks again for your help.

EDIT - this is as close as i have come to doing what i want, but it appears that there is a gui that is hidden somewhere - it shows up in the taskbar, but there is no way to close it? - I made the variables global in my code to make this work.

Func _Exit()
    MsgBox('','','closing')

    GUIDelete($hGUI_Cross)
    GUIDelete($hGUI_Zoom)
    GUIDelete($hGUI)

    _WinAPI_ReleaseDC($hGUI_Zoom, $hGUI_ZoomDC)
    _WinAPI_ReleaseDC(0, $hDC_Zoom)
    _WinAPI_DeleteDC($hGUI_ZoomDC)
    _WinAPI_DeleteDC($hDC_Zoom)

    DllClose($user32_dll)
    DllClose($hDwmApiDll)

    ToolTip("")
    HotKeySet("{ESC}")

    sleep(10000)
    Exit

EndFunc

EDIT 2

if you take out the sleep and exit my application hangs and the tool tip does not disappear. The hanging, might not be the right word, but I am unable to work on my computer afterwards as the mouse buttons do not close. You have to hit Ctrl Alt Del and go to task manager and then use your arrows to move down to the autoit.exe and then hit the delete key to close out of the application.

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

In case someone else wants to give this a try. I am trying to allow for the ECS key to exit out of the screen capture, but not exit out of the application - and then be able to pull up the screen capture again.

HINT - before removing the sleep and exit from the function _Exit()

If you take out the sleep and exit my application hangs and the tool tip does not disappear. The hanging, might not be the right word, but I am unable to work on my computer afterwards as the mouse buttons does not close the application. You have to hit Ctrl Alt Del and go to task manager and then use your arrows to move down to the autoit.exe and then hit the delete key to close out of the application.

#include <Clipboard.au3>
#include <GDIPlus.au3>
#include <GDIPlusConstants.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>





;coded by UEZ build 2011-02-27
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Icon=Images\Audiograbber_64x64_transparent.ico
#AutoIt3Wrapper_Res_Description=Takes a screenshot from marked area on desktop
#AutoIt3Wrapper_Res_Fileversion=0.6.5.5
#AutoIt3Wrapper_Res_LegalCopyright=UEZ 2010
#AutoIt3Wrapper_Res_Language=1033
://////=__=
;~ #AutoIt3Wrapper_Res_Comment=
://////=__=--
://////=__=
://////=__=
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_UPX_Parameters=--ultra-brute
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_Obfuscated.au3"



; for screen captur
Global $zx = 0, $zy = 0, $up = 1
Global $zoom_level = 6, $zoom_min = 2, $zoom_max = 25
Global $hGUI = '', $hGUI_Dot = '', $hGUI_Cross = '', $hGUI_Zoom = '', $user32_dll = '', $hDC_Zoom = '', $hGUI_ZoomDC = ''
Global $hDwmApiDll = '', $hDC_Draw, $obj_orig, $hPen
Global $hBitmap, $hMemDC, $memBitmap, $hDC



Example1()




; example 1
Func Example1()
    Local $msg

    GUICreate("My GUI") ; will create a dialog box that when displayed is centered
    $button1 = GUICtrlCreateButton('screen caputer', 0, 0)
    GUISetState(@SW_SHOW) ; will display an empty dialog box

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        If $msg = $button1 Then Mark_Area("", True)
    WEnd
    GUIDelete()
EndFunc   ;==>Example1









; functions for Screen capture

Func Mark_Area($filename = "", $execute = False, $disable_aero = False)
    If $filename <> "" And Not StringRegExp($filename, "\.(jpg|bmp|gif|png|tif)$") Then _
            _WinAPI_ShowError($filename & @CRLF & @CRLF & "Unknown image filename extension!" & @CRLF & _
            "Valid extensions are: bmp, gif, jpg, png, tif!")

    ;http://msdn.microsoft.com/en-us/library/aa969510%28VS.85%29.aspx
    Local Const $hDwmApiDll = DllOpen("dwmapi.dll")
    Local $sChkAero = DllStructCreate("int;")
    DllCall($hDwmApiDll, "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($sChkAero))
    Local $aero_on = DllStructGetData($sChkAero, 1)
    If $aero_on And $disable_aero Then DllCall($hDwmApiDll, "int", "DwmEnableComposition", "uint", False)
    $sChkAero = 0
    Sleep(500)

    $user32_dll = DllOpen("user32.dll")
    Local $w, $h, $mpos = MouseGetPos(), $pixel_color

    $hGUI_Cross = GUICreate("", 30, 30, $mpos[0], $mpos[1], $WS_POPUP, BitOR($WS_DISABLED, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
    $hGUI_Dot = GUICreate("", 1, 1, 18, 18, BitOR($WS_POPUP, $WS_CLIPSIBLINGS), $WS_EX_TOPMOST)
    GUISetBkColor(0, $hGUI_Dot)
    GUISetState(@SW_SHOW, $hGUI_Dot)
    GUISetState(@SW_SHOW, $hGUI_Cross)
    WinSetTrans($hGUI_Cross, "", 1)

    HotKeySet("{ESC}", "_Exit")

    Local Const $zw = 256
    Local Const $zh = 256
    Local Const $lW = 40
    Local Const $lH = 40
    Local Const $dist_x = 24, $dist_y = 24
    Local $zoomW = Int($zw / $zoom_level)
    Local $zoomH = Int($zh / $zoom_level)
    $hGUI_Zoom = GUICreate("Zoom", $zw, $zh, $zx, $zx, BitOR($WS_POPUP, $DS_MODALFRAME), BitOR($WS_EX_OVERLAPPEDWINDOW, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
    GUISetState(@SW_SHOW, $hGUI_Zoom)
    $hDC_Zoom = _WinAPI_GetDC(0)
    $hGUI_ZoomDC = _WinAPI_GetDC($hGUI_Zoom)
    _WinAPI_SetBkMode($hGUI_ZoomDC, $TRANSPARENT)

    $hDC_Draw = _WinAPI_GetWindowDC(0)
    $hPen = _WinAPI_CreatePen($PS_DASHDOT, 8, 0x0000FF) ;BGR
    $obj_orig = _WinAPI_SelectObject($hDC_Draw, $hPen)

    GUIRegisterMsg(0x020A, "WM_MOUSEWHEEL")
    Local $aLastPos[2]
    Do
        GUISetCursor(3, 1, $hGUI_Cross)
        $mpos = MouseGetPos()
        If _IsPressed("02", $user32_dll) Then _WinAPI_DrawLine($hDC_Draw, $mpos[0] - 100, $mpos[1] - 100, $mpos[0] - 100, $mpos[1] - 100)
        If $mpos[0] <> $aLastPos[0] Or $mpos[1] <> $aLastPos[1] Then
            $pixel_color = Hex(PixelGetColor($mpos[0], $mpos[1]), 6)
            WinMove($hGUI_Cross, "", $mpos[0] - 15, $mpos[1] - 15)
            WinMove($hGUI_Dot, "", $mpos[0], $mpos[1])
            ToolTip("Please mark area" & @CRLF & _
                    "on your desktop!" & @CRLF & _
                    "ESC to abort" & @CRLF & @CRLF & _
                    "Pixel Color: 0x" & $pixel_color, $mpos[0] + $dist_x + $zoomW / 3, $mpos[1] + $dist_y + + $zoomH / 3)
            $aLastPos = $mpos
        EndIf
        If CheckRectCollision($zx - $lW, $zy - $lH, $zx + $zw + $lW, $zy + $zh + $lH, $mpos[0], $mpos[1]) Then
            $up *= -1
            If $up = -1 Then
                $zx = @DesktopWidth - $zw - 4
                WinMove($hGUI_Zoom, "", $zx, $zy)
            Else
                $zx = 0
                WinMove($hGUI_Zoom, "", $zx, $zy)
            EndIf
        EndIf
        _WinAPI_StretchBlt($hGUI_ZoomDC, 0, 0, $zw, $zh, $hDC_Zoom, $mpos[0] - $zoomW / 2, $mpos[1] - $zoomH / 2, $zoomW, $zoomH, $SRCCOPY)
        $zoomW = Int($zw / $zoom_level)
        $zoomH = Int($zh / $zoom_level)

        Sleep(30)
    Until _IsPressed("01", $user32_dll)
    ToolTip("")
    HotKeySet("{ESC}")
    GUIRegisterMsg(0x020A, "")
    _WinAPI_SelectObject($hDC_Draw, $obj_orig)
    _WinAPI_DeleteObject($hPen)
    _WinAPI_ReleaseDC(0, $hDC_Draw)

    $mpos = MouseGetPos()
    Local $m_startx = $mpos[0]
    Local $m_starty = $mpos[1]

    Local $hGUI = GUICreate("", 0, 0, $m_startx, $m_starty, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_STATICEDGE))
    GUISetState(@SW_SHOW, $hGUI)
    GUISetBkColor(0x0000B0)
    Local $size = 2
    Local $label, $label_text = "ScreenGrabber by UEZ'10"
    If @OSVersion = "WIN_XP" Then
        $label = GUICtrlCreateLabel($label_text, $size, $size, 0, 0, Default, $WS_EX_COMPOSITED) ;$WS_EX_COMPOSITED is not working with AERO properly
    Else
        $label = GUICtrlCreateLabel($label_text, $size, $size, 0, 0) ;$WS_EX_COMPOSITED is not working with AERO properly
    EndIf
    GUICtrlSetFont($label, 6)
    GUICtrlSetBkColor($label, 0xB0C0F0)
    WinSetTrans($hGUI, "", 0x80)

    Local $iX1, $iY1, $aLastPos[2]
    Do
        GUISetCursor(3, 1, $hGUI)
        $mpos = MouseGetPos()
        If $mpos[0] <> $aLastPos[0] Or $mpos[1] <> $aLastPos[1] Then
            $w = Abs($mpos[0] - $m_startx) + 1
            $h = Abs($mpos[1] - $m_starty) + 1
            If $mpos[0] < $m_startx Then
                $iX1 = $mpos[0]
            Else
                $iX1 = $m_startx
            EndIf
            If $mpos[1] < $m_starty Then
                $iY1 = $mpos[1]
            Else
                $iY1 = $m_starty
            EndIf
            $pixel_color = Hex(PixelGetColor($mpos[0], $mpos[1]), 6)
            ToolTip($w & "x" & $h & @CRLF & "Pixel Color: 0x" & $pixel_color)
            WinMove($hGUI, "", $iX1, $iY1, $w, $h)
            WinMove($hGUI_Dot, "", $mpos[0], $mpos[1])
            $aLastPos = $mpos
            GUICtrlSetPos($label, $size, $size, $w - $size * 2 - 3, $h - $size * 2 - 3)
        EndIf
        If CheckRectCollision($zx - $lW / 2, $zy - $lH / 2, $zx + $zw + $lW / 2, $zy + $zh + $lH / 2, $mpos[0], $mpos[1]) Then
            $up *= -1
            If $up = -1 Then
                $zx = @DesktopWidth - $zw - 4
                WinMove($hGUI_Zoom, "", $zx, $zy)
            Else
                $zx = 0
                WinMove($hGUI_Zoom, "", $zx, $zy)
            EndIf
        EndIf
        _WinAPI_StretchBlt($hGUI_ZoomDC, 0, 0, $zw, $zh, $hDC_Zoom, $mpos[0] - $zoomW / 2, $mpos[1] - $zoomH / 2, $zoomW, $zoomH, $SRCCOPY)
        Sleep(20)
    Until Not _IsPressed("01", $user32_dll)
    ToolTip("")
    DllClose($user32_dll)
    GUIDelete($hGUI_Cross)
    _WinAPI_ReleaseDC($hGUI_Zoom, $hGUI_ZoomDC)
    _WinAPI_ReleaseDC(0, $hDC_Zoom)
    _WinAPI_DeleteDC($hGUI_ZoomDC)
    _WinAPI_DeleteDC($hDC_Zoom)
    GUIDelete($hGUI_Zoom)
    Local $Win_Coord = WinGetPos($hGUI) ;x,y,width,height
    GUIDelete($hGUI)

    Grab_Region($Win_Coord[0], $Win_Coord[1], $Win_Coord[2], $Win_Coord[3], $filename)
    If $aero_on Then
        DllCall($hDwmApiDll, "int", "DwmEnableComposition", "uint", True)
    EndIf
    DllClose($hDwmApiDll)
    Sleep(500)
    If $filename <> "" And $execute Then ShellExecute($filename)
EndFunc   ;==>Mark_Area

Func WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam)
    Local $wheel_Dir = _WinAPI_HiWord($wParam)
    If $wheel_Dir > 0 Then
        If $zoom_level < $zoom_max Then
            $zoom_level += 1
        EndIf
    Else
        If $zoom_level > $zoom_min Then
            $zoom_level -= 1
        EndIf
    EndIf
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_MOUSEWHEEL

Func Grab_Region($x, $y, $w, $h, $filename, $jpg_quality = 85)
    Local $err, $err_txt
    Local $hDC = _WinAPI_GetDC(0)
    Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    Local $memBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
    Local $hObj = _WinAPI_SelectObject($hMemDC, $memBitmap)
    _WinAPI_BitBlt($hMemDC, 0, 0, $w, $h, $hDC, $x, $y, $SRCCOPY)

    _GDIPlus_Startup()
    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($memBitmap)
    If @error Then Return SetError(1, @extended, _WinAPI_ShowError("Unable to create BITMAP!"))
    If $filename <> "" Then
        If StringRight($filename, 3) = "jpg" Then
            Local $sCLSID = _GDIPlus_EncodersGetCLSID("JPG")
            Local $tParams = _GDIPlus_ParamInit(1)
            Local $tData = DllStructCreate("int Quality")
            DllStructSetData($tData, "Quality", $jpg_quality) ;quality 0-100 (poor-best)
            Local $pData = DllStructGetPtr($tData)
            _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)
            Local $pParams = DllStructGetPtr($tParams)
            _GDIPlus_ImageSaveToFileEx($hBitmap, $filename, $sCLSID, $pParams)
            $tData = 0
        Else
            _GDIPlus_ImageSaveToFile($hBitmap, $filename)
        EndIf
    Else
        If Not _ClipBoard_Open(0) Then
            $err = @error
            $err_txt = "_ClipBoard_Open failed!"
        EndIf
        If Not _ClipBoard_Empty() Then
            $err = @error
            $err_txt = "_ClipBoard_Empty failed!"
        EndIf
        If Not _ClipBoard_SetDataEx($memBitmap, $CF_BITMAP) Then
            $err = @error
            $err_txt = "_ClipBoard_SetDataEx failed!"
        EndIf
        _ClipBoard_Close()
        If Not $err Then MsgBox(0, "Information", "Image grabbed to clipboard!", 10)
    EndIf
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_DeleteObject($memBitmap)
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_DeleteDC($hDC)
    If $err Then Return SetError(1, @extended, _WinAPI_ShowError($err_txt))
    Return SetError(0)
EndFunc   ;==>Grab_Region


Func _Exit()
    MsgBox('', '', 'closing')

    GUIDelete($hGUI_Cross)
    GUIDelete($hGUI_Zoom)
    GUIDelete($hGUI)
    #cs
        _WinAPI_ReleaseDC($hGUI_Zoom, $hGUI_ZoomDC)
        _WinAPI_ReleaseDC(0, $hDC_Zoom)
        _WinAPI_DeleteDC($hGUI_ZoomDC)
        _WinAPI_DeleteDC($hDC_Zoom)
        
        
        _GDIPlus_BitmapDispose($hBitmap)
        _GDIPlus_Shutdown()
        _WinAPI_DeleteDC($hMemDC)
        _WinAPI_DeleteObject($memBitmap)
        _WinAPI_ReleaseDC(0, $hDC)
        _WinAPI_DeleteDC($hDC)
    #ce

    ;DllClose($user32_dll)
    ;DllClose($hDwmApiDll)

    ToolTip("")
    HotKeySet("{ESC}")

    Sleep(10000)
    Exit

EndFunc   ;==>_Exit

Func _WinAPI_StretchBlt($hDestDC, $iXDest, $iYDest, $iWidthDest, $iHeightDest, $hSrcDC, $iXSrc, $iYSrc, $iWidthSrc, $iHeightSrc, $iRop)
    Local $Ret = DllCall('gdi32.dll', 'int', 'StretchBlt', 'hwnd', $hDestDC, 'int', $iXDest, 'int', $iYDest, 'int', $iWidthDest, 'int', $iHeightDest, 'hwnd', $hSrcDC, 'int', $iXSrc, 'int', $iYSrc, 'int', $iWidthSrc, 'int', $iHeightSrc, 'dword', $iRop)
    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    Return 1
EndFunc   ;==>_WinAPI_StretchBlt

Func CheckRectCollision($iLeft, $iTop, $iRight, $iBottom, $iX, $iY)
    Local $tagRECT = "int Left;int Top;int Right;int Bottom"
    Local $tRECT = DllStructCreate($tagRECT)
    DllStructSetData($tRECT, 1, $iLeft)
    DllStructSetData($tRECT, 2, $iTop)
    DllStructSetData($tRECT, 3, $iRight)
    DllStructSetData($tRECT, 4, $iBottom)
    Local $aResult = DllCall("User32.dll", "int", "PtInRect", "ptr", DllStructGetPtr($tRECT), "int", $iX, "int", $iY)
    Return $aResult[0] <> 0
EndFunc   ;==>CheckRectCollision
Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Try this:

 

;coded by UEZ build 2011-08-05
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Icon=..\..\..\Images\Audiograbber_64x64_transparent.ico
#AutoIt3Wrapper_Res_Description=Takes a screenshot from marked area on desktop
#AutoIt3Wrapper_Res_Fileversion=0.7.5.0
#AutoIt3Wrapper_Res_LegalCopyright=UEZ 2010
#AutoIt3Wrapper_Res_Language=1033
;~ #AutoIt3Wrapper_Res_Field=Coded by|UEZ
;~ #AutoIt3Wrapper_Res_Comment=
;~ #AutoIt3Wrapper_Res_Field=Build|2011-08-05 Beta
;~ #AutoIt3Wrapper_Res_Field=Compile date|%longdate% %time%
;~ #AutoIt3Wrapper_Res_Field=AutoIt Version|%AutoItVer%
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_UPX_Parameters=--best --lzma
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_Obfuscated.au3"
;~ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include <ButtonConstants.au3>
#include <Clipboard.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)
Opt("GUICloseOnESC", 0)
TraySetState (2)

Global Const $hGUI_Main = GUICreate("ScreenGrabber by UEZ 2010/2011", 314, 86)
GUISetBkColor(0xA6CAF0)
Global Const $bCSR = GUICtrlCreateButton("Capture Screen Region", 8, 8, 203, 41)
GUICtrlSetFont(-1, 15, 400, 0, "Times New Roman")
Global Const $bExit = GUICtrlCreateButton("Exit", 224, 8, 83, 41)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
Global Const $lSave = GUICtrlCreateLabel("Save Image to:", 10, 58, 88, 16)
GUICtrlSetFont(-1, 10, 400, 0, "Times New Roman")
Global Const  $Input = GUICtrlCreateInput("", 92, 56, 214, 21)
GUICtrlSetTip(-1, "Type in the path + filename where to save the captured image" & @LF & "If empty captured image will be copied to clipboard!")
GUICtrlSetFont(-1, 10, 400, 0, "Times New Roman")
GUISetState(@SW_SHOW, $hGUI_Main)
Global $zx = 0, $zy = 0, $up = 1
Global $zoom_level = 6, $zoom_min = 2, $zoom_max = 25
Global $nMsg, $esc, $f, $hGUI, $label
Global Const $margin = 12, $size = 2

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE,  $bExit
            GUIDelete($hGUI_Main)
            Exit
        Case $bCSR
            $zoom_level = 6
            $esc = False
            $f = GUICtrlRead($Input)
            Mark_Area($f, True)
    EndSwitch
WEnd


Func Mark_Area($filename = "", $execute = False, $disable_aero = False)
    If $filename <> "" And Not StringRegExp($filename, "\.(jpg|bmp|gif|png|tif)$") Then _
        _WinAPI_ShowError($filename & @CRLF & @CRLF &  "Unknown image filename extension!" & @CRLF & _
                                                                                                         "Valid extensions are: bmp, gif, jpg, png, tif!")

    ;http://msdn.microsoft.com/en-us/library/aa969510(VS.85).aspx
    Local Const $hDwmApiDll = DllOpen("dwmapi.dll")
    Local $sChkAero = DllStructCreate("int;")
    DllCall($hDwmApiDll, "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($sChkAero))
    Local $aero_on = DllStructGetData($sChkAero, 1)
    If $aero_on And $disable_aero Then DllCall($hDwmApiDll, "int", "DwmEnableComposition", "uint", False)
    $sChkAero = 0

    Local Const $user32_dll = DllOpen("user32.dll")
    Local $w, $h, $mpos = MouseGetPos(), $pixel_color
    Local $old_cursor = MouseGetCursor()

    Local $hGUI_Cross = GUICreate("", 30, 30,  $mpos[0], $mpos[1], $WS_POPUP, BitOR($WS_DISABLED, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
    Local $hGUI_Dot = GUICreate("", 1, 1, 18, 18, BitOR($WS_POPUP, $WS_CLIPSIBLINGS), $WS_EX_TOPMOST, WinGetHandle(AutoItWinGetTitle()))
    GUISetBkColor(0, $hGUI_Dot)
    GUISetState(@SW_SHOW, $hGUI_Dot)
    GUISetState(@SW_SHOW, $hGUI_Cross)
    WinSetTrans($hGUI_Cross, "", 1)

    HotKeySet("{ESC}", "_Exit_CSR")

    Local Const $zw = 256
    Local Const $zh = 256
    Local Const $lW = 40
    Local Const $lH = 40
    Local Const $dist_x = 24, $dist_y = 24, $radius = 160
    Local $dirx = 1, $drx = 0, $diry = 1, $dry = 0, $lower_border, $right_border
    Local $zoomW = Int($zw / $zoom_level)
    Local $zoomH = Int($zh / $zoom_level)
    Local $hGUI_Zoom = GUICreate("Zoom", $zw, $zh, $zx, $zx, BitOR($WS_POPUP,$DS_MODALFRAME), BitOR($WS_EX_OVERLAPPEDWINDOW,$WS_EX_TOPMOST,$WS_EX_WINDOWEDGE), WinGetHandle(AutoItWinGetTitle()))
    GUISetState(@SW_SHOW, $hGUI_Zoom)
    Local $hDC_Zoom = _WinAPI_GetDC(0)
    Local $hGUI_ZoomDC = _WinAPI_GetDC($hGUI_Zoom)
    _WinAPI_SetBkMode($hGUI_ZoomDC, $TRANSPARENT)

    Local $hDC_Draw = _WinAPI_GetWindowDC(0)
    Local $hPen = _WinAPI_CreatePen($PS_DASHDOT, 8, 0x0000FF) ;BGR
    Local $obj_orig = _WinAPI_SelectObject($hDC_Draw, $hPen)

    Local $aPos, $aRet, $aRet_prev, $area, $g
    Local $hGUI_Mark = GUICreate("", 0, 0, 0, 0, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW)
    GUISetBkColor(0xFF0000, $hGUI_Mark)
    GUISetState(@SW_HIDE, $hGUI_Mark)
    Local Const $frame_size = 2

    GUIRegisterMsg(0x020A, "WM_MOUSEWHEEL")
    Local $aLastPos[2]
    WinSetState($hGUI_Main, "", @SW_MINIMIZE)
    Do
        If $esc Then ExitLoop
        $mpos = MouseGetPos()
        If _IsPressed("11", $user32_dll) Then
            GUISetState(@SW_HIDE, $hGUI_Zoom)
            $aRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", $mpos[0], "long", $mpos[1])
            $aPos = WinGetPos(HWnd($aRet[0]))
            If $aRet[0] <> $hGUI_Mark And $aRet[0] <> 0 And $aRet[0] <> $aRet_prev And $aRet[0] <> $hGUI_Cross Then
                $aRet_prev = $aRet[0]
                WinMove($hGUI_Mark, "", $aPos[0], $aPos[1], $aPos[2], $aPos[3])
                _GuiHole($hGUI_Mark, $frame_size, $frame_size, $aPos[2] - 2 * $frame_size, $aPos[3] - 2 * $frame_size, $aPos[2], $aPos[3])
                GUISetState(@SW_SHOW, $hGUI_Mark)
            EndIf
            ToolTip("")
            $area = True
            If _IsPressed("12", $user32_dll) Then ExitLoop
        Else
            $area = False
            GUISetState(@SW_SHOW, $hGUI_Zoom)
            GUISetState(@SW_HIDE, $hGUI_Mark)
            GUISetCursor(3, 1, $hGUI_Cross)
            If _IsPressed("02", $user32_dll) Then _WinAPI_DrawLine($hDC_Draw, $mpos[0] - 100 , $mpos[1] - 100 , $mpos[0] - 100 , $mpos[1] - 100)
            If $mpos[0] <> $aLastPos[0] Or $mpos[1] <> $aLastPos[1] Then
                $pixel_color = Hex(PixelGetColor($mpos[0], $mpos[1]), 6)
                WinMove($hGUI_Cross, "", $mpos[0] - 15, $mpos[1] - 15)
                WinMove($hGUI_Dot, "", $mpos[0], $mpos[1])
                ToolTip("Mark area on your" & @CRLF & _
                              "desktop! Hold Ctrl to" & @CRLF & _
                              "select controls, Ctrl+Alt"& @CRLF & _
                              "to grab control!"& @CRLF & _
                              "ESC to abort"& @CRLF & @CRLF & _
                              "Position: " & $mpos[0] & "," & $mpos[1] & @CRLF & _
                              "Pixel Color: 0x" & $pixel_color, $drx + $mpos[0] + $dirx * ($dist_x + $zoomW / 3) , $dry + $mpos[1] + $diry * ($dist_y + $zoomH / 3))
                $aLastPos = $mpos

                $right_border = Pixel_Distance($mpos[0], $mpos[1], @DesktopWidth, $mpos[1])
                If $right_border < $radius Then
                    $dirx = -1
                    $drx = -$radius
                Else
                    $dirx = 1
                    $drx = 0
                EndIf
                $lower_border = Pixel_Distance($mpos[0], $mpos[1], $mpos[0], @DesktopHeight)
                If $lower_border < $radius Then
                    $diry = -1
                    $dry = -$radius
                Else
                    $diry = 1
                    $dry = 0
                EndIf
            EndIf
        EndIf

        If CheckRectCollision($zx - $lW, $zy - $lH , $zx + $zw + $lW, $zy + $zh + $lH, $mpos[0], $mpos[1]) Then
            $up *= -1
            If $up = -1 Then
                $zx = @DesktopWidth - $zw - 4
                WinMove($hGUI_Zoom, "", $zx, $zy)
            Else
                $zx = 0
                WinMove($hGUI_Zoom, "", $zx, $zy)
            EndIf
        EndIf
        _WinAPI_StretchBlt($hGUI_ZoomDC, 0, 0, $zw, $zh, $hDC_Zoom, $mpos[0] - $zoomW / 2, $mpos[1] - $zoomH / 2, $zoomW, $zoomH, $SRCCOPY)
        $zoomW = Int($zw / $zoom_level)
        $zoomH = Int($zh / $zoom_level)

        Sleep(30)
    Until _IsPressed("01", $user32_dll)
    GUIDelete($hGUI_Mark)
    ToolTip("")

    If $area Then
        $g = Grab_Region($aPos[0], $aPos[1], $aPos[2], $aPos[3], $filename)
    Else
        HotKeySet("{ESC}")
        GUIRegisterMsg(0x020A, "")
        _WinAPI_SelectObject($hDC_Draw, $obj_orig)
        _WinAPI_DeleteObject($hPen)
        _WinAPI_ReleaseDC(0, $hDC_Draw)

        $mpos = MouseGetPos()
        Local $m_startx = $mpos[0]
        Local $m_starty = $mpos[1]

        $hGUI = GUICreate("", 0, 0, $m_startx, $m_starty, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_COMPOSITED)
        GUISetState(@SW_SHOW, $hGUI)
        GUISetBkColor(0xC8D8FF)
;~      Local $label_text = "ScreenGrabber by UEZ'10"
;~      $label = GUICtrlCreateLabel($label_text, $size, $size, 0, 0)
;~      GUICtrlSetFont($label, 6)
;~      GUICtrlSetBkColor($label, 0xC8D8FF)
        WinSetTrans($hGUI, "", 0x70)

        GUIRegisterMsg($WM_LBUTTONDOWN, "WM_LBUTTONDOWN")
        GUIRegisterMsg($WM_MOUSEMOVE, "SetCursor")

        Local  $iX1, $iY1, $aLastPos[2], $selected = False
;~      GUISetCursor($old_cursor, 1, $hGUI)
        Do
;~          GUISetCursor(3, 1, $hGUI)
            $mpos = MouseGetPos()
            If $mpos[0] <> $aLastPos[0] Or $mpos[1] <> $aLastPos[1] Then
                If Not $selected Then
                    $w = Abs($mpos[0] - $m_startx) + 1
                    $h = Abs($mpos[1] - $m_starty) + 1
                EndIf
                If $mpos[0] < $m_startx  Then
                    $iX1 = $mpos[0]
                Else
                    $iX1 = $m_startx
                EndIf
                If $mpos[1] < $m_starty Then
                    $iY1 = $mpos[1]
                Else
                    $iY1 = $m_starty
                EndIf
                $pixel_color = Hex(PixelGetColor($mpos[0], $mpos[1]), 6)

                $right_border = Pixel_Distance($mpos[0], $mpos[1], @DesktopWidth, $mpos[1])
                If $right_border < $radius Then
                    $drx = -$radius
                Else
                    $drx = $radius / 4
                EndIf
                $lower_border = Pixel_Distance($mpos[0], $mpos[1], $mpos[0], @DesktopHeight)
                If $lower_border < $radius Then
                    $dry = -$radius
                Else
                    $dry = $radius / 4
                EndIf

                If  Not $selected Then WinMove($hGUI,"", $iX1 ,$iY1 , $w, $h)
                WinMove($hGUI_Dot, "", $mpos[0], $mpos[1])
                $aLastPos = $mpos
                ToolTip("Windows Size: " & $w & "x" & $h & @CRLF & "Position: " & $mpos[0] & "," & $mpos[1], $drx + $mpos[0], $dry + $mpos[1])
                GUICtrlSetPos($label, $size, $size, $w - $size * 2, $h - $size * 2)
            EndIf

            If CheckRectCollision($zx - $lW / 2, $zy - $lH / 2, $zx + $zw + $lW / 2, $zy + $zh + $lH / 2, $mpos[0], $mpos[1]) Then
                $up *= -1
                If $up = -1 Then
                    $zx = @DesktopWidth - $zw - 4
                    WinMove($hGUI_Zoom, "", $zx, $zy)
                Else
                    $zx = 0
                    WinMove($hGUI_Zoom, "", $zx, $zy)
                EndIf
            EndIf

            _WinAPI_StretchBlt($hGUI_ZoomDC, 0, 0, $zw, $zh, $hDC_Zoom, $mpos[0] - $zoomW / 2, $mpos[1] - $zoomH / 2, $zoomW, $zoomH, $SRCCOPY)

            If Not _IsPressed("01", $user32_dll) Then $selected = True
            Sleep(20)
        Until _IsPressed("1B", $user32_dll)
        GUIRegisterMsg($WM_LBUTTONDOWN, "")
        GUIRegisterMsg($WM_MOUSEMOVE, "")
        ToolTip("")
        DllClose($user32_dll)
        _WinAPI_ReleaseDC($hGUI_Zoom, $hGUI_ZoomDC)
        _WinAPI_ReleaseDC(0, $hDC_Zoom)
        _WinAPI_DeleteDC($hGUI_ZoomDC)
        _WinAPI_DeleteDC($hDC_Zoom)
        Local $Win_Coord = WinGetPos($hGUI) ;x,y,width,height
        GUIDelete($hGUI_Dot)
        GUIDelete($hGUI_Cross)
        GUIDelete($hGUI_Zoom)
        GUIDelete($hGUI_ZoomDC)
        GUIDelete($hGUI)

        If Not $esc Then $g = Grab_Region($Win_Coord[0], $Win_Coord[1], $Win_Coord[2], $Win_Coord[3], $filename)
    EndIf
    If $aero_on Then DllCall($hDwmApiDll, "int", "DwmEnableComposition", "uint", True)
    DllClose($hDwmApiDll)
    Sleep(500)
    WinSetState($hGUI_Main, "", @SW_RESTORE)
    If $filename <> "" And $execute Then ShellExecute($filename)
EndFunc

;GetMousePosType returns a code depending on the border the mouse cursor is near
Func GetMousePosType()
    Local $cp = GUIGetCursorInfo($hGUI)
    Local $wp = WinGetPos($hGUI)
    If @error Then Return 0
    Local $side = 0
    Local $TopBot = 0
    Local $curs
    If $cp[0] < $margin Then $side = 1
    If $cp[0] > $wp[2] - $margin Then $side = 2
    If $cp[1] < $margin Then $TopBot = 3
    If $cp[1] > $wp[3] - $margin Then $TopBot = 6
    Return $side + $TopBot
EndFunc ;==>GetMousePosType

Func SetCursor()
Local $curs
    Switch GetMousePosType()
        Case 0
            $curs = 2
        Case 1, 2
            $curs = 13
        Case 3, 6
            $curs = 11
        Case 5, 7
            $curs = 10
        Case 4, 8
            $curs = 12
    EndSwitch
    GUISetCursor($curs, 1)
EndFunc ;==>SetCursor

Func WM_LBUTTONDOWN($hWnd, $iMsg, $StartWIndowPosaram, $lParam)
    Local $drag = GetMousePosType()
    If $drag > 0 Then
        DllCall("user32.dll", "long", "SendMessage", "hwnd", $hWnd, "int", $WM_SYSCOMMAND, "int", 0xF000 + $drag, "int", 0)
    EndIf
;F001 = LHS, F002 = RHS, F003 = top, F004 = TopLeft, F005 = TopRight, F006 = Bottom, F007 = BL, F008 = BR
;F009 = move gui, same as F011 F12  to F01F
;F010,  moves cursor to centre top of gui - no idea what that is useful for.
;F020 minimizes
;F030 maximizes
EndFunc ;==>WM_LBUTTONDOWN

Func _Exit_CSR()
    $esc = True
    Return
EndFunc

Func WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam)
    Local $wheel_Dir = _WinAPI_HiWord($wParam)
    If $wheel_Dir > 0 Then
        If $zoom_level < $zoom_max Then
            $zoom_level += 1
        EndIf
    Else
        If $zoom_level  > $zoom_min Then
            $zoom_level  -= 1
        EndIf
    EndIf
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_MOUSEWHEEL

Func Grab_Region($x, $y, $w, $h, $filename, $jpg_quality = 85)
    Local $err, $err_txt, $s
    Local $hDC = _WinAPI_GetDC(0)
    Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    Local $memBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
    _WinAPI_SelectObject($hMemDC, $memBitmap)
    _WinAPI_BitBlt($hMemDC, 0, 0, $w, $h, $hDC, $x, $y, $SRCCOPY)

    _GDIPlus_Startup()
    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($memBitmap)
    If @error Then Return SetError(1, @extended, _WinAPI_ShowError("Unable to create HBITMAP!"))
    If $filename <> "" Then
        If StringRight($filename, 3) = "jpg" Then
            Local $sCLSID = _GDIPlus_EncodersGetCLSID ("JPG")
            Local $tParams = _GDIPlus_ParamInit (1)
            Local $tData = DllStructCreate("int Quality")
            DllStructSetData($tData, "Quality", $jpg_quality) ;quality 0-100 (poor-best)
            Local $pData = DllStructGetPtr($tData)
            _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)
            Local $pParams = DllStructGetPtr($tParams)
            $s = _GDIPlus_ImageSaveToFileEx($hBitmap, $filename, $sCLSID, $pParams)
            $tData = 0
        Else
            $s = _GDIPlus_ImageSaveToFile($hBitmap, $filename)
            $err = @error
        EndIf
        If Not $s Then
            $err_txt = "Unable to save file!"
        EndIf
    Else
        If Not _ClipBoard_Open(0) Then
            $err = @error
            $err_txt = "_ClipBoard_Open failed!"
        EndIf
        If Not _ClipBoard_Empty() Then
            $err = @error
            $err_txt = "_ClipBoard_Empty failed!"
        EndIf
        If Not _ClipBoard_SetDataEx($memBitmap, $CF_BITMAP) Then
            $err = @error
            $err_txt = "_ClipBoard_SetDataEx failed!"
        EndIf
        _ClipBoard_Close()
        If Not $err Then MsgBox(0, "Information", "Image grabbed to clipboard!", 10)
    EndIf
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_DeleteObject($memBitmap)
    _WinAPI_DeleteDC($hDC)
    If $err Then Return SetError(1, @extended, _WinAPI_ShowError($err_txt))
    Return SetError(0)
EndFunc

Func _WinAPI_StretchBlt($hDestDC, $iXDest, $iYDest, $iWidthDest, $iHeightDest, $hSrcDC, $iXSrc, $iYSrc, $iWidthSrc, $iHeightSrc, $iRop)
    Local $Ret  = DllCall('gdi32.dll', 'int', 'StretchBlt', 'hwnd', $hDestDC, 'int', $iXDest, 'int', $iYDest, 'int', $iWidthDest, 'int', $iHeightDest, 'hwnd', $hSrcDC, 'int', $iXSrc, 'int', $iYSrc, 'int', $iWidthSrc, 'int', $iHeightSrc, 'dword', $iRop)
    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    Return 1
EndFunc   ;==>_WinAPI_StretchBlt

Func CheckRectCollision($iLeft, $iTop, $iRight, $iBottom, $iX, $iY )
    Local $tagRECT = "int Left;int Top;int Right;int Bottom"
    Local $tRECT = DllStructCreate($tagRECT)
    DllStructSetData($tRECT, 1, $iLeft)
    DllStructSetData($tRECT, 2, $iTop)
    DllStructSetData($tRECT, 3, $iRight)
    DllStructSetData($tRECT, 4, $iBottom)
    Local $aResult = DllCall("User32.dll", "int", "PtInRect", "ptr", DllStructGetPtr($tRECT), "int", $iX, "int", $iY)
    Return $aResult[0] <> 0
EndFunc

Func Pixel_Distance($x1, $y1, $x2, $y2) ;Pythagoras theorem
    Local $a, $b
    If $x2 = $x1 And $y2 = $y1 Then Return 0
    $a = $y2 - $y1
    $b = $x2 - $x1
    Return Sqrt($a * $a + $b * $b)
EndFunc   ;==>Pixel_Distance

Func _GuiHole($hWnd, $i_x, $i_y, $i_sizew, $i_sizeh, $width, $height)
    Local $outer_rgn, $inner_rgn, $combined_rgn
    $outer_rgn = _WinAPI_CreateRectRgn(0, 0, $width, $height)
    $inner_rgn = _WinAPI_CreateRectRgn($i_x, $i_y, $i_x + $i_sizew, $i_y + $i_sizeh)
    $combined_rgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    _WinAPI_CombineRgn($combined_rgn, $outer_rgn, $inner_rgn, $RGN_DIFF)
    _WinAPI_DeleteObject($outer_rgn)
    _WinAPI_DeleteObject($inner_rgn)
    _WinAPI_SetWindowRgn($hWnd, $combined_rgn)
EndFunc   ;==>_GuiHole
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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Try this:

Br,

UEZ

Will have to give it a shot tomorrow - but it looks like this may do the trick - thanks for your time!


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

@UEZ

It works - you are the best. I do not think I would have been able to figure that out, so thanks again for your time.


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
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
Sign in to follow this  
Followers 0