Jump to content

YO need help in dragging the selected area


ActualAkshay
 Share

Recommended Posts

I found this script a while ago somewhere in the forums, dont know who is the real auther :S :S :S sorry about that

#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

the scripts work perfect, cant it be done that selected area can be dragged? and double clicking captures the area?

plz help asap,

PS thanks in advance :)

Link to comment
Share on other sites

  • Moderators

ActualAkshay,

It is actually my original code. :)

But this is not a trivial request. The transparent area is created within another GUI and so dragging it requires the entire GUI to be moved - this can pose problems as Windows does not like you dragging the top of a GUI higher than the top of the display. Moving the rectangle also affects the position of the transparent area relative to the underlying GUI, so it will need some careful maths to make sure that the script then captures the correct area when triggered. :(

Do not expect miracles and certainly do not expect any result quickly. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

ActualAkshay,

It is actually my original code. :)

But this is not a trivial request. The transparent area is created within another GUI and so dragging it requires the entire GUI to be moved - this can pose problems as Windows does not like you dragging the top of a GUI higher than the top of the display. Moving the rectangle also affects the position of the transparent area relative to the underlying GUI, so it will need some careful maths to make sure that the script then captures the correct area when triggered. :(

Do not expect miracles and certainly do not expect any result quickly. ;)

M23

I am not really good at maths, :thumbsdown: isnt there any other way of doing it? and also which is smooth like this script? (maybe because area is being marked inside the gui)

Thanks for replying :)

Link to comment
Share on other sites

  • Moderators

ActualAkshay,

I am working on it - but be patient. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

In Windows Screenshooter you can select an area on the desktop and move the retangle.

When I find some time I will create a small code extract with the same feature.

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

  • Moderators

UEZ,

Trying to spoil my fun, eh! And just when I have it almost working too! :mad:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Go ahead Melba23, I didn't start it at all.

To extract the part from Windows Screenshooter is not easy because of spaghetti code. ;)

Sorry when I have spoiled your fun which was not my intention. :

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

  • Moderators

UEZ,

I was only joking, my friend! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

ActualAkshay,

I had to change the code to give you an outline rectangle rather than a transparent one - and at the moment you fire the screenshot by releasing the mouse button. You drag the rectangle by dragging the lines themselves - or the little box in the top left corner. See what you think: ;)

#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")

    ; Create transparent GUI with Cross cursor
    $hCross_GUI = GUICreate("Test", @DesktopWidth, @DesktopHeight - 20, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
    WinSetTrans($hCross_GUI, "", 8)
    GUISetState(@SW_SHOW, $hCross_GUI)
    GUISetCursor(3, 1, $hCross_GUI)

    Global $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
    GUISetBkColor(0x000000)

    ; 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()

        $hMaster_Mask = _WinAPI_CreateRectRgn(0, 0, 0, 0)
        $hMask = _WinAPI_CreateRectRgn($iX1,  $aMouse_Pos[1], $aMouse_Pos[0],  $aMouse_Pos[1] + 1) ; Bottom of rectangle
        _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
        _WinAPI_DeleteObject($hMask)
        $hMask = _WinAPI_CreateRectRgn($iX1, $iY1, $iX1 + 1, $aMouse_Pos[1]) ; Left of rectangle
        _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
        _WinAPI_DeleteObject($hMask)
        $hMask = _WinAPI_CreateRectRgn($iX1 + 1, $iY1 + 1, $aMouse_Pos[0], $iY1) ; Top of rectangle
        _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
        _WinAPI_DeleteObject($hMask)
        $hMask = _WinAPI_CreateRectRgn($aMouse_Pos[0], $iY1, $aMouse_Pos[0] + 1,  $aMouse_Pos[1]) ; Right of rectangle
        _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
        _WinAPI_DeleteObject($hMask)
        ; Set overall region
        _WinAPI_SetWindowRgn($hRectangle_GUI, $hMaster_Mask)

        If WinGetState($hRectangle_GUI) < 15 Then GUISetState()
        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)
    GUIDelete($hCross_GUI)
    DllClose($UserDLL)

    ; Create a transparent GUI to show an identical rectangle
    $hDrag_GUI = GUICreate("", $iX2 - $iX1, $iY2 - $iY1, $iX1, $iY1, $WS_POPUP, BitOr($WS_EX_LAYERED, $WS_EX_TOPMOST))
    GUISetBkColor(0xABCDEF)
    GUICtrlCreateLabel("", 0, 0, 5, 5)
    GUICtrlSetBkColor(-1, 0)
    GUICtrlCreateLabel("", 0, 0, $iX2 - $iX1, 1)
    GUICtrlSetBkColor(-1, 0)
    GUICtrlCreateLabel("", $iX2 - $iX1 - 1, 0, 1, $iY2 - $iY1)
    GUICtrlSetBkColor(-1, 0)
    GUICtrlCreateLabel("", 0, 0, 1, $iY2 - $iY1)
    GUICtrlSetBkColor(-1, 0)
    GUICtrlCreateLabel("", 0, $iY2 - $iY1 - 1, $iX2 - $iX1, 1)
    GUICtrlSetBkColor(-1, 0)
    _WinAPI_SetLayeredWindowAttributes($hDrag_GUI, 0xABCDEF, 250)
    GUISetState()

    ; Allow the mouse up message to register
    While GUIGetMsg()
        Sleep(10)
    WEnd

    While 1

        Switch GUIGetMsg()
            Case $GUI_EVENT_PRIMARYDOWN
                ; Drag the rectangle with the mouse
                _SendMessage($hDrag_GUI, $WM_SYSCOMMAND, 0xF012, 0) ; $SC_DRAGMOVE
            Case $GUI_EVENT_PRIMARYUP
                ; Fire the screen capture
                $aPos = WinGetPos($hDrag_GUI)
                $iX1 = $aPos[0]
                $iY1 = $aPos[1]
                $iX2 = $aPos[0] + $aPos[2]
                $iY2 = $aPos[1] + $aPos[3]
                GUIDelete($hDrag_GUI)
                ExitLoop

        EndSwitch

    WEnd

EndFunc   ;==>Mark_Rect

Is it worth continuing along these lines? What would you like to see changed - other than the double-click firing which I will work on tomorrow? :huh:

M23

Edited by Melba23
Added more explanation

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

In Windows Screenshooter you can select an area on the desktop and move the retangle.

When I find some time I will create a small code extract with the same feature.

Br,

UEZ

ActualAkshay,

I had to change the code to give you an outline rectangle rather than a transparent one - and at the moment you fire the screenshot by releasing the mouse button. You drag the rectangle by dragging the lines themselves - or the little box in the top left corner. See what you think: ;)

#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")

; Create transparent GUI with Cross cursor
$hCross_GUI = GUICreate("Test", @DesktopWidth, @DesktopHeight - 20, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
WinSetTrans($hCross_GUI, "", 8)
GUISetState(@SW_SHOW, $hCross_GUI)
GUISetCursor(3, 1, $hCross_GUI)

Global $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
GUISetBkColor(0x000000)

; 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()

$hMaster_Mask = _WinAPI_CreateRectRgn(0, 0, 0, 0)
$hMask = _WinAPI_CreateRectRgn($iX1, $aMouse_Pos[1], $aMouse_Pos[0], $aMouse_Pos[1] + 1) ; Bottom of rectangle
_WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
_WinAPI_DeleteObject($hMask)
$hMask = _WinAPI_CreateRectRgn($iX1, $iY1, $iX1 + 1, $aMouse_Pos[1]) ; Left of rectangle
_WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
_WinAPI_DeleteObject($hMask)
$hMask = _WinAPI_CreateRectRgn($iX1 + 1, $iY1 + 1, $aMouse_Pos[0], $iY1) ; Top of rectangle
_WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
_WinAPI_DeleteObject($hMask)
$hMask = _WinAPI_CreateRectRgn($aMouse_Pos[0], $iY1, $aMouse_Pos[0] + 1, $aMouse_Pos[1]) ; Right of rectangle
_WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
_WinAPI_DeleteObject($hMask)
; Set overall region
_WinAPI_SetWindowRgn($hRectangle_GUI, $hMaster_Mask)

If WinGetState($hRectangle_GUI) < 15 Then GUISetState()
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)
GUIDelete($hCross_GUI)
DllClose($UserDLL)

; Create a transparent GUI to show an identical rectangle
$hDrag_GUI = GUICreate("", $iX2 - $iX1, $iY2 - $iY1, $iX1, $iY1, $WS_POPUP, BitOr($WS_EX_LAYERED, $WS_EX_TOPMOST))
GUISetBkColor(0xABCDEF)
GUICtrlCreateLabel("", 0, 0, 5, 5)
GUICtrlSetBkColor(-1, 0)
GUICtrlCreateLabel("", 0, 0, $iX2 - $iX1, 1)
GUICtrlSetBkColor(-1, 0)
GUICtrlCreateLabel("", $iX2 - $iX1 - 1, 0, 1, $iY2 - $iY1)
GUICtrlSetBkColor(-1, 0)
GUICtrlCreateLabel("", 0, 0, 1, $iY2 - $iY1)
GUICtrlSetBkColor(-1, 0)
GUICtrlCreateLabel("", 0, $iY2 - $iY1 - 1, $iX2 - $iX1, 1)
GUICtrlSetBkColor(-1, 0)
_WinAPI_SetLayeredWindowAttributes($hDrag_GUI, 0xABCDEF, 250)
GUISetState()

; Allow the mouse up message to register
While GUIGetMsg()
Sleep(10)
WEnd

While 1

Switch GUIGetMsg()
Case $GUI_EVENT_PRIMARYDOWN
; Drag the rectangle with the mouse
_SendMessage($hDrag_GUI, $WM_SYSCOMMAND, 0xF012, 0) ; $SC_DRAGMOVE
Case $GUI_EVENT_PRIMARYUP
; Fire the screen capture
$aPos = WinGetPos($hDrag_GUI)
$iX1 = $aPos[0]
$iY1 = $aPos[1]
$iX2 = $aPos[0] + $aPos[2]
$iY2 = $aPos[1] + $aPos[3]
GUIDelete($hDrag_GUI)
ExitLoop

EndSwitch

WEnd

EndFunc ;==>Mark_Rect

Is it worth continuing along these lines? What would you like to see changed - other than the double-click firing which I will work on tomorrow? :huh:

M23

There's a program called CaptureIt in the forum, i think its by mscreator, its Region Capture is kind of cool, but the only thing that's not cool, the selected area becomes translucent and rest of the area stays transparent, and I don't think there point in making selected area translucent isn't there a way that selected area stays transparent and rest translucent? there's no way to drag it if its transparent? :(

I want it just like select feature in Photoshop hmmm like, you can resize it and move it again and again until you press double click to capture the area, or right click to open a menu (showing various options, such as cancel etc etc etc) OR better is showing a nice good looking floater at bottom or the top of the screen, I was working on all this stuff but couldn't figure out how to make the area drag-able, well lets see if I am able to do the rest on my own :S :S

Thank you, again, for helping me out. :)

Edited by ActualAkshay
Link to comment
Share on other sites

  • Moderators

ActualAkshay,

Another approach. This time you get a draggable, resizeable rectangle with a rightclick context menu to determine the next action: ;)

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

Global $hCapture_GUI
; Set distance from edge of Capture_GUI where resizing is possible
Global Const $iMargin = 4
; Set max and min Capture_GUI sizes
Global Const $iGUIMinX = 50, $iGUIMinY = 50, $iGUIMaxX = @DesktopWidth - 100, $iGUIMaxY = @DesktopHeight - 100

_Main()

Func _Main()

    Local $sBMP_Path = @ScriptDir & "\Rect.bmp"

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

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

    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $hCancel_Button
                FileDelete($sBMP_Path)
                Exit
            Case $hRect_Button
                GUISetState(@SW_HIDE, $hMain_GUI)
                Local $aCoords = Mark_Rect()
                ; Capture selected area
                _ScreenCapture_Capture($sBMP_Path, $aCoords[0], $aCoords[1], $aCoords[0] + $aCoords[2], $aCoords[1] + $aCoords[3], False)
                GUISetState(@SW_SHOW, $hMain_GUI)
                ; Display image
                Local $hBitmap_GUI = GUICreate("Selected Rectangle", $aCoords[2], $aCoords[3], 100, 100)
                Local $hPic = GUICtrlCreatePic(@ScriptDir & "\Rect.bmp", 0, 0, $aCoords[2], $aCoords[3])
                GUISetState()
        EndSwitch
    WEnd

EndFunc   ;==>_Main

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

Func Mark_Rect()

    ; Create capture GUI
    $hCapture_GUI = GUICreate("Y", 100, 100, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    GUISetBkColor(0xABCDEF)

    ; Create label for dragging
    Local $cLabel = GUICtrlCreateLabel("", $iMargin * 2, $iMargin * 2, 100 - ($iMargin * 4), 100 - ($iMargin * 4), -1, $GUI_WS_EX_PARENTDRAG)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)

    ; Create context menu
    Local $cContextMenu = GUICtrlCreateContextMenu($cLabel)
    $cContext_Capture = GUICtrlCreateMenuItem("Capture", $cContextMenu)
    $cContext_Cancel = GUICtrlCreateMenuItem("Cancel", $cContextMenu)

    ; Hide GUI
    _WinAPI_SetLayeredWindowAttributes($hCapture_GUI, 0xABCDEF, 250)

    GUISetState()

    ; Set transparency level
    WinSetTrans($hCapture_GUI, "", 100)

    ; Register message handlers
    GUIRegisterMsg($WM_MOUSEMOVE, "_SetCursor") ; For cursor type change
    GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") ; For resize/drag
    GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO") ; For GUI size limits

    While 1

        Switch GUIGetMsg()
            Case $cContext_Capture
                ; Get GUI position and delete
                $aPos = WinGetPos($hCapture_GUI)
                GUIDelete($hCapture_GUI)
                ; Unregister message handlers
                GUIRegisterMsg($WM_MOUSEMOVE, "")
                GUIRegisterMsg($WM_LBUTTONDOWN, "")
                GUIRegisterMsg($WM_GETMINMAXINFO, "")
                ; Peturn position
                Return $aPos
            Case $cContext_Cancel
                Exit
        EndSwitch
    WEnd

EndFunc   ;==>Mark_Rect

; Set cursor to correct resizing form if mouse is over a border
Func _SetCursor()
    Local $iCursorID
    Switch _Check_Border()
        Case 0
            ConsoleWrite("Hit" & @CRLF)
            $iCursorID = 2
        Case 1, 2
            $iCursorID = 13
        Case 3, 6
            $iCursorID = 11
        Case 5, 7
            $iCursorID = 10
        Case 4, 8
            $iCursorID = 12
    EndSwitch
    GUISetCursor($iCursorID, 1)
EndFunc   ;==>_SetCursor

; Check cursor type and resize/drag window as required
Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    Local $iCursorType = _Check_Border()
    If $iCursorType > 0 Then ; Cursor is set to resizing style so send appropriate resize message
        $iResizeType = 0xF000 + $iCursorType
        _SendMessage($hCapture_GUI, $WM_SYSCOMMAND, $iResizeType, 0)
    EndIf
EndFunc   ;==>_WM_LBUTTONDOWN

; Determines if mouse cursor over a border
Func _Check_Border()
    Local $aCurInfo = GUIGetCursorInfo($hCapture_GUI)
    Local $aWinPos = WinGetPos($hCapture_GUI)
    Local $iSide = 0
    Local $iTopBot = 0
    If $aCurInfo[0] < $iMargin Then $iSide = 1
    If $aCurInfo[0] > $aWinPos[2] - $iMargin Then $iSide = 2
    If $aCurInfo[1] < $iMargin Then $iTopBot = 3
    If $aCurInfo[1] > $aWinPos[3] - $iMargin Then $iTopBot = 6
    Return $iSide + $iTopBot
EndFunc   ;==>_Check_Border

; Set min and max GUI sizes
Func _WM_GETMINMAXINFO($hWnd, $iMsg, $wParam, $lParam)
    $tMinMaxInfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($tMinMaxInfo, 7, $iGUIMinX)
    DllStructSetData($tMinMaxInfo, 8, $iGUIMinY)
    DllStructSetData($tMinMaxInfo, 9, $iGUIMaxX)
    DllStructSetData($tMinMaxInfo, 10, $iGUIMaxY)
    Return 0
EndFunc   ;==>_WM_GETMINMAXINFO

And that is my best (and last) effort so I hope it suits. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

ActualAkshay,

Glad I could help. Do not forget to let us see the end result. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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