Can a context menu have side-by-side menu items?

  • Thread starter Thread starter VMI
  • Start date Start date
V

VMI

Usually, Windows context menus have menu items that go from top to bottom:

Copy
Paste
Cut
Process
....
....

Is it possible to make a Context menu so that the menu items were
side-to-side:

Copy / Paste
Cut / Process
.... / ...

Thanks.
 
VMI said:
Usually, Windows context menus have menu items that go from top to bottom:

Copy
Paste
Cut
Process
...
...

Is it possible to make a Context menu so that the menu items were
side-to-side:

Copy / Paste
Cut / Process
... / ...

Thanks.

I do not believe so, atleast not with the ContextMenu class. It may be
possible with a custom context menu class, but that would take more
knowledge than I have about Win32 menu's.
 
Is it possible to make a Context menu so that the menu items were
side-to-side:

Copy / Paste
Cut / Process
... / ...

The Win32 API lets you split a menu in multiple columns. You can use
code such as this

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

....

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

....

const uint MIIM_FTYPE = 0x100;
const uint MFT_MENUBARBREAK = 0x20;
const uint MFT_MENUBREAK = 0x40;

MENUITEMINFO mii = new MENUITEMINFO();
mii.cbSize = Marshal.SizeOf( typeof(MENUITEMINFO) );
mii.fMask = MIIM_FTYPE;
mii.fType = MFT_MENUBREAK;

SetMenuItemInfo( YourContextMenu.Handle, idx, true, ref mii );

where idx is the index of the item you want to break on. Replace
MFT_MENUBREAK with MFT_MENUBARBREAK if you want a vertical divider to
appear between the columns.



Mattias
 
Back
Top