Rogue5099 Posted April 22, 2012 Share Posted April 22, 2012 I have a GUI that has several Menu Items but it uses the same function with a different parameter. Without converting script to OnEvent is there a way to read the Menu Item clicked and use that as a parameter? expandcollapse popup$HardwareMenu = GUICtrlCreateMenu("Information") $AboutCPU = GUICtrlCreateMenuItem("Processor", $HardwareMenu) $AboutRAM = GUICtrlCreateMenuItem("RAM (Memory)", $HardwareMenu) $AboutHDD = GUICtrlCreateMenuItem("Hard Drive", $HardwareMenu) $AboutMotherboard = GUICtrlCreateMenuItem("Motherboard", $HardwareMenu) $AboutGraphics = GUICtrlCreateMenuItem("Graphics Card", $HardwareMenu) $AboutSoundCard = GUICtrlCreateMenuItem("Sound Card", $HardwareMenu) $AboutNetwork = GUICtrlCreateMenuItem("Network", $HardwareMenu) GUICtrlCreateMenuItem("", $HardwareMenu) $AboutOS = GUICtrlCreateMenuItem("Operating System", $HardwareMenu) $AboutBios = GUICtrlCreateMenuItem("BIOS", $HardwareMenu) $AboutSystem = GUICtrlCreateMenuItem("System", $HardwareMenu) GUICtrlCreateMenuItem("", $HardwareMenu) $AboutBattery = GUICtrlCreateMenuItem("Battery", $HardwareMenu) $AboutMonitor = GUICtrlCreateMenuItem("Monitor", $HardwareMenu) $AboutKeyboard = GUICtrlCreateMenuItem("Keyboard", $HardwareMenu) $AboutMouse = GUICtrlCreateMenuItem("Mouse", $HardwareMenu) Switch Case $AboutBattery HardwareGUI("Battery") Case $AboutBios HardwareGUI("BIOS") Case $AboutKeyboard HardwareGUI("Keyboard") Case $AboutRAM HardwareGUI("RAM") Case $AboutHDD HardwareGUI("HDDInfo") Case $AboutMonitor HardwareGUI("Monitor") Case $AboutMotherboard HardwareGUI("Motherboard") Case $AboutMouse HardwareGUI("Mouse") Case $AboutNetwork HardwareGUI("Network") Case $AboutSystem HardwareGUI("System") Case $AboutCPU HardwareGUI("CPU") Case $AboutSoundCard HardwareGUI("SoundCard") Case $AboutGraphics HardwareGUI("GraphicsCard") Case $AboutOS HardwareGUI("OS") EndSwitch But I would like to change it to something like this: Switch @GUI_CtrlID Case 11 To 24 HardwareGUI(@GUI_CtrlHandle) EndSwitch My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 22, 2012 Moderators Share Posted April 22, 2012 Rogue5099,I would do it like this: #include <GUIConstantsEx.au3> Global $aMenu[4] = ["Processor", "RAM", "Hard Drive", "Motherboard"] $hGUI = GUICreate("Test", 500, 500) $HardwareMenu = GUICtrlCreateMenu("Information") $AboutCPU = GUICtrlCreateMenuItem("Processor", $HardwareMenu) $AboutRAM = GUICtrlCreateMenuItem("RAM (Memory)", $HardwareMenu) $AboutHDD = GUICtrlCreateMenuItem("Hard Drive", $HardwareMenu) $AboutMotherboard = GUICtrlCreateMenuItem("Motherboard", $HardwareMenu) GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $AboutCPU To $AboutMotherboard MsgBox(0, "You actioned", $aMenu[$iMsg - $AboutCPU]) EndSwitch WEndBut you must make sure that you create all the menu items in immediate succession or the trick does not work. 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 Link to comment Share on other sites More sharing options...
Rogue5099 Posted April 22, 2012 Author Share Posted April 22, 2012 But you must make sure that you create all the menu items in immediate succession or the trick does not workLooks like I got a lot of rearranging to to thanks again! My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
PhoenixXL Posted April 22, 2012 Share Posted April 22, 2012 Hey Rogue5099!!! I tried my Best to help You Out But I didnt got Very Successful Results............ You can Make a Compromise and Set the Text for the Function You want to Execute as If you Dont get it Look at the COde!! expandcollapse popup#include-once #include <WindowsConstants.au3> #include <GUIConstantsEX.au3> GUICreate('') $HardwareMenu = GUICtrlCreateMenu("Information") $AboutCPU = GUICtrlCreateMenuItem("Processor", $HardwareMenu) $AboutRAM = GUICtrlCreateMenuItem("RAM (Memory)", $HardwareMenu) $AboutHDD = GUICtrlCreateMenuItem("Hard Drive", $HardwareMenu) $AboutMotherboard = GUICtrlCreateMenuItem("Motherboard", $HardwareMenu) $AboutGraphics = GUICtrlCreateMenuItem("Graphics Card", $HardwareMenu) $AboutSoundCard = GUICtrlCreateMenuItem("Sound Card", $HardwareMenu) $AboutNetwork = GUICtrlCreateMenuItem("Network", $HardwareMenu) GUICtrlCreateMenuItem("", $HardwareMenu) $AboutOS = GUICtrlCreateMenuItem("Operating System", $HardwareMenu) $AboutBios = GUICtrlCreateMenuItem("BIOS", $HardwareMenu) $AboutSystem = GUICtrlCreateMenuItem("System", $HardwareMenu) GUICtrlCreateMenuItem("", $HardwareMenu) $AboutBattery = GUICtrlCreateMenuItem("Battery", $HardwareMenu) $AboutMonitor = GUICtrlCreateMenuItem("Monitor", $HardwareMenu) $AboutKeyboard = GUICtrlCreateMenuItem("Keyboard", $HardwareMenu) $AboutMouse = GUICtrlCreateMenuItem("Mouse", $HardwareMenu) Global $About[14]=[$AboutCPU,$AboutRAM, $AboutHDD,$AboutMotherboard,$AboutGraphics,$AboutSoundCard,$AboutNetwork,$AboutOS,$AboutBios,$AboutSystem ,$AboutBattery,$AboutMonitor,$AboutKeyboard,$AboutMouse] GUISetState() Global $nMsg While $nMsg<>$GUI_EVENT_CLOSE $nMsg=GUIGetMsg() For $l=0 To 13 Switch $nMsg Case $About[$l] HardwareGUI(_getText($About[$l])) EndSwitch Next WEnd Func HardwareGUI($x) Return ConsoleWrite($x&@CRLF) EndFunc Func _getText($hWnd) Return GUICtrlRead($hWnd,1) EndFunc My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 22, 2012 Moderators Share Posted April 22, 2012 PhoenixXL, That is very clever. But could I offer this slightly changed version: #include <WindowsConstants.au3> #include <GUIConstantsEX.au3> GUICreate('') $HardwareMenu = GUICtrlCreateMenu("Information") $AboutCPU = GUICtrlCreateMenuItem("Processor", $HardwareMenu) $AboutRAM = GUICtrlCreateMenuItem("RAM (Memory)", $HardwareMenu) $AboutHDD = GUICtrlCreateMenuItem("Hard Drive", $HardwareMenu) $AboutMotherboard = GUICtrlCreateMenuItem("Motherboard", $HardwareMenu) $AboutGraphics = GUICtrlCreateMenuItem("Graphics Card", $HardwareMenu) $AboutSoundCard = GUICtrlCreateMenuItem("Sound Card", $HardwareMenu) $AboutNetwork = GUICtrlCreateMenuItem("Network", $HardwareMenu) GUICtrlCreateMenuItem("", $HardwareMenu) $AboutOS = GUICtrlCreateMenuItem("Operating System", $HardwareMenu) $AboutBios = GUICtrlCreateMenuItem("BIOS", $HardwareMenu) $AboutSystem = GUICtrlCreateMenuItem("System", $HardwareMenu) GUICtrlCreateMenuItem("", $HardwareMenu) $AboutBattery = GUICtrlCreateMenuItem("Battery", $HardwareMenu) $AboutMonitor = GUICtrlCreateMenuItem("Monitor", $HardwareMenu) $AboutKeyboard = GUICtrlCreateMenuItem("Keyboard", $HardwareMenu) $AboutMouse = GUICtrlCreateMenuItem("Mouse", $HardwareMenu) GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $AboutCPU To $AboutMouse MsgBox(0, "You actioned", GUICtrlRead($iMsg, 1)) EndSwitch WEnd Now you do not need the array. 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 Link to comment Share on other sites More sharing options...
Rogue5099 Posted April 22, 2012 Author Share Posted April 22, 2012 (edited) The array did mess up once it got past the separators. I'll try the GUICtrlRead. GUICtrlRead($iMsg, 1) worked perfectly thanks, source is now much cleaner! Edited April 22, 2012 by Rogue5099 My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
PhoenixXL Posted April 23, 2012 Share Posted April 23, 2012 It feels Good At Least I was Able To Help U Out!! My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. 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