Jump to content

how to highligh a control boundary


hobli
 Share

Recommended Posts

Hi, all,

I would like to do a simple script function, like:

func showCtrlBoundary($controlHandle, $colorRGB)

;draw a square box with color of $colorRGB around the region occupied by the control $controlHandle

endfunc

Has anybody has any idea?

I have some idea about drawing lines on screen with gdi32.dll calls, but have no idea how to erase those lines afterwards.

thanks a lot

Link to comment
Share on other sites

  • Moderators

hobli,

You could use labels - but be sure to disable them! :D

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 100, 100)
GUISetBkColor(0xC4C4C4)

$hLabel = GUICtrlCreateLabel("", 8, 8, 84, 34)
GUICtrlSetBkColor(-1, 0xC4C4C4)
GUICtrlSetState(-1, $GUI_DISABLE)
$hButton = GUICtrlCreateButton("Toggle", 10, 10, 80, 30)

GUISetState()

$fLit = False

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            Switch $fLit
                Case True
                    $fLit = False
                    GUICtrlSetBkColor($hLabel, 0xC4C4C4)
                Case False
                    $fLit = True
                    GUICtrlSetBkColor($hLabel, 0xFFFF00)
            EndSwitch
    EndSwitch

WEnd

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

Hi, Melba23,

Thanks for your sample code. My intention is to draw/highlight contour around a control on any other windows applications.

E.g, I would like to highlight the boundary of a button in the window calculator GUI.

What I can do now is to draw any lines on screen/or other appl's gui, but I am not able to erase the drawing, unless I manually refresh the screen/relevant gui.

Pls look at the screen shot attached. thanks.

post-39511-12543230219913_thumb.png

Link to comment
Share on other sites

  • Moderators

hobli,

Sorry, I did not realise you meant 3rd party apps! Take a look at this - not quite what you want , but it might give you some ideas on what you might need to look at next:

; credit MrCreator and martin

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

Opt("GuiOnEventMode", 1)
HotKeySet("{ESC}", "QuitApp")

If Not IsDeclared("WM_WINDOWPOSCHANGED") Then Assign("WM_WINDOWPOSCHANGED",0x0047)
Global $ahGUI[4]
Global $Last_hControl = -1

Global $Frame_Color = 0xff0000;0xFF0000
Global $Frame_Width = 2
Global $hCtrl
$Main_GUI = GuiCreate("Highlight Controls Demo")
GUISetOnEvent($GUI_EVENT_CLOSE, "QuitApp")
GUIRegisterMsg($WM_WINDOWPOSCHANGED, "WM_WINDOWPOSCHANGED")


GUICtrlCreateButton("Button", 20, 20)
GUICtrlCreateCheckbox("CheckBox", 20, 60)
GUICtrlCreateEdit("", 120, 60, 240, 150)


GUICtrlCreateLabel("Info: ", 20, 250)
GUICtrlSetFont(-1, 9, 800)
$Info_Label = GUICtrlCreateLabel("", 120, 270, 250, 80)

GUISetState()

While 1
    Sleep(100)

    $hCtrl = _ControlGetHovered()

    If $hCtrl <> 0 And $Last_hControl <> $hCtrl And Not IsHighLight_GUIs($hCtrl) Then
        if not _IsPressed("1") Then
            $Last_hControl = $hCtrl
            $aCtrlPos = WinGetPos($hCtrl)

            GUICtrlSetData($Info_Label, _
                    "X = " & $aCtrlPos[0] & @CRLF & _
                    "Y = " & $aCtrlPos[1] & @CRLF & _
                    "W = " & $aCtrlPos[2] & @CRLF & _
                    "H = " & $aCtrlPos[3] & @CRLF & _
                    "Control Data = " & ControlGetText($hCtrl, "", ""))

            GUISquareDelete()
            GUICreateSquare($aCtrlPos[0], $aCtrlPos[1], $aCtrlPos[2], $aCtrlPos[3])
        EndIf
    Else
        $aNewCtrlPos = WinGetPos($hCtrl)
        for $n = 0 to 3
            if $aCtrlPos[$n] <> $aNewCtrlPos[$n] Then
                GUISquareDelete()
                $hCtrl = 0
                $Last_hControl = 0
                ExitLoop
            EndIf
        Next
    EndIf
WEnd

Func GUICreateSquare($X, $Y, $W, $H)
    $X -= $Frame_Width
    $Y -= $Frame_Width
    $W += $Frame_Width
    $H += $Frame_Width
    $ahGUI[0] = GUICreate("", $W, $Frame_Width, $X, $Y, $WS_POPUP, $WS_EX_TOPMOST+$WS_EX_TOOLWINDOW)
    GUISetBkColor($Frame_Color)

    $ahGUI[1] = GUICreate("", $Frame_Width, $H, $X, $Y, $WS_POPUP, $WS_EX_TOPMOST+$WS_EX_TOOLWINDOW)
    GUISetBkColor($Frame_Color)

    $ahGUI[2] = GUICreate("", $Frame_Width, $H, $X+$W, $Y, $WS_POPUP, $WS_EX_TOPMOST+$WS_EX_TOOLWINDOW)
    GUISetBkColor($Frame_Color)

    $ahGUI[3] = GUICreate("", $W+$Frame_Width, $Frame_Width, $X, $Y+$H, $WS_POPUP, $WS_EX_TOPMOST+$WS_EX_TOOLWINDOW)
    GUISetBkColor($Frame_Color)

    For $i = 0 To 3
        GUISetState(@SW_SHOW, $ahGUI[$i])
    Next
EndFunc

Func GUISquareDelete()
    For $i = 0 To 3
        If IsHWnd($ahGUI[$i]) And $ahGUI[$i] <> $Main_GUI Then GUIDelete($ahGUI[$i])
    Next

    $ahGUI = ""
    Dim $ahGUI[4]
EndFunc

Func IsHighLight_GUIs($hCtrl)
    For $i = 0 To 3
        If $ahGUI[$i] = $hCtrl Then Return True
    Next
    Return False
EndFunc

Func _ControlGetHovered()
    Local $aRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
    If Not IsArray($aRet) Then Return SetError(1, 0, 0)
    Return HWnd($aRet[0])
EndFunc


Func WM_WINDOWPOSCHANGED($hWndGUI, $MsgID, $WParam, $LParam)
    If $hWndGUI = $Main_GUI or $hWndGUI = $hCtrl Then
        GUISquareDelete()
        $Last_hControl = -1
    Else
        Return $GUI_RUNDEFMSG
    EndIf
EndFunc

Func QuitApp()
    Exit
EndFunc

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