WiiDSmoker Posted May 18, 2016 Share Posted May 18, 2016 (edited) I can get the context menu to show, but upon hitting 'About button'; nothing happens. Func test () $Label = GUICtrlCreateLabel("test", 121, 0, 30, 17) Global $idButtoncontext = GUICtrlCreateContextMenu($Label ) Global $idMenuAbout = GUICtrlCreateMenuItem("About button", $idButtoncontext) End Func While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idMenuAbout msgbox(0,0,"test") EndSwitch WEnd Edited May 18, 2016 by WiiDSmoker Link to comment Share on other sites More sharing options...
AutoBert Posted May 19, 2016 Share Posted May 19, 2016 (edited) build a runable reproducer script next time it's no good coding practice declaring Globals in local scope Your func test is never closed, correct the typo if all is done it works: ; *** Start added by AutoIt3Wrapper *** #include <GUIConstantsEx.au3> ; *** End added by AutoIt3Wrapper *** #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Global $idButtoncontext Global $idMenuAbout test() Func test() $hGui = GUICreate('contextmenu test') $Label = GUICtrlCreateLabel("test", 121, 0, 30, 17) $idButtoncontext = GUICtrlCreateContextMenu($Label) $idMenuAbout = GUICtrlCreateMenuItem("About button", $idButtoncontext) GUISetState() EndFunc ;==>test While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idMenuAbout MsgBox(0,"Title" ,"Text") EndSwitch WEnd and this way it's also working in GuiOnEvent-Mode: ; *** Start added by AutoIt3Wrapper *** #include <GUIConstantsEx.au3> ; *** End added by AutoIt3Wrapper *** #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Opt('GUIOnEventMode', 1); Enable/disable OnEvent functions notifications. 0 = (default) disable. 1 = enable. test() Func test() Local $hGui = GUICreate('contextmenu test') GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit') Local $Label = GUICtrlCreateLabel("test", 121, 0, 30, 17) Local $idButtoncontext = GUICtrlCreateContextMenu($Label) Local $idMenuAbout = GUICtrlCreateMenuItem("About button", $idButtoncontext) GUICtrlSetOnEvent($idMenuAbout, '_MenuAbout') GUISetState() EndFunc ;==>test While 1 Sleep(1000) WEnd Func _exit() Exit EndFunc ;==>_exit Func _MenuAbout() MsgBox(0,"Title" ,"Text") EndFunc ;==>_MenuAbout Edited May 19, 2016 by AutoBert added GUIOnEventMode (asked per PM) 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