C# 将菜单选项插入应用程序菜单

C# 将菜单选项插入应用程序菜单,c#,winforms,menu,titlebar,C#,Winforms,Menu,Titlebar,Windows应用程序在标题栏的左上角、应用程序名称的左侧有一个图标?如果您单击它,它具有诸如恢复,最小化,最大化等选项。。等等 在许多程序中,它们有额外的菜单选项(Windows提供的默认菜单选项除外)。如何在C#Winforms中实现此功能?有关“在Windows窗体应用程序中自定义系统菜单”的教程: 片段: 导入user32.dll以访问更改系统菜单所需的函数 [DllImport("user32.dll")] private static extern IntPtr GetSyste

Windows应用程序在标题栏的左上角、应用程序名称的左侧有一个图标?如果您单击它,它具有诸如
恢复
最小化
最大化
等选项。。等等

在许多程序中,它们有额外的菜单选项(Windows提供的默认菜单选项除外)。如何在C#Winforms中实现此功能?

有关“在Windows窗体应用程序中自定义系统菜单”的教程:

片段:

导入user32.dll以访问更改系统菜单所需的函数

[DllImport("user32.dll")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("user32.dll")]
private static extern bool InsertMenu (IntPtr hMenu, 
    Int32 wPosition, Int32 wFlags, Int32 wIDNewItem, 
    string lpNewItem);
获取当前系统菜单,并向其中添加项目:

IntPtr sysMenuHandle = GetSystemMenu(this.Handle, false);
//It would be better to find the position at run time of the 'Close' item, but...

InsertMenu(sysMenuHandle, 5, MF_BYPOSITION | MF_SEPARATOR, 0, string.Empty);
InsertMenu(sysMenuHandle, 6, MF_BYPOSITION , IDM_CUSTOMITEM1, "Item 1");
InsertMenu(sysMenuHandle, 7, MF_BYPOSITION , IDM_CUSTOMITEM2, "Item 2");

public const Int32 WM_SYSCOMMAND = 0x112;
public const Int32 MF_SEPARATOR = 0x800;
public const Int32 MF_BYPOSITION = 0x400;
public const Int32 MF_STRING = 0x0;
public const Int32 IDM_CUSTOMITEM1  = 1000;
public const Int32 IDM_CUSTOMITEM2 = 1001;
捕获新自定义项的选择,以便为其分配方法:

protected override void WndProc(ref Message m)
{
    if(m.Msg == WM_SYSCOMMAND)
    {
        switch(m.WParam.ToInt32())
        {
            case IDM_CUSTOMITEM1 : 
                MessageBox.Show("Clicked 'Item 1'");
                return;
            case IDM_CUSTOMITEM1 :
                MessageBox.Show("Clicked 'item 2'");
                return;
            default:
                break;
        } 
    }
    base.WndProc(ref m);
}

你能提供这些说明的一个片段以及你的链接吗?