Sign in to follow this  
Followers 0
unknown12

Clickable Label

10 posts in this topic

I know I can make something happen when I click on a image, but is there anyway to make something happen when I click on a label?

Thanks.

Share this post


Link to post
Share on other sites



#include <guiconstants.au3>
Opt("MouseCoordMode", 2)
Dim $left = 10
Dim $top = 20
Dim $width = 100
Dim $height = 25
Dim $Mouse

$Main = GUICreate("MyGui", 200, 100)
$label = GUICtrlCreateLabel("This Label", $left, $top, $width, $height)

GUISetState()
While 1
    $imsg = GUIGetMsg()
    Select
        Case $imsg = $GUI_EVENT_CLOSE
            Exit
        Case _IsPressed('01')
            $Mouse = MouseGetPos()
            If IsArray($Mouse) Then
                If $Mouse[0] >= $left And $Mouse[0] <= $left + $width And $Mouse[1] >= $top And $Mouse[1] <= $top + $height Then
                MsgBox(48, "Label", "You Clicked The Label")
                EndIf
            EndIf
    EndSelect
WEnd
    
Func _IsPressed($s_hexKey, $v_dll = 'user32.dll')
    Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc


[center]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.[/center]

Share this post


Link to post
Share on other sites

Is there anyway that could be made into a UDF?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I'm sure... did you try to?

Edit:

Oh and your welcome...

Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

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

GUISetState()
While 1
    $imsg = GUIGetMsg()
    Select
        Case $imsg = $GUI_EVENT_CLOSE
            Exit
        Case _IsPressed('01')
            If _LabelClick($Main, "", $MyLabel) = 1 Then MsgBox(48, "Yes", "It was Your Label!")
    EndSelect
WEnd

Func _LabelClick($GUI, $Text, $Label)
    Local $Pos = ControlGetPos($GUI, $Text, $Label)
    Local $Mouse = MouseGetPos()
    If IsArray($Mouse) And IsArray($Pos) Then
        If $Mouse[0] >= $Pos[0] And $Mouse[0] <= $Pos[0] + $Pos[2] And $Mouse[1] >= $Pos[1] And $Mouse[1] <= $Pos[1] + $Pos[3] Then
            Return 1
        EndIf
    EndIf
    Return 0
EndFunc

Func _IsPressed($s_hexKey, $v_dll = 'user32.dll')
    Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc

Edit:

Just updated the UDF a bit...

Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

Thanks SmOke_N :P

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Here... This makes it all one UDF rather than having to have _IsPressed() there too... I just mixed the 2.

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

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

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

Func _LabelClick($sg_GUI, $sl_Label, $s_hexKey = '01', $st_Text = '', $v_dll = 'user32.dll')
    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()
        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

Edit:

Made the $s_hexKey / $Text / $v_dll all optional parameters, now all you have to do is enter Main GUI Variable name and Label to Check Variable Name in.

Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

Thanks!

Share this post


Link to post
Share on other sites

I revised this a bit more and stuck in in the scripts and scraps forum if your interested: http://www.autoitscript.com/forum/index.ph...ndpost&p=136123


[center]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.[/center]

Share this post


Link to post
Share on other sites

;~ I use clickable labels often like this.

#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

$gui=GuiCreate("Task Drawer", "150", "150", "150", "150", $WS_POPUP, $WS_EX_TOPMOST)

GUISetBkColor (0x660000)

$lbl = GUICtrlCreateLabel("Label", 3, 0, "150", 20, $SS_CENTER, $SS_NOTIFY)

GUICtrlSetBkColor ( $lbl, 0x3399CC )

GUICtrlSetColor ( $lbl, 0x660000)

GUICtrlSetTip($lbl, "Click here to exit" )

GUICtrlSetOnEvent($lbl, "bye")

GuiSetState()

While 1

Sleep(10)

WEnd

Func bye()

Exit

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  
Followers 0