hobli Posted September 29, 2009 Share Posted September 29, 2009 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 More sharing options...
Moderators Melba23 Posted September 29, 2009 Moderators Share Posted September 29, 2009 hobli, You could use labels - but be sure to disable them! #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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
hobli Posted September 30, 2009 Author Share Posted September 30, 2009 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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 30, 2009 Moderators Share Posted September 30, 2009 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: expandcollapse popup; 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
hobli Posted October 1, 2009 Author Share Posted October 1, 2009 Hi, Melba23, Excellent! it's very clever way of achieving this. thx Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now