您的位置:首页 > 编程语言 > C#

C#给任务栏右键菜单增加按钮

2008-07-03 17:19 357 查看
using System.Runtime.InteropServices;

[DllImport("user32.dll")]

private static extern int GetSystemMenu(int hwnd, int bRevert);



[DllImport("user32.dll")]

private static extern int AppendMenu(

int hMenu, int Flagsw, int IDNewItem, string lpNewItem);



private void SetupSystemMenu()



...{

// get handle to system menu

int menu = GetSystemMenu(this.Handle.ToInt32(), 0);

// add a separator

AppendMenu(menu, 0xA00, 0, null);

// add an item with a unique ID

AppendMenu(menu, 0, 1234, "跳至URL");

AppendMenu(menu, 0, 1235, "关于HTML帮助");

}



protected override void WndProc(ref Message m)



...{

base.WndProc(ref m);

// WM_SYSCOMMAND is 0x112

if (m.Msg == 0x112)



...{

// check for my new menu item ID

if (m.WParam.ToInt32() == 1234)



...{

// show About box here...

MessageBox.Show("Btn One");

}

if (m.WParam.ToInt32() == 1235)



...{

// show About box here...

MessageBox.Show("Btn Two");

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: