Jump to content
Sign in to follow this  

_GUICtrlMenu_GetMenuDefaultItem returns -1

Recommended Posts


I do some test with adding menuentries to existing programs.

Found '_GUICtrlMenu_GetMenuDefaultItem.au3' sample that uses notepad.exe (in AutoIt examples).

It should return the DefaultMenuItems.

The sample seems to not work, because "_GUICtrlMenu_GetMenuDefaultItem($hFile))" returns -1.

I heared about that some Autoit Menu functions don't work with newer menus.

Is this correct?


#include <GuiMenu.au3>

Opt('MustDeclareVars', 1)


Func _Main()
    Local $hWnd, $hMain, $hFile

    ; Open Notepad
    $hWnd = WinGetHandle("[CLASS:Notepad]")
    $hMain = _GUICtrlMenu_GetMenu($hWnd)
    $hFile = _GUICtrlMenu_GetItemSubMenu($hMain, 0)

    ; Get/Set File menu default item
    Writeln("File menu default item: " & _GUICtrlMenu_GetMenuDefaultItem($hFile))
    _GUICtrlMenu_SetMenuDefaultItem($hFile, 1)
    Writeln("File menu default item: " & _GUICtrlMenu_GetMenuDefaultItem($hFile))

EndFunc   ;==>_Main

; Write a line of text to Notepad
Func Writeln($sText)
    ControlSend("[CLASS:Notepad]", "", "Edit1", $sText & @CR)
EndFunc   ;==>Writeln
Edited by MZXPTLK

Share this post

Link to post
Share on other sites

It doesn't look to me like Notepad has a default MenuItem. What do you really expect of that script?


Yes, maybe, I don't know.

I thought the first items in each menu are returned!?

That's why I'm asking.

But why did the Autoit developers create this script?


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.