[System.Runtime.InteropServices.DllImport("user32")]
private static extern IntPtr GetSystemMenu(IntPtr hwnd,bool bRevert);
[System.Runtime.InteropServices.DllImport("user32")]
private static extern IntPtr AppendMenu(IntPtr hMenu,int wFlags,IntPtr wIDNewItem,string lpNewItem);
const int MF_POPUP = 0x0010;
const int MF_SEPARATOR = 0x0800;
将 mainMenu1 菜单添加到系统菜单
private void Form1_Load(object sender, System.EventArgs e)
{
IntPtr mnuSystem;
mnuSystem=GetSystemMenu(this.Handle,false);
AppendMenu(mnuSystem, MF_SEPARATOR, (IntPtr)0, "");
for(int i= 0;i<this.mainMenu1.MenuItems.Count;i++)
{
AppendMenu(mnuSystem,MF_POPUP,this.mainMenu1.MenuItems[i].Handle,this.mainMenu1.MenuItems[i].Text);
}
}