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

Cinthya Lopez Cinthya_K_Lopez at raytheon.com
Tue Feb 20 15:06:04 CST 2018


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.isis.vanderbilt.edu/pipermail/gme-users/attachments/20180220/63f49a96/attachment.html>


More information about the gme-users mailing list