Jump to content

LabelClick()


SmOke_N
 Share

Recommended Posts

  • Moderators

I'm sure it's been written before, but this was written for a request in the GUI forum. It uses the same DllCall as the _IsPressed() UDF the $s_hexKey/$st_Text/and the $v_dll are optional parameteres here.

UDF:

Func _LabelClicked($sg_GUI, $sl_Label, $s_hexKey = '01', $st_Text = '', $v_dll = 'user32.dll')
    Local $Opt = Opt('MouseCoordMode', 2)
    Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)
    If Not @Error And BitAND($a_R[0], 0x8000) = 0x8000 Then
        Local $lab_Pos = ControlGetPos($sg_GUI, $st_Text, $sl_Label)
        Local $lab_Mouse = MouseGetPos()
        Opt('MouseCoordMode', $Opt)
        If IsArray($lab_Mouse) And IsArray($lab_Pos) Then
            If $lab_Mouse[0] >= $lab_Pos[0] And $lab_Mouse[0] <= $lab_Pos[0] + $lab_Pos[2] And $lab_Mouse[1] >= $lab_Pos[1] _  
                And $lab_Mouse[1] <= $lab_Pos[1] + $lab_Pos[3] Then Return 1
        EndIf
    EndIf
    Return 0
EndFunc

Sample Test GUI:

#include <guiconstants.au3>
Opt("MouseCoordMode", 0)

$Main = GUICreate("MyGui", 200, 100)
$MyLabel = GUICtrlCreateLabel("This Label", 10, 20, 100, 25)

GUISetState()
While 1
    $imsg = GUIGetMsg()
    Select
        Case $imsg = -3
            Exit
        Case _LabelClicked($Main, $MyLabel)
            MsgBox(48, "Yes", "It was Your Label!")
    EndSelect
WEnd

Edit:

Changed from _LabelClick() (Might be misinterpreted) to _LabelClicked() ... If a Moderator could change the title to _LabelClicked() would be great!!

Edit2:

Added suggestion from LxP :P Thanks again!

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You can also do this so as not to affect the main script's MouseCoordMode setting:

Func _LabelClicked(...)
    ···
    Local $Opt = Opt('MouseCoordMode', 2)
    Local $lab_Mouse = MouseGetPos()
    Opt('MouseCoordMode', $Opt)
    ···
EndFunc
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...