Jump to content
Sign in to follow this  
SmOke_N

LabelClick()

Recommended Posts

SmOke_N

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.

Share this post


Link to post
Share on other sites
LxP

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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.