C#增加任务栏系统右键菜单项目

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
...{
    public partial class Form1 : Form
    ...{
        Class1 SkinClass = new Class1();

        public Form1()
        ...{
            InitializeComponent();

            SetupSystemMenu();
        }

        [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    separator 
            AppendMenu(menu, 0xA00, 0, null);
            //   add   an   item   with    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");
                }
            }
        }

    }
}

posted @ 2009-08-18 15:54  oraclejava  阅读(731)  评论(0)    收藏  举报