Jump to content

Clickable Label


unknown12
 Share

Recommended Posts

  • Moderators

#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

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

  • Moderators

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

Edit:

Oh and your welcome...

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

  • Moderators

#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

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

  • Moderators

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

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

  • Moderators

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

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

;~ 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

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