利用IMessageFilter屏蔽Winform右键

来源:互联网 发布:js rgb转16进制 编辑:程序博客网 时间:2024/05/22 17:03

由于项目需要winform中嵌入flash,flash传统的右键不屏蔽的话很麻烦。

办法有多种,这里仅出示利用IMessageFilter屏蔽Winform右键的实例:

 

 

using System;
using System.Windows.Forms;

namespace MyWinform
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            MesFilter mf = new MesFilter();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.AddMessageFilter(mf);
            Application.Run(new Form1());
            Application.RemoveMessageFilter(mf);

        
        }
    }

    class MesFilter : IMessageFilter
    {
        public bool PreFilterMessage(ref   Message m)
        {
            Console.WriteLine(m);
            if (m.Msg == 0x204 || m.Msg == 0x205)
            {
                return true;
            }
            return false;
        }
    }

}