picea892 Posted May 25, 2009 Posted May 25, 2009 Hi The below script is cut and paste from help. The help indicates that "@GUI_CTRLID would equal $okbutton", however if you put @GUI_CTRLID in messagebox it returns 4. It is a unique number to the control but less intuitive then a controlId would be. How would I get $okbutton in onevent mode? Could an alternative be to use @GUI_CTRLHANDLE somehow? #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode $mainwindow = GUICreate("Hello World", 200, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUICtrlCreateLabel("Hello world! How are you?", 30, 10) $okbutton = GUICtrlCreateButton("OK", 70, 50, 60) GUICtrlSetOnEvent($okbutton, "OKButton") GUISetState(@SW_SHOW) While 1 Sleep(1000) ; Idle around WEnd Func OKButton() ;Note: at this point @GUI_CTRLID would equal $okbutton, ;and @GUI_WINHANDLE would equal $mainwindow MsgBox(0, "GUI Event", "You pressed OK!") EndFunc Func CLOSEClicked() ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, ;and @GUI_WINHANDLE would equal $mainwindow MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...") Exit EndFunc
AdmiralAlkex Posted May 25, 2009 Posted May 25, 2009 I don't get the problem.How would I get $okbutton in onevent mode?$okbutton and @GUI_CTRLID returns the same value so it shouldn't matter. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
picea892 Posted May 25, 2009 Author Posted May 25, 2009 I don't get the problem.$okbutton and @GUI_CTRLID returns the same value so it shouldn't matter.You're right there are work arounds.1) I can keep track of the guictrl creation order and relate it to the @GUI_CTRLID #2) I can record the guictrl handle upon creation using Guictrlgethandle and compare it to the @GUI_CTRLHANDLESure there alternate ways.I'm just wondering why @GUI_CTRLID returns a number instead of $okbutton....which is what the helpfile says should be returned...or am I reading the helpfile wrong?
Moderators Melba23 Posted May 25, 2009 Moderators Posted May 25, 2009 picea892,@GUI_CTRLID does not return the literal string "$okbutton", it returns the value of the variable $okbutton. Try running this:#include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1); Change to OnEvent mode $mainwindow = GUICreate("Hello World", 200, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUICtrlCreateLabel("Hello world! How are you?", 30, 10) $okbutton = GUICtrlCreateButton("OK", 70, 50, 60) GUICtrlSetOnEvent($okbutton, "OKButton") GUISetState(@SW_SHOW) While 1 Sleep(1000); Idle around WEnd Func OKButton() ;Note: at this point @GUI_CTRLID would equal $okbutton, ;and @GUI_WINHANDLE would equal $mainwindow MsgBox(0, "GUI Event", "You pressed OK!" & @CRLF & "$okbutton = " & $okbutton & @CRLF & "@GUI_CTRLID = " & @GUI_CTRLID );<<<< Should give you the answer! EndFunc Func CLOSEClicked() ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, ;and @GUI_WINHANDLE would equal $mainwindow MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...") Exit EndFuncSo there is no need to use either of your work arounds - as long as you use a variable to store the ControlID when the control is created, you always have the correct value to hand.M23 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
picea892 Posted May 25, 2009 Author Posted May 25, 2009 Wow....How many times I have used $msg = GUIGetMsg() and never understood how it worked. This is the same thing.....only in on-event mode. I'm feeling a little sheepish right now. I'm really sorry for this basic question and I really appreciate the time you two took to set me straight. On-event mode is quite slick, I think I'm sold on using it.
Moderators Melba23 Posted May 25, 2009 Moderators Posted May 25, 2009 picea892,Delighted to have been of help!There are good reasons to use both GUI modes - a lot depends on what you are trying to do. However, MessageLoop does allow parameters to be passed to the functions - you have to use martin's UDF to do the same with OnEvent.So pick the one which works best for the script you are writing - and always remember that with Opt("GUIOnEventMode") you can use both modes in the same script, just not at the same time! ;-)M23 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
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