private bool ProcessMouseMessage(IntPtr hWnd, int msg, int x, int y) { if (!this.processingMessage) { new NamedPermissionSet("FullTrust").Assert(); foreach (BehaviorService.AdornerWindow window in BehaviorService.AdornerWindow.AdornerWindowList) { this.currentAdornerWindow = window; IntPtr handle = window.DesignerFrame.Handle; if (window.ProcessingDrag || ((hWnd != handle) && System.Design.SafeNativeMethods.IsChild(new HandleRef(this, handle), new HandleRef(this, hWnd)))) { int num; System.Design.UnsafeNativeMethods.GetWindowThreadProcessId(new HandleRef(null, hWnd), out num); if (num != this.thisProcessID) { return false; } try { this.processingMessage = true; System.Design.NativeMethods.POINT pt = new System.Design.NativeMethods.POINT { x = x, y = y }; System.Design.NativeMethods.MapWindowPoints(IntPtr.Zero, window.Handle, pt, 1); Message m = Message.Create(hWnd, msg, IntPtr.Zero, (IntPtr) MAKELONG(pt.y, pt.x)); if (m.Msg == 0x201) { this.lastLButtonDownTimeStamp = System.Design.UnsafeNativeMethods.GetMessageTime(); } else if ((m.Msg == 0x203) && (System.Design.UnsafeNativeMethods.GetMessageTime() == this.lastLButtonDownTimeStamp)) { return true; } if (!window.WndProcProxy(ref m, pt.x, pt.y)) { return true; } break; } finally { this.processingMessage = false; } } } } return false; }
private unsafe IntPtr MouseHookProc(int nCode, IntPtr wparam, IntPtr lparam) { if (this.isHooked && (nCode == 0)) { System.Design.NativeMethods.MOUSEHOOKSTRUCT* mousehookstructPtr = (System.Design.NativeMethods.MOUSEHOOKSTRUCT*) lparam; if (mousehookstructPtr != null) { try { if (this.ProcessMouseMessage(mousehookstructPtr->hWnd, (int) ((long) wparam), mousehookstructPtr->pt_x, mousehookstructPtr->pt_y)) { return (IntPtr) 1; } } catch (Exception exception) { this.currentAdornerWindow.Capture = false; if (exception != CheckoutException.Canceled) { this.currentAdornerWindow.behaviorService.ShowError(exception); } if (System.Windows.Forms.ClientUtils.IsCriticalException(exception)) { throw; } } finally { this.currentAdornerWindow = null; } } } return System.Design.UnsafeNativeMethods.CallNextHookEx(new HandleRef(this, this.mouseHookHandle), nCode, wparam, lparam); }