Tech Off Thread

1 post

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

[C#] Using GetMenuItemInfo

Back to Forum: Tech Off
  • User profile image

    I want to get the text of a certain menu item so I use GetMenuItemInfo.

    I tried it this way:

     static extern bool GetMenuItemInfo(IntPtr hMenu, uint uItem, bool fByPosition, ref MENUITEMINFO lpmii);

     public struct MENUITEMINFO
        public uint cbSize;
        public uint fMask;
        public uint fType;
        public uint fState;
        public uint wID;
        public IntPtr hSubMenu;
        public IntPtr hbmpChecked;
        public IntPtr hbmpUnchecked;
        public string dwTypeData;
        public IntPtr dwItemData;
        public uint cch;
        public IntPtr hbmpItem;


    mif.cbSize = (uint)Marshal.SizeOf(typeof(MENUITEMINFO));
    mif.fMask = 16;
    mif.fType = 0;
    mif.dwTypeData = null;
    GetMenuItemInfo(iconsMenu, 2, false, ref mif);
    mif.dwTypeData = new String('\0', (int)(mif.cch + 1));
    GetMenuItemInfo(iconsMenu, 2, false, ref mif);


    iconsMenu is the handle to the menu which I want to get the item's text from. It doesn't work and I'm quite sure I'm doing something wrong.

    Can you please tell me what's wrong? Thanks in advance Smiley

    I think I know why it doesn't work - the menu had been probably disposed when I called the GetMenuItemInfo command. Nevermind then.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.