日期:2014-05-19  浏览次数:20959 次

如何在窗体标题栏左边的控制菜单加入自己的菜单啊?
如题,不知道那个东西应该叫它什么名字。
我们一般在窗口标题栏点右键   或   按Alt+空格   可以弹出那个菜单。




------解决方案--------------------
using System.Runtime.InteropServices;

[DllImport( "user32.dll ")]
public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

[DllImport( "user32.dll ")]
public static extern bool InsertMenu(IntPtr hMenu, uint uPosition, uint uFlags,
uint uIDNewItem, string lpNewItem);

public const int MF_BYCOMMAND = 0;
public const int MF_STRING = 0;
public const int MF_BYPOSITION = 0x400;
public const int MF_SEPARATOR = 0x800;

private const uint SC_ABOUT = 0x0001;
public const int WM_SYSCOMMAND = 0x0112;

private void Form1_Load(object sender, EventArgs e)
{
IntPtr vMenuHandle = GetSystemMenu(Handle, false);
InsertMenu(vMenuHandle, 255, MF_STRING, SC_ABOUT, "About... ");
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_SYSCOMMAND:
if ((uint)m.WParam == SC_ABOUT)
{
MessageBox.Show( "Zswang 路过! ");
}
break;
}
base.WndProc(ref m);
}