Jump to content

Get CtrlID or CtrlHandle without OnEvent


Recommended Posts

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?

$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
Link to post
Share on other sites
  • Moderators

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

WEnd

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

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

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

#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 post
Share on other sites
  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

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 post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...