Sign in to follow this  
Followers 0
DarkOnyx

Right click menus

8 posts in this topic

Hi everyone.  

I have just found this software and I must say that it's magnificent.  I am teaching myself through various code examples and I created a basic GUI.  Cool.  

I was looking at this example here:

=======================================================================================
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

Example1()
Example2()

; ****************
; * First sample *
; ****************
Func Example1()
    ;right click on gui to bring up context Menu.
    ;right click on the "ok" button to bring up a controll specific context menu.

    GUICreate("My GUI Context Menu", 300, 200)

    Local $contextmenu = GUICtrlCreateContextMenu()

    Local $button = GUICtrlCreateButton("OK", 100, 100, 70, 20)
    Local $buttoncontext = GUICtrlCreateContextMenu($button)
    GUICtrlCreateMenuItem("About button", $buttoncontext)

    Local $newsubmenu = GUICtrlCreateMenu("new", $contextmenu)
    GUICtrlCreateMenuItem("text", $newsubmenu)

    GUICtrlCreateMenuItem("Open", $contextmenu)
    GUICtrlCreateMenuItem("Save", $contextmenu)
    GUICtrlCreateMenuItem("", $contextmenu) ; separator

    GUICtrlCreateMenuItem("Info", $contextmenu)

    GUISetState()

    ; Run the GUI until the dialog is closed
    While 1
        Local $msg = GUIGetMsg()

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
    GUIDelete()
EndFunc   ;==>Example1

 

=======================================================================================

 

I see that it creates a simple right click menu.  Very nice.  But none of the controls actually do anything so I am having trouble understanding that next step.  I'd experimented with switch/case and haven't had that much luck on making any new breakthroughs in my understanding. 

Which command allows the "Info" button on the right click menu execute a command?  Where should I start looking?  Thanks.

 

Share this post


Link to post
Share on other sites



Hi DarkOnyx,

 and welcome to the forum!

Switch case was the correct place to look. Now just get a working example of some code using these and play around with it until you see how it works, then start changing to do what you want.

I just posted just such an >example. B)

The buttons used are different from the Context Menu but same basic concept.

Bill

Share this post


Link to post
Share on other sites

Here a simple example to get you started:

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

    GUICreate("My GUI Context Menu", 300, 200)
    Local $case_0, $case_1, $case_2, $case_3
    Local $contextmenu = GUICtrlCreateContextMenu()

    Local $button = GUICtrlCreateButton("OK", 100, 100, 70, 20)
    Local $buttoncontext = GUICtrlCreateContextMenu($button)
    GUICtrlCreateMenuItem("About button", $buttoncontext)

    Local $newsubmenu = GUICtrlCreateMenu("new", $contextmenu)
    GUICtrlCreateMenuItem("text", $newsubmenu)

    $case_0 = GUICtrlCreateMenuItem("Case 0", $contextmenu)
    $case_1 = GUICtrlCreateMenuItem("Case 1", $contextmenu)
    GUICtrlCreateMenuItem("", $contextmenu) ; separator
    $case_2 = GUICtrlCreateMenuItem("Case 2", $contextmenu)
    $case_3 = GUICtrlCreateMenuItem("Case 3", $contextmenu)

    GUICtrlCreateMenuItem("Info", $contextmenu)

    GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $case_0
            MsgBox(0, "Case 0", "This is Case 0")
        Case $case_1
            MsgBox(0, "Case 1", "This is Case 1")
        Case $case_2
          _Function_case_2()
        Case $case_3
            MsgBox(0, "Case 3", "This is Case 3")
    EndSwitch
WEnd

Func _Function_case_2()
     MsgBox(0, "Case 2", "This is Function Case 2")

EndFunc

Share this post


Link to post
Share on other sites

Thanks so much for taking the time to help me get started!

I'll play around with the code and see what happens.  Thanks again!

Share this post


Link to post
Share on other sites

Aha!  Opt("GUIOnEventMode", 1) did something that made the menus not work.  

Interesting...

Share this post


Link to post
Share on other sites

DarkOnyx,

You can only run either OnEvent or MessageLoop mode at one time in a script. So if you want to run the script in OnEvent mode you will need to assign event functions to each of the active menu items using GUICtrlSetOnEvent. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

It works great now!

Headache eliminated....

Of course, there's only one thing to do now... GO ON TO THE NEXT HEADACHE INDUCING CODE!

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