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

TrackPopupMenuEx (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 TrackPopupMenuEx in other DLLs exists, click on Find References to the right.

.
Summary
This function displays a floating pop-up menu at the specified location and tracks the selection of items on the pop-up menu. The floating pop-up menu can appear anywhere on the screen.

C# Signature:

[DllImport("user32.dll", SetLastError=true)]
[DllImport("coredll.dll", SetLastError=true)]
static extern uint TrackPopupMenuEx(IntPtr hMenu, uint uFlags, int x, int y, IntPtr hWnd, IntPtr tpmParams);

User-Defined Types:

uFlags:

    uint TPM_LEFTALIGN = 0x0000;
    uint TPM_CENTERALIGN = 0x0004;
    uint TPM_RIGHTALIGN = 0x0008;
    uint TPM_TOPALIGN = 0x0000;
    uint TPM_VCENTERALIGN = 0x0010;
    uint TPM_BOTTOMALIGN = 0x0020;
    uint TPM_HORIZONTAL = 0x0000;
    uint TPM_VERTICAL = 0x0040;
    uint TPM_RETURNCMD = 0x0100;

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

Tips & Tricks:

Use TrackPopupMenuEx with the TPM_RETURNCMD flag to return the ID of the selected Menu Item.

Sample Code:

    MessageWindow eventSink = new MessageWindow();
    IntPtr hMenu = CreatePopUpMenu();

    // Add some items...
    AppendMenu(hMenu, MF_STRING, 1001, "Item 1");

    // Display a Pop Up menu at the bottom right corner of the working area of the screen
    // growing from bottom to top
    uint menuItemID = TrackPopupMenuEx(hMenu, TPM_BOTTOMALIGN | TPM_RETURNCMD, Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height, eventSink.Hwnd, IntPtr.Zero);

    // Use the menuItemID to fire some event...

Documentation

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