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

From: Mattias Sjögren (mattias.dont.want.spam_at_mvps.org)
Date: 10/16/04


Date: Sat, 16 Oct 2004 22:33:21 +0200


>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

-- 
Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Relevant Pages

  • Manipulating win32 app menus from c# using pinvoke...
    ... supplying the fMask of the MENUITEMINFO with the MF_OWNERDRAW constant from ... public uint cbSize; ... public IntPtr hbmpChecked; ... private static extern IntPtr GetSubMenu ...
    (microsoft.public.dotnet.languages.csharp)
  • DCOM across domains
    ... public IntPtr pIID; ... public struct COAUTHIDENTITY ... public uint DomainLength; ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Access Denied executing Batch File from CreateProcessAsUser
    ... > public uint dwX; ... > public IntPtr lpReserved2; ... > private extern static bool CreateProcessAsUser(IntPtr hToken, ... > lpApplicationName, String lpCommandLine, ref SECURITY_ATTRIBUTES ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Function WaveInOpen doesnt return meesage MM_WIM_OPEN?
    ... public IntPtr hWaveOut = IntPtr.Zero; ... public uint nAvgBytesPerSec; ... public static extern int waveInOpen(ref IntPtr lphWaveIn, ... IntPtr dwCallback, uint dwInstance, uint dwFlags); ...
    (microsoft.public.dotnet.languages.csharp)