Jump to content

Highlight


oMBRa
 Share

Recommended Posts

oMBra

Example:

#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>

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

Global $LastHwnd = 0

_GDIPlus_Startup()

While 1
    $hWnd = _ControlGetHovered()
    If $hWnd Then FrameRect($hWnd)
    Sleep(10)
WEnd

Func _ControlGetHovered()
    Local $aRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
    If ($aRet[0] <> 0) And ($aRet[0] <> $LastHwnd) Then
        _WinAPI_RedrawWindow($LastHwnd, 0, 0, $RDW_INVALIDATE)
        $LastHwnd = $aRet[0]
        Return HWnd($aRet[0])
    EndIf
EndFunc

Func FrameRect($hWnd)
    Local $hGraphic, $hPen, $iWidth, $iHeight
    
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hPen = _GDIPlus_PenCreate(0xA1FF0000, 6)
    
    $iWidth = _WinAPI_GetClientWidth($hWnd)
    $iHeight = _WinAPI_GetClientHeight($hWnd)
    
    _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $iWidth, $iHeight, $hPen)
    
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_PenDispose($hPen)
EndFunc

Func _Exit()
    _WinAPI_RedrawWindow($LastHwnd, 0, 0, $RDW_INVALIDATE)
    _GDIPlus_Shutdown()
    Exit
EndFuncoÝ÷ ØLZ^&lÊ­歡Ûjëh×6#include <GuiConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

Opt("GuiOnEventMode", 1)

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

Global $hSquare_GUI     = -1
Global $hCtrl           = -1
Global $Last_hControl   = -1

Global $Frame_Color     = 0xFF0000
Global $Frame_Width     = 3

$Main_GUI = GuiCreate("Highlight Controls Demo")

GUISetOnEvent($GUI_EVENT_CLOSE, "QuitApp")
GUIRegisterMsg($WM_WINDOWPOSCHANGED, "WM_WINDOWPOSCHANGED")

GUICtrlCreateButton("Button", 20, 20)
GUICtrlCreateCheckbox("CheckBox", 20, 60)

GUICtrlCreateLabel("Info: ", 20, 150)
GUICtrlSetFont(-1, 9, 800)

$Info_Edit = GUICtrlCreateEdit("", 80, 150, 300, 220, $GUI_SS_DEFAULT_EDIT+$ES_READONLY)

GUISetState()

While 1
    Sleep(10) ;So the CPU will not increes "badly" while we play with the mouse cursor :)
    _IdleWait()

    If _IsPressed(1) Then
        GUIDeleteSquare($hSquare_GUI)
        While _IsPressed(1)
            Sleep(10)
            Check_Highlight_Controls_Proc()
        WEnd
        $Last_hControl = -1
    EndIf

    Check_Highlight_Controls_Proc()
WEnd

Func Check_Highlight_Controls_Proc()
    Local $hCtrl = _ControlGetHovered()

    If $hCtrl <> 0 And $Last_hControl <> $hCtrl And $hSquare_GUI <> $hCtrl Then
        $Last_hControl = $hCtrl
        Local $aCtrlPos = WinGetPos($hCtrl)

        GUICtrlSetData($Info_Edit, _
            "X = " & $aCtrlPos[0] & @CRLF & _
            "Y = " & $aCtrlPos[1] & @CRLF & _
            "W = " & $aCtrlPos[2] & @CRLF & _
            "H = " & $aCtrlPos[3] & @CRLF & @CRLF & _
            "Control/Win Class Name: " & _WinGetClassName($hCtrl) & @CRLF & _
            "Control/Win Handle: " & $hCtrl & @CRLF & _
            "Control ID: " & _HwndToID($hCtrl) & @CRLF & @CRLF & _
            "Control Data:" & @CRLF & ControlGetText($hCtrl, "", ""))

        GUIDeleteSquare($hSquare_GUI)
        $hSquare_GUI = GUICreateSquare($aCtrlPos[0], $aCtrlPos[1], $aCtrlPos[2], $aCtrlPos[3])
    EndIf
EndFunc

Func GUICreateSquare($i_X=-1, $i_Y=-1, $i_W=-1, $i_H=-1)
    Local $hSquare_GUI = GUICreate("", $i_W, $i_H, $i_X, $i_Y, $WS_POPUP, $WS_EX_TOOLWINDOW+$WS_EX_TOPMOST)
    GUISetBkColor($Frame_Color)

    _GUISetHole($hSquare_GUI, $Frame_Width, $Frame_Width, $i_W - ($Frame_Width * 2), $i_H - ($Frame_Width * 2))

    GUISetState(@SW_SHOWNOACTIVATE, $hSquare_GUI)

    Return $hSquare_GUI
EndFunc

Func GUIDeleteSquare($hSquare_GUI)
    If IsHWnd($hSquare_GUI) And $hSquare_GUI <> $Main_GUI Then GUIDelete($hSquare_GUI)
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 _HwndToID($hWnd)
    If Not IsHWnd($hWnd) Then Return SetError(1, 0, "")

    Local $aRet = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hWnd)
    If Not IsArray($aRet) Then Return SetError(2, 0, "")

    Return $aRet[0]
EndFunc

Func _WinGetClassName($hWnd)
    $aClassName = DLLCall("user32.dll", "int", "GetClassName", "hWnd", $hWnd, "str", "", "int", 64)
    If Not @error And $aClassName[0] <> 0 Then Return $aClassName[2]
    Return ""
EndFunc

Func _GUISetHole($hWin, $i_X, $i_Y, $i_SizeW, $i_SizeH)
    Local $aWinPos, $Outer_Rgn, $Inner_Rgn, $Wh, $Combined_Rgn
    Local Const $RGN_DIFF = 4
    $aWinPos = WinGetPos($hWin)

    $Outer_Rgn = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", $aWinPos[2], "long", $aWinPos[3])
    $Inner_Rgn = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", $i_Y, "long", $i_Y, "long", $i_Y + $i_SizeW, _
            "long", $i_Y + $i_SizeH)
    $Combined_Rgn = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 0, "long", 0)
    DllCall("gdi32.dll", "long", "CombineRgn", "long", $Combined_Rgn[0], "long", $Outer_Rgn[0], "long", $Inner_Rgn[0], _
            "int", $RGN_DIFF)
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $hWin, "long", $Combined_Rgn[0], "int", 1)
EndFunc

Func _IdleWait($IdleSec=0)
    Local $iSave, $stLastInput = DllStructCreate("uint;dword")
    DllStructSetData($stLastInput, 1, DllStructGetSize($stLastInput))
    DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($stLastInput))
    Do
        $iSave = DllStructGetData($stLastInput, 2)
        Sleep(20)
        DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($stLastInput))
    Until (DllStructGetData($stLastInput, 2) - $iSave) > $IdleSec
    Return DllStructGetData($stLastInput, 2) - $iSave
EndFunc

Func WM_WINDOWPOSCHANGED($hWndGUI, $MsgID, $WParam, $LParam)
    If $hWndGUI <> $Main_GUI Then Return $GUI_RUNDEFMSG
    GUIDeleteSquare($hSquare_GUI)
    Check_Highlight_Controls_Proc()
    $Last_hControl = -1
EndFunc

Func QuitApp()
    Exit
EndFunc

Also see here

;)

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