Sign in to follow this  
Followers 0
benners

[Sorted] Context Menu - menu and submenu text

1 post in this topic

#1 ·  Posted (edited)

I am trying to get the text of a menu who's item has been selected. What I have is 2 or more menus (Import\Export) on a context menu each containing 2 menu items (File 1\File 2) with the same text.

I can get the text of the last item clicked but as the text would be the same for both the Import and Export menus I need to get the text of the menu that contains the menu item that was clicked, I can then create a case selection based on which menu, Import or Export, is the active menu. Is this possible?.

Cheers.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Form1", 331, 175, 193, 125)
$Button1 = GUICtrlCreateButton("Button1", 32, 96, 75, 25, 0)
$Button1context = GUICtrlCreateContextMenu($Button1)
$Import_From = GUICtrlCreateMenu("Import From", $Button1context)
$File1_Import = GUICtrlCreateMenuItem("File 1", $Import_From)
GUICtrlSetOnEvent(-1, 'Button1')
$File2_Import = GUICtrlCreateMenuItem("File 2", $Import_From)
GUICtrlSetOnEvent(-1, 'Button1')
$Export_To = GUICtrlCreateMenu("Export To", $Button1context)
$File1_export = GUICtrlCreateMenuItem("File 1", $Export_To)
GUICtrlSetOnEvent(-1, 'Button1')
$File2_Export = GUICtrlCreateMenuItem("File 2", $Export_To)
GUICtrlSetOnEvent(-1, 'Button1')
GUISetState(@SW_SHOW)

GUISetOnEvent($GUI_EVENT_CLOSE, "DoExit") 

While 1
Sleep(10)
WEnd

Func Button1()
        MsgBox(0,'Menu Clicked', 'active menu text goes here')
        
    Switch GUICtrlRead(@GUI_CtrlId, 1); Get the text of the selected menu item.
        Case 'File 1'           
            
        Case 'File 2'
            
    EndSwitch
    
EndFunc

Func DoExit()
    Exit
EndFunc

N/M changed to use Switch @GUI_CtrlId instead. :)

Edited by benners

Share this post


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
Sign in to follow this  
Followers 0