[gme-users] Adding context menu items through a decorator

Kevin Smyth kevin.m.smyth at gmail.com
Tue Feb 20 16:27:49 CST 2018


Hi Cinthya,

Your AppendMenu declaration is wrong for 64-bit. It should be:
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern int AppendMenu(IntPtr hMenu, uint uFlags, IntPtr uIDNewItem,
string lpNewItem);

But the issue for 32-bit is the uIDNewItem. This is from the C++ example
and works:
const int CTX_MENU_ID = 0x4001 + 100;

I don't know why 0x5995 doesn't work.

Remove the EnableMenuItem calls; they are not
needed. ContextMenuFlags.MF_ENABLED is wrong here.

Kevin

On Tue, Feb 20, 2018 at 3:06 PM, Cinthya Lopez <Cinthya_K_Lopez at raytheon.com
> wrote:

> Hi,
>
>
>
> I am attempting to add a context menu item through a decorator. My
> decorator is written in C#. Calling the user32.dll function AppenMenu()
> adds my context menu items just fine. My problem is that they all are
> disabled and calling the user32.dll function EnableMenuItem() does not seem
> to work. Does anyone have an idea of what could be my problem. This is what
> I have…
>
>
>
> Declarations:
>
>
>
>         [DllImport("user32.dll", CharSet=CharSet.Auto)]
>
>         static extern bool AppendMenu(IntPtr hMenu, uint uFlags, uint
> uIDNewItem, string lpNewItem);
>
>
>
>         [DllImport("user32.dll")]
>
>         static extern bool EnableMenuItem(IntPtr hMenu, uint
> uIDEnableItem, uint uEnable);
>
>
>
>         struct ContextMenuFlags
>
>         {
>
>             public const int MF_ENABLED  = 0x00000000;  // Enables the
> menu item so that it can be selected, and restores it from its grayed state
>
>             public const int MF_STRING     = 0;                       //
> Specifies that the menu item is a text string; the lpNewItem parameter is a
> pointer to the string
>
>             public const int MF_GRAYED   = 0x00000001;  // Disables the
> menu item and grays it so that it cannot be selected
>
>             public const int MF_DISABLED = 0x00000002;  // Disables the
> menu item so that it cannot be selected, but the flag does not gray it
>
>         };
>
>
>
>         const int    CTX_MENU_ID  = 0x5995;
>
>         const String CTX_MENU_STR = "My Attributes";
>
>
>
> In my decorator’s MouseRightButtonDown() function I have…
>
>
>
>         public void MouseRightButtonDown(ulong hCtxMenu, uint nFlags, int
> pointx, int pointy, ulong transformHDC)
>
>         {
>
>             IntPtr intPtr = (IntPtr)hCtxMenu;
>
>             bool retVal1 = AppendMenu(intPtr, ContextMenuFlags.MF_STRING,
> CTX_MENU_ID, CTX_MENU_STR);
>
>             retVal1 = AppendMenu(intPtr, ContextMenuFlags.MF_STRING,
> CTX_MENU_ID+1, CTX_MENU_STR + "(1)");
>
>             retVal1 = AppendMenu(intPtr, ContextMenuFlags.MF_STRING,
> CTX_MENU_ID+2, CTX_MENU_STR + "(2)");
>
>
>
>             bool retVal2 = EnableMenuItem(intPtr, CTX_MENU_ID,
> ContextMenuFlags.MF_ENABLED);
>
>             retVal2 = EnableMenuItem(intPtr, CTX_MENU_ID+1,
> ContextMenuFlags.MF_ENABLED);
>
>             retVal2 = EnableMenuItem(intPtr, CTX_MENU_ID+2,
> ContextMenuFlags.MF_ENABLED);
>
>         }
>
>
>
>
>
> Thank you,
>
> Cinthya
>
> _______________________________________________
> gme-users mailing list
> gme-users at list.isis.vanderbilt.edu
> http://list.isis.vanderbilt.edu/cgi-bin/mailman/listinfo/gme-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.isis.vanderbilt.edu/pipermail/gme-users/attachments/20180220/789c2c67/attachment.html>


More information about the gme-users mailing list