Jump to content

Distinguish Left/Right Click Sub Menu


Go to solution Solved by spudw2k,

Recommended Posts

I am looking for a way to have a switch recognize when I left click vs. right click on a submenu option. I can perform this task on controls within the GUI but I can't figure it out within Menu Options.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Global $GUI, $menu, $subMenu

$GUI = GUICreate("Example GUI", 300, 200)

$menu = GUICtrlCreateMenu("&File")
$subMenu = GUICtrlCreateMenuItem("Options", $menu)

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_SECONDARYUP
            $mCur = GUIGetCursorInfo($GUI)
            If IsArray($mCur) Then
                If $mCur[4] = $subMenu Then MsgBox(0, "Test", "Right Clicked")
            EndIf
        Case $subMenu
            MsgBox(0, "Test", "Left Clicked")
    EndSwitch
WEnd

 

Link to comment
Share on other sites

  • Solution

I believe you will have to resort to a Message handler. 

Here is an example which handles the WM_MENURBUTTONUP Windows Message ID.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3>

Global $GUI, $menu, $subMenu

$GUI = GUICreate("Example GUI", 300, 200)

$menu = GUICtrlCreateMenu("&File")
$subMenu = GUICtrlCreateMenuItem("Options", $menu)

GUIRegisterMsg($WM_MENURBUTTONUP, "_WM_MENURBUTTONUP")  ;Register Message Handler

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $subMenu
            MsgBox(0, "Test", "Left Clicked")
    EndSwitch
WEnd

Func _WM_MENURBUTTONUP($hWnd, $iMsg, $wParam, $lParam)
    Local $hMenu = GUICtrlGetHandle($menu)
    Switch $lParam  ;Handle of triggering Menu
        Case $hMenu
            Local $iMenuIndexID = _GUICtrlMenu_GetItemID($hMenu, $wParam)    ;Get ID using Handle of Menu Subitem ($wParam)
            Switch $iMenuIndexID
                Case $subMenu
                    MsgBox(0, "Test", "Right Clicked")
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc

 

Edited by spudw2k
Link to comment
Share on other sites

Link to comment
Share on other sites

10 hours ago, argumentum said:

Why ?, what for ?

A bit silly, but my intention was for it to be a bit of an easter egg. A way to access back end information, but I admit the idea was more of a learning opportunity for me to get creative and I took advantage of the idea to improve my understanding of code. The actual script I am looking to implement it on is a glorified mouse clicker with a bunch of handy tools for interacting with Windows.

11 hours ago, spudw2k said:

I believe you will have to resort to a Message handler. 

Here is an example which handles the WM_MENURBUTTONUP Windows Message ID.

This! I was looking down the right path but fell short. I was able to find WM_MENUSELECT and that was not working as desired. This is exactly what I was looking for and would not have been able to piece it together without help. I have zero understanding of how that Function is working which gives me a chance to read up :) 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...