Sign in to follow this  
Followers 0
AndyS01

event handler for top menu item

2 posts in this topic

I want to have an event handler for when I click on an Options top menu item, but I can only get them for sub-menu items.

So if I had a top menu like this: "&File &Options", and the Options has no submenus, I want to capture a click on the Options item so I can bring up an Options popup GUI.

Here is a stripped down example:

Opt("GUIEventOptions", 1)

GUICreate("My GUI")

$iID = GUICtrlCreateMenu("&Options", -1)

GUICtrlSetOnEvent($iID, "handle_Options_Click")

GUISetState(@SW_SHOW) ; will display an empty dialog box

While 1
    Sleep(500) ; sleep a short while
WEnd
exit(1)

Func handle_Options_Click()
    MsgBox(0, "TRACE", "Options menu button was clicked" & @CRLF)
EndFunc

When I run it, I do not get to the event handler.

Any help would be appreciated.

Andy

Share this post


Link to post
Share on other sites

Wow - it takes a beginner to mess-up a script ... where Opt("GUIEventOptions", 1) comes from???

What you want it doesn't work if you have only that one menu - the trick to make this to work is to create a MenuItem ... which - obviously - needs a menu created first ... well, you get the idea.

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

GUICreate("My GUI")
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseScript")
$Start = GUICtrlCreateMenu("&Start")
$HelpM = GUICtrlCreateMenuItem("&Options", -1)
GUICtrlSetOnEvent(-1, "handle_Options_Click")

GUISetState(@SW_SHOW) ; will display an empty dialog box

While 1
    Sleep(100) ; sleep a short while
WEnd


Func handle_Options_Click()
    MsgBox(0, "TRACE", "Options menu button was clicked" & @CRLF)
EndFunc
Func CloseScript()
    Exit
EndFunc

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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