Sign in to follow this  
Followers 0
WiiDSmoker

Context Menu Case Switch Not Working

2 posts in this topic

#1 ·  Posted (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 by WiiDSmoker

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

  1. build a runable reproducer script next time
  2. it's no good coding practice declaring Globals in local scope
  3. 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 by AutoBert
added GUIOnEventMode (asked per PM)

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