unknown12 Posted January 1, 2006 Posted January 1, 2006 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.
Moderators SmOke_N Posted January 1, 2006 Moderators Posted January 1, 2006 #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.
unknown12 Posted January 1, 2006 Author Posted January 1, 2006 Is there anyway that could be made into a UDF?
Moderators SmOke_N Posted January 1, 2006 Moderators Posted January 1, 2006 (edited) I'm sure... did you try to? Edit: Oh and your welcome... Edited January 1, 2006 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.
Moderators SmOke_N Posted January 1, 2006 Moderators Posted January 1, 2006 (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 January 1, 2006 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.
Moderators SmOke_N Posted January 1, 2006 Moderators Posted January 1, 2006 (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 January 1, 2006 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.
Moderators SmOke_N Posted January 2, 2006 Moderators Posted January 2, 2006 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.
John Posted January 9, 2006 Posted January 9, 2006 ;~ 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now