Jump to content

Recommended Posts

Posted

I had written a GUI with several buttons and I wanted one of the buttons to show its context menu regardless of the user right or left clicking the button.  The whole purpose of the button was to show the user a menu of options and a context menu fit the need just fine, but I needed it to display with either click option.  I came up with the code below to accomplish this but I feel like I might be missing some very obvious easier way to do this and I feel it's a little lame to be forcing a right click mouse action on the button as a result of the user doing a left click, but it works!

Anyone have a suggestion of a better way to do this?  Otherwise, if this idea helps you, here you go.

#include <GUIConstantsEx.au3>

LeftClickContextTest()

Func LeftClickContextTest()
    Local $hGUI = GUICreate("My GUI", 200, 100)
    Local $button = GUICtrlCreateButton("Show Context", 15, 40, 85, 25)
    Local $close = GUICtrlCreateButton("Close", 110, 40, 85, 25)
    Local $context = GUICtrlCreateContextMenu($button)
    GUICtrlCreateMenuItem("Test Context Item 1", $context)
    GUICtrlCreateMenuItem("Test Context Item 2", $context)
    GUICtrlCreateMenuItem("Test Context Item 3", $context)
    GUISetState(@SW_SHOW, $hGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $close
                ExitLoop
            Case $button
                MouseClick("right", MouseGetPos(0), MouseGetPos(1), 1, 0)
        EndSwitch
    WEnd
EndFunc

 

Progress lies not in enhancing what is, but in advancing towards what will be. - Kahlil Gibran
  • 5 months later...
Posted

Very late to the party, but saw this when looking for something else, so I thought I would contribute the following ... might help someone.

ControlClick($hGUI, "", $button, "right", 1)

That means the right-click context menu will appear when left clicking the button.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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
×
×
  • Create New...