Sign in to follow this  
Followers 0
plastix

Region Selection with Highlight Mod

3 posts in this topic

I found with interest a topic regarding transparency and region selection for screen capture. The examples included are excellent (HERE). In particular, Melba23's highlighted method was cool - I was trying this out on a number of desktops with dark/black backgrounds. Ss such, the selection area is a little hard to see / the highlight effect is lost a little. i tried to merge elements from the example with a rectangle around the selection area and entered flicker hell... I don't understand any of the WinAPI calls... Is it possible to draw a coloured / white rectangle around the selection area ?

TIA :mellow:

Share this post


Link to post
Share on other sites



plastix,

I was wondering when you would show up after the other topic was locked. :mellow:

Flattery will get you almost everything.: :lol:

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

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

; 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
            Exit
        Case $hRect_Button
            GUISetState(@SW_HIDE, $hMain_GUI)
            Mark_Rect()
            Exit
    EndSwitch

WEnd

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

Func Mark_Rect()

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

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

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

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

        _GUIDrawRect($hRectangle_GUI, $iX1, $iY1, $aMouse_Pos[0],  $aMouse_Pos[1])

        If WinGetState($hRectangle_GUI) < 15 Then GUISetState()

        ; 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($hHole_GUI, $iX_Pos + 1, $iY_Pos + 1, $iWidth - 1, $iHeight - 1)

        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($hHole_GUI)
    DllClose($UserDLL)

EndFunc   ;==>Mark_Rect

Func _GUIDrawRect($hWnd, $iX1, $iY1, $iX2, $iY2)

    $hMaster_Mask = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    $hMask = _WinAPI_CreateRectRgn($iX1, $iY2, $iX2,  $iY2 + 1) ; Bottom of rectangle
    _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
    _WinAPI_DeleteObject($hMask)
    $hMask = _WinAPI_CreateRectRgn($iX1, $iY1, $iX1 + 1, $iY2) ; Left of rectangle
    _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
    _WinAPI_DeleteObject($hMask)
    $hMask = _WinAPI_CreateRectRgn($iX1 + 1, $iY1 + 1, $iX2, $iY1) ; Top of rectangle
    _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
    _WinAPI_DeleteObject($hMask)
    $hMask = _WinAPI_CreateRectRgn($iX2, $iY1, $iX2 + 1, $iY2) ; Right of rectangle
    _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
    _WinAPI_DeleteObject($hMask)
    ; Set overall region
    _WinAPI_SetWindowRgn($hWnd, $hMaster_Mask)

EndFunc

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

If you want to change the colour of the outline, then you need to alter the <<<<<<<<<< line:

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

I hope this does what you want. :(

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

perfect. thanks :(

(actually, i didn't notice the post was locked till few hours ago :mellow:)

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