Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

AppendMenu (coredll)
 

coredll is for smart devices, not desktop Windows. Therefore, this information only applies to code using the .NET Compact Framework. To see if information for AppendMenu in other DLLs exists, click on Find References to the right.

.
Summary
This function appends a new item to the end of the specified menu. You can use AppendMenu to specify the content, appearance, and behavior of the menu item.

C# Signature:

[DllImport("coredll.dll")]
[DllImport("coredll.dll", SetLastError=true)]
static extern uint AppendMenu(IntPtr hMenu, uint uFlags, uint uIDNewItem, string lpNewItem);

User-Defined Types:

[uFlags]

    uint MF_BYCOMMAND = 0x00000000;
    uint MF_BYPOSITION = 0x00000400;
    uint MF_SEPARATOR = 0x00000800;
    uint MF_ENABLED = 0x00000000;
    uint MF_GRAYED = 0x00000001;
    uint MF_UNCHECKED = 0x00000000;
    uint MF_CHECKED = 0x00000008;
    uint MF_STRING = 0x00000000;
    uint MF_OWNERDRAW = 0x00000100;
    uint MF_POPUP = 0x00000010;

uint MF_BYCOMMAND = 0x00000000;

uint MF_BYPOSITION = 0x00000400;

uint MF_SEPARATOR = 0x00000800;

uint MF_ENABLED = 0x00000000;

uint MF_GRAYED = 0x00000001;

uint MF_UNCHECKED = 0x00000000;

uint MF_CHECKED = 0x00000008;

uint MF_STRING = 0x00000000;

uint MF_OWNERDRAW = 0x00000100;

uint MF_POPUP = 0x00000010;

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

To add a submenu use MF_STRING in conjunction with MF_POPUP passing to the [uIDNewItem] parameter the handle to the submenu parent item as illustrated in the Sample Code section.

Sample Code:

    [DllImport("coredll.dll")]
    static extern IntPtr CreatePopupMenu();

IntPtr hMenu = CreatePopupMenu();

uint flags = MF_STRING;

    [DllImport("coredll.dll")]
    static extern uint AppendMenu(IntPtr hMenu, uint uFlags, uint uIDNewItem, string lpNewItem);

AppendMenu(hMenu, flags, 1001, "Simple Menu Item");

    const uint MF_STRING = 0x00000000;
    const uint MF_POPUP = 0x00000010;

IntPtr subMenuParentItem = CreatePopupMenu();

flags |= MF_POPUP;

    public void CreateMenu()
    {
        IntPtr hMenu = CreatePopupMenu();
        uint flags = MF_STRING;

AppendMenu(hMenu, flags, (uint) subMenuParentItem, "Pop-up Parent Item");

AppendMenu(subMenuParentItem, MF_STRING, 1010, "Submenu Simple Item");

        AppendMenu(hMenu, flags, 1001, "Simple Menu Item");

        IntPtr subMenuParentItem = CreatePopupMenu();
        flags |= MF_POPUP;

        AppendMenu(hMenu, flags, (uint) subMenuParentItem, "Pop-up Parent Item");
        AppendMenu(subMenuParentItem, MF_STRING, 1010, "Submenu Simple Item");
    }

Documentation
AppendMenu on MSDN

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions