Jump to content
Sign in to follow this  

How to insert a menu item to an application

Recommended Posts


I wanna insert some menu items to an application to do something the application can't do, how?

this is the unfinished code. I can successfully insert "test item" to the applicatoin, but when I click it, nothing happens, there should be a message box popup. Would please help me, thanks a lot

$hWnd = WinGetHandle("Title of my application", "some text")
$hMenu = _GUICtrlMenu_GetMenu($hWnd)
$mi_test = 1000
_GUICtrlMenu_InsertMenuItem($hMenu, 0, "test item", $mi_test)

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    ConsoleWrite(_WinAPI_LoWord ($iwParam) & @CRLF)
    Switch _WinAPI_LoWord ($iwParam)
        Case $mi_test
           MsgBox(0, "", "")
EndFunc   ;==>WM_COMMAND

Share this post

Link to post
Share on other sites

Basically, your code flows like this:

Declare variables

Insert item

Register a message with an internal AUTOIT created GUI by calling a custom function

Sleep for ... ever.


Where's the test for when the user clicks on that menu?

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post

Link to post
Share on other sites

that's an interresting feature,

not perfect but it's a start :

#include <GuiMenu.au3>
$hWnd = WinGetHandle("C:\AutoIT\forum\new_menu.au3 - SciTE")
$hMenu = _GUICtrlMenu_GetMenu($hWnd)
_GUICtrlMenu_InsertMenuItem($hMenu, 0, "Menu Name")

While 1
    $state = _GUICtrlMenu_GetItemState($hMenu, 0)
    If $state<>0 Then myFunc($State)

Func myFunc($myState)
    MsgBox(0,"Menu State",$myState)

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.