JohnOne Posted February 1, 2011 Share Posted February 1, 2011 (edited) Hi all, wondering if there is a way to dertermine which control triggered a function, when multiple controls trip just a single function. I have some code which is repetative you see, with just one paramater different. In the case of the code below "Red" and "Green". So I'm looking for a way to have the data in the label set according to the button which is pressed. I'm certain I've seen this on the forums, except I cannot find it with my search. Sorry anoy the gui, I just made it quickly with koda, but it was my hope that GUIGetMsg() would work in some way. Any pointers appreciated. Sample code. #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 233, 131, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") $Button1 = GUICtrlCreateButton("Red", 32, 16, 75, 25, $WS_GROUP) GUICtrlSetOnEvent($Button1, "Buttonclick") $Button2 = GUICtrlCreateButton("Green", 128, 16, 75, 25, $WS_GROUP) GUICtrlSetOnEvent($Button2, "Buttonclick") $Label1 = GUICtrlCreateLabel("", 68, 56, 92, 20) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func Buttonclick() Local $str = "" $msg = GUIGetMsg(1) Switch $msg[0] Case $Button1 $str = "Red" Case $Button2 $str = "Green" EndSwitch GUICtrlSetData($Label1,$str) EndFunc ;==>Buttonclick Func Form1Close() Exit EndFunc ;==>Form1Close I know I could do something like this expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 233, 131, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") $Button1 = GUICtrlCreateButton("Red", 32, 16, 75, 25, $WS_GROUP) GUICtrlSetOnEvent($Button1, "Button1Click") $Button2 = GUICtrlCreateButton("Green", 128, 16, 75, 25, $WS_GROUP) GUICtrlSetOnEvent($Button2, "Button2Click") $Label1 = GUICtrlCreateLabel("", 68, 56, 92, 20) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func Button1Click() $str = "Red" _Function($str) EndFunc Func Button2Click() $str = "Green" _Function($str) EndFunc Func _Function($str) GUICtrlSetData($Label1,$str) EndFunc ;==>Buttonclick Func Form1Close() Exit EndFunc ;==>Form1Close But I could do without all the functions, as there may be a lot of them. Plus, I'm curious to know. Edited February 1, 2011 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 1, 2011 Moderators Share Posted February 1, 2011 JohnOne,Mixing OnEvent and MessageLoop modes.... There is a nice macro in OnEvent mode which does just what you want: Func Buttonclick() Local $str = "" Switch @GUI_CtrlId ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Case $Button1 $str = "Red" Case $Button2 $str = "Green" EndSwitch GUICtrlSetData($Label1,$str) EndFunc ;==>ButtonclickM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JohnOne Posted February 1, 2011 Author Share Posted February 1, 2011 Thats the fella, thank you sire. Always forget to think about those handy macros. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
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