Jump to content

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)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
Sleep(2000000)

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    ConsoleWrite(_WinAPI_LoWord ($iwParam) & @CRLF)
    Switch _WinAPI_LoWord ($iwParam)
        Case $mi_test
           MsgBox(0, "", "")
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND
Link to comment
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.

Exit.

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

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

Link to comment
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)
    Sleep(500)
WEnd

Func myFunc($myState)
    MsgBox(0,"Menu State",$myState)
EndFunc
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...