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
    yyy

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

    I tried it this way:

    [DllImport("user32.dll")]
     static extern bool GetMenuItemInfo(IntPtr hMenu, uint uItem, bool fByPosition, ref MENUITEMINFO lpmii);

    [StructLayout(LayoutKind.Sequential)]
     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;
     }

    .
    .
    .

    MENUITEMINFO mif = new MENUITEMINFO();
               
    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);

    MessageBox.Show(mif.dwTypeData);


    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


    EDIT:
    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.