c#用IMessageFilter拦截键盘消息

来源:互联网 发布:知乎恐怖提问 编辑:程序博客网 时间:2024/06/08 00:39


 public class MessageFilter : IMessageFilter
        {
            [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
            public bool PreFilterMessage(ref Message m)
            {
                if (m.Msg == 0x0100)
                {
                    MessageBox.Show(m.Msg.ToString() + "   :" + m.WParam.ToInt32());
            
                               }
                return false;
            }
        }




 static void Main()
        {
            Application.EnableVisualStyles();
            Application.AddMessageFilter(new WindowsFormsApplication9.Form1.MessageFilter());
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

0 0
原创粉丝点击