private void button54_Click(object sender, EventArgs e) { WndProc proc = MyWndProc; IntPtr result = Win32API.CallWindowProc(proc, this.Handle, WindowsMsg.WM_SIZE, (IntPtr)0, (IntPtr)0); Console.WriteLine(result); }
/// <summary> /// 接收到消息 /// </summary> /// <param name="m"></param> public virtual int MessageReceived(IntPtr hWnd, int Msg, int wParam, int lParam) { //TODO: 燃烧吧,大脑!参考:Systen.Windwos.Forms.Control.WndProc(ref Message m) 方法; //TODO: 鼠标移动:判断当前响应的控件;鼠标按压、抬起、点击、双击等,调用控件 OnMouseXXX(注意鼠标按压后仍移动,并移动到别处抬起的情况),由控件再回调鼠标事件;此容器刚再向外部触发封装好的自定义事件; //Console.WriteLine($"{DateTime.Now.ToString()} - {hWnd} : {Msg} ({wParam}, {lParam})"); switch (Msg) { //case } //放行消息 return(Win32API.CallWindowProc(this.OldWndProcHandle, hWnd, Msg, wParam, lParam)); }
/// <summary> /// Function to handle raw input messages on the window. /// </summary> /// <param name="hwnd">The window handle.</param> /// <param name="msg">The message.</param> /// <param name="wParam">The parameter.</param> /// <param name="lParam">The parameter.</param> /// <returns>The result of the procedure.</returns> private IntPtr RawWndProc(IntPtr hwnd, WindowMessages msg, IntPtr wParam, IntPtr lParam) { if (_disposed) { throw new ObjectDisposedException(Resources.GORINP_RAW_HOOK_STILL_ACTIVE); } if (msg != WindowMessages.RawInput) { // If we have a pointing device set as exclusive, then block all WM_MOUSE messages. if ((ExclusiveDevices & InputDeviceType.PointingDevice) == InputDeviceType.PointingDevice) { switch (msg) { case WindowMessages.XButtonDoubleClick: case WindowMessages.LeftButtonDoubleClick: case WindowMessages.RightButtonDoubleClick: case WindowMessages.MiddleButtonDoubleClick: case WindowMessages.LeftButtonDown: case WindowMessages.LeftButtonUp: case WindowMessages.RightButtonDown: case WindowMessages.RightButtonUp: case WindowMessages.MiddleButtonDown: case WindowMessages.MiddleButtonUp: case WindowMessages.XButtonDown: case WindowMessages.XButtonUp: case WindowMessages.MouseMove: case WindowMessages.MouseWheel: return(IntPtr.Zero); } } // ReSharper disable once InvertIf if ((ExclusiveDevices & InputDeviceType.Keyboard) == InputDeviceType.Keyboard) { switch (msg) { case WindowMessages.KeyDown: case WindowMessages.KeyUp: case WindowMessages.Char: case WindowMessages.UniChar: case WindowMessages.AppCommand: case WindowMessages.DeadChar: case WindowMessages.HotKey: return(IntPtr.Zero); case WindowMessages.SysKeyDown: var vKey = (VirtualKeys)wParam; // Allow Alt+F4, Alt+Tab and Ctrl + Escape return(vKey == VirtualKeys.F4 ? Win32API.CallWindowProc(_oldWndProc, hwnd, msg, wParam, lParam) : IntPtr.Zero); } } return(Win32API.CallWindowProc(_oldWndProc, hwnd, msg, wParam, lParam)); } var inputMessage = new Message { HWnd = hwnd, Msg = (int)msg, LParam = lParam, WParam = wParam }; return(MessageFilter.PreFilterMessage(ref inputMessage) ? inputMessage.Result : Win32API.CallWindowProc(_oldWndProc, hwnd, msg, wParam, lParam)); }