Jump to content

Show context-menu at left-click


 Share

Recommended Posts

Is there any way to show a context-menu, when for example left-clicking a button ?

At default it requires a right-click, which works, but for what I want to use it for

(where the context-menu is the only function for that button) it's just doesn't

feel natural having to right-click it.

Doesn't seem like a big deal, but anyway it would be great if it was possible !

Link to comment
Share on other sites

Do you not have in Mouse options, to change primary button with secondary button? I have the option in XP.

<{POST_SNAPBACK}>

Yes, but that's just a crude workaround.

I was thinking more of a DLLCall or something...

Link to comment
Share on other sites

Maybe ControlClick()

e.g.:

Case $msg = $pressedCTRL
    ControlClick($hWnd, "", $pressedCTRL, "right"); Display the context menu

<{POST_SNAPBACK}>

Already thought of.. It works perfectly, however I wouldn't call this a clean solution

but maybe a...clean workaround.. ?

Anyway, I will probably use this method if there isn't any other way of doing it.

Link to comment
Share on other sites

Already thought of.. It works perfectly, however I wouldn't call this a clean solution

but maybe a...clean workaround.. ?

Anyway, I will probably use this method if there isn't any other way of doing it.

<{POST_SNAPBACK}>

Yes, maybe isn't a clean, like you say...

I think that, there is a DLL function... :(

Link to comment
Share on other sites

Hmm, with DllCall we can do it this way:

#include <GUIConstants.au3>

$WM_CONTEXTMENU = 0x7B

$hGUI = GUICreate("Left Clicks context demo", 300, 200)

$hMenu = GUICtrlCreateContextMenu()
GUICtrlCreateMenuitem ("Menu item 1", $hMenu)
GUICtrlCreateMenuitem ("Menu item 2", $hMenu)
$hBtn = GUICtrlCreateButton("Click me!", 5, 5)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    If $nMsg = $GUI_EVENT_CLOSE Then Exit
    If $nMsg = $hBtn Then
        DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $hGUI, "int", $WM_CONTEXTMENU, "int", ControlGetHandle($hGUI, "", $hBtn), "int", 0)
    Endif
Wend

That's how I always did it. Only problem is that the menu will appear near the mouse, even if you used an accelerator key or something. Say the button name was &Click, you move your mouse 200px away from teh button, then press Alt+C. The menu will appear at the mouse.

Yes, it is... According to MSDN lParam here is carry position of where mouse clicked. But I'm trying to set this with no luck... it's always appears at mouse position.
Link to comment
Share on other sites

  • 2 weeks later...

Awsome, LazyCat !

Thanks a bunch !

I saw your post yesterday, but then I didn't had the time to test it !

Anyway, it works perfectly ! Thanks again !

ShakeHand("right")

-Helge-

Hmm, with DllCall we can do it this way:

#include <GUIConstants.au3>

$WM_CONTEXTMENU = 0x7B

$hGUI = GUICreate("Left Clicks context demo", 300, 200)

$hMenu = GUICtrlCreateContextMenu()
GUICtrlCreateMenuitem ("Menu item 1", $hMenu)
GUICtrlCreateMenuitem ("Menu item 2", $hMenu)
$hBtn = GUICtrlCreateButton("Click me!", 5, 5)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    If $nMsg = $GUI_EVENT_CLOSE Then Exit
    If $nMsg = $hBtn Then
        DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $hGUI, "int", $WM_CONTEXTMENU, "int", ControlGetHandle($hGUI, "", $hBtn), "int", 0)
    Endif
Wend

Yes, it is... According to MSDN lParam here is carry position of where mouse clicked. But I'm trying to set this with no luck... it's always appears at mouse position.

<{POST_SNAPBACK}>

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...