C# 获取系统消息监听

 public HomeWindowNew()
        {
            InitializeComponent();

            SourceInitialized += HandleInitialized;
           
        }

        private void HandleInitialized(object sender, EventArgs e)
        {
            IntPtr wptr = new WindowInteropHelper(this).Handle;
            HwndSource hs = HwndSource.FromHwnd(wptr);
            hs.AddHook(new HwndSourceHook(WpfHandleWinowMsg));
        }

        private IntPtr WpfHandleWinowMsg(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            Console.WriteLine("00000" + msg);
            switch (msg)
            {
                case 1:
                    break;
                case 2:
                    break;
                default:

                    break;
            }
            return IntPtr.Zero;
        }

 

你可能感兴趣的:(C#)