Sign in to follow this  
Followers 0
covaks

_GUICtrlMenu_DrawMenuBar

2 posts in this topic

Looking at the example in the help file, posted below, how would I capture clicks on the menu items? I tried GuiGetMsg, as well as OnEventMode with GuiCtrlSetOnEvent, but couldn't get anything to work.

I'd like to add items to a context menu or menu on another application. Adding items to a context menu in another program would be ideal, but I can't find anything solid on it. Searching the forums either brings up context menu help for my own gui, or posts about editing the context menu for explorer, which is not what I want. So, I figure adding menu items is the next best thing, and this example looks like a step in the right direction. I know how to add buttons and other controls using Anygui, but I'd prefer a menu or context menu if it's possible.

_GUICtrlMenu_DrawMenuBar help file example:

#include <GuiMenu.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $hWnd, $hMain, $hItem1, $hItem2

    ; Open Notepad
    Run("Notepad.exe")
    WinWaitActive("Untitled - Notepad")
    $hWnd = WinGetHandle("Untitled - Notepad")
    $hMain = _GUICtrlMenu_GetMenu ($hWnd)

    ; Create subitem menu
    $hItem1 = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hItem1, 0, "SubItem &1", 0x1000)
    _GUICtrlMenu_InsertMenuItem ($hItem1, 1, "SubItem &2", 0x1001)

    ; Create menu
    $hItem2 = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hItem2, 0, "Item &1", 0x2000, $hItem1)
    _GUICtrlMenu_InsertMenuItem ($hItem2, 1, "Item &2", 0x2001)
    _GUICtrlMenu_InsertMenuItem ($hItem2, 2, "", 0)
    _GUICtrlMenu_InsertMenuItem ($hItem2, 3, "Item &3", 0x2002)
    _GUICtrlMenu_InsertMenuItem ($hItem2, 4, "Item &4", 0x2003)

    ; Insert new menu into Notepad
    _GUICtrlMenu_InsertMenuItem ($hMain, 6, "&AutoIt", 0, $hItem2)
    _GUICtrlMenu_DrawMenuBar ($hWnd)

EndFunc   ;==>_Main

Share this post


Link to post
Share on other sites



Looking at the example in the help file, posted below, how would I capture clicks on the menu items? I tried GuiGetMsg, as well as OnEventMode with GuiCtrlSetOnEvent, but couldn't get anything to work.

I'd like to add items to a context menu or menu on another application. Adding items to a context menu in another program would be ideal, but I can't find anything solid on it. Searching the forums either brings up context menu help for my own gui, or posts about editing the context menu for explorer, which is not what I want. So, I figure adding menu items is the next best thing, and this example looks like a step in the right direction. I know how to add buttons and other controls using Anygui, but I'd prefer a menu or context menu if it's possible.

_GUICtrlMenu_DrawMenuBar help file example:

#include <GuiMenu.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $hWnd, $hMain, $hItem1, $hItem2

    ; Open Notepad
    Run("Notepad.exe")
    WinWaitActive("Untitled - Notepad")
    $hWnd = WinGetHandle("Untitled - Notepad")
    $hMain = _GUICtrlMenu_GetMenu ($hWnd)

    ; Create subitem menu
    $hItem1 = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hItem1, 0, "SubItem &1", 0x1000)
    _GUICtrlMenu_InsertMenuItem ($hItem1, 1, "SubItem &2", 0x1001)

    ; Create menu
    $hItem2 = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hItem2, 0, "Item &1", 0x2000, $hItem1)
    _GUICtrlMenu_InsertMenuItem ($hItem2, 1, "Item &2", 0x2001)
    _GUICtrlMenu_InsertMenuItem ($hItem2, 2, "", 0)
    _GUICtrlMenu_InsertMenuItem ($hItem2, 3, "Item &3", 0x2002)
    _GUICtrlMenu_InsertMenuItem ($hItem2, 4, "Item &4", 0x2003)

    ; Insert new menu into Notepad
    _GUICtrlMenu_InsertMenuItem ($hMain, 6, "&AutoIt", 0, $hItem2)
    _GUICtrlMenu_DrawMenuBar ($hWnd)

EndFunc   ;==>_Main
Once you add the AutoIt menu item to Notepad's menu bar, your script exits, so it isn't listening for any messages anyway. But the real problem is that messages from that control go to Notepad.exe because that's the process owning that GUI. So messages are generated, but Notepad.exe gets and ignores them as unexpected.

Interesting bottom-up way to assemble the menu, by the way...

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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