Jump to content



Photo

Get CtrlID or CtrlHandle without OnEvent


  • Please log in to reply
6 replies to this topic

#1 Rogue5099

Rogue5099

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 313 posts

Posted 22 April 2012 - 01:03 PM

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?

AutoIt         
$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






#2 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,301 posts

Posted 22 April 2012 - 01:14 PM

Rogue5099,

I would do it like this: ;)
AutoIt         
#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 WEnd

But you must make sure that you create all the menu items in immediate succession or the trick does not work. :)

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#3 Rogue5099

Rogue5099

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 313 posts

Posted 22 April 2012 - 01:21 PM

But you must make sure that you create all the menu items in immediate succession or the trick does not work


Looks like I got a lot of rearranging to to ;) thanks again!

#4 PhoenixXL

PhoenixXL

    Be what you are, believe me its always the BEST...

  • Active Members
  • PipPipPipPipPipPip
  • 1,299 posts

Posted 22 April 2012 - 01:29 PM

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

AutoIt         
#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

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.

#5 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,301 posts

Posted 22 April 2012 - 01:43 PM

PhoenixXL,

That is very clever. ;)

But could I offer this slightly changed version:
AutoIt         
#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
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#6 Rogue5099

Rogue5099

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 313 posts

Posted 22 April 2012 - 01:47 PM

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 by Rogue5099, 22 April 2012 - 01:56 PM.


#7 PhoenixXL

PhoenixXL

    Be what you are, believe me its always the BEST...

  • Active Members
  • PipPipPipPipPipPip
  • 1,299 posts

Posted 23 April 2012 - 03:18 AM

It feels Good
At Least I was Able To Help U Out!! ;)
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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users