/// <summary> /// Server uses this to return an element in response to WM_GETOBJECT. /// </summary> /// <param name="hwnd">hwnd from the WM_GETOBJECT message</param> /// <param name="wParam">wParam from the WM_GETOBJECT message</param> /// <param name="lParam">lParam from the WM_GETOBJECT message</param> /// <param name="el">element to return</param> /// <returns>Server should return the return value as the lresult return value to the WM_GETOBJECT windows message</returns> public static IntPtr ReturnRawElementProvider(IntPtr hwnd, IntPtr wParam, IntPtr lParam, IRawElementProviderSimple el) { ValidateArgument(hwnd != IntPtr.Zero, nameof(SRID.HwndMustBeNonNULL)); ValidateArgumentNonNull(el, "el"); return(UiaCoreProviderApi.UiaReturnRawElementProvider(hwnd, wParam, lParam, el)); }
public static IntPtr ReturnRawElementProvider(IntPtr hwnd, IntPtr wParam, IntPtr lParam, IRawElementProviderSimple el) { Utility.ValidateArgument(hwnd != IntPtr.Zero, "HWND must not be null"); Utility.ValidateArgumentNonNull(el, "el"); return(UiaCoreProviderApi.UiaReturnRawElementProvider(hwnd, wParam, lParam, el)); }
protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) { const double wheelDelta = 120.0; const long UiaRootObjectId = -25; uint timestamp = unchecked ((uint)GetMessageTime()); RawInputEventArgs e = null; var shouldTakeFocus = false; switch ((WindowsMessage)msg) { case WindowsMessage.WM_ACTIVATE: { var wa = (WindowActivate)(ToInt32(wParam) & 0xffff); switch (wa) { case WindowActivate.WA_ACTIVE: case WindowActivate.WA_CLICKACTIVE: { Activated?.Invoke(); UpdateInputMethod(GetKeyboardLayout(0)); break; } case WindowActivate.WA_INACTIVE: { Deactivated?.Invoke(); break; } } return(IntPtr.Zero); } case WindowsMessage.WM_NCCALCSIZE: { if (ToInt32(wParam) == 1 && !HasFullDecorations || _isClientAreaExtended) { return(IntPtr.Zero); } break; } case WindowsMessage.WM_CLOSE: { bool?preventClosing = Closing?.Invoke(); if (preventClosing == true) { return(IntPtr.Zero); } BeforeCloseCleanup(false); // Used to distinguish between programmatic and regular close requests. _isCloseRequested = true; break; } case WindowsMessage.WM_DESTROY: { UiaCoreProviderApi.UiaReturnRawElementProvider(_hwnd, IntPtr.Zero, IntPtr.Zero, null); // We need to release IMM context and state to avoid leaks. if (Imm32InputMethod.Current.HWND == _hwnd) { Imm32InputMethod.Current.ClearLanguageAndWindow(); } //Window doesn't exist anymore _hwnd = IntPtr.Zero; //Remove root reference to this class, so unmanaged delegate can be collected s_instances.Remove(this); Closed?.Invoke(); _mouseDevice.Dispose(); _touchDevice?.Dispose(); //Free other resources Dispose(); return(IntPtr.Zero); } case WindowsMessage.WM_DPICHANGED: { var dpi = ToInt32(wParam) & 0xffff; var newDisplayRect = Marshal.PtrToStructure <RECT>(lParam); _scaling = dpi / 96.0; ScalingChanged?.Invoke(_scaling); using (SetResizeReason(PlatformResizeReason.DpiChange)) { SetWindowPos(hWnd, IntPtr.Zero, newDisplayRect.left, newDisplayRect.top, newDisplayRect.right - newDisplayRect.left, newDisplayRect.bottom - newDisplayRect.top, SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE); } return(IntPtr.Zero); } case WindowsMessage.WM_KEYDOWN: case WindowsMessage.WM_SYSKEYDOWN: { e = new RawKeyEventArgs( WindowsKeyboardDevice.Instance, timestamp, _owner, RawKeyEventType.KeyDown, KeyInterop.KeyFromVirtualKey(ToInt32(wParam), ToInt32(lParam)), WindowsKeyboardDevice.Instance.Modifiers); break; } case WindowsMessage.WM_SYSCOMMAND: // Disable system handling of Alt/F10 menu keys. if ((SysCommands)wParam == SysCommands.SC_KEYMENU && HighWord(ToInt32(lParam)) <= 0) { return(IntPtr.Zero); } break; case WindowsMessage.WM_MENUCHAR: { // mute the system beep return((IntPtr)((int)MenuCharParam.MNC_CLOSE << 16)); } case WindowsMessage.WM_KEYUP: case WindowsMessage.WM_SYSKEYUP: { e = new RawKeyEventArgs( WindowsKeyboardDevice.Instance, timestamp, _owner, RawKeyEventType.KeyUp, KeyInterop.KeyFromVirtualKey(ToInt32(wParam), ToInt32(lParam)), WindowsKeyboardDevice.Instance.Modifiers); break; } case WindowsMessage.WM_CHAR: { // Ignore control chars and chars that were handled in WM_KEYDOWN. if (ToInt32(wParam) >= 32 && !_ignoreWmChar) { e = new RawTextInputEventArgs(WindowsKeyboardDevice.Instance, timestamp, _owner, new string((char)ToInt32(wParam), 1)); } break; } case WindowsMessage.WM_LBUTTONDOWN: case WindowsMessage.WM_RBUTTONDOWN: case WindowsMessage.WM_MBUTTONDOWN: case WindowsMessage.WM_XBUTTONDOWN: { shouldTakeFocus = ShouldTakeFocusOnClick; if (ShouldIgnoreTouchEmulatedMessage()) { break; } e = new RawPointerEventArgs( _mouseDevice, timestamp, _owner, (WindowsMessage)msg switch { WindowsMessage.WM_LBUTTONDOWN => RawPointerEventType.LeftButtonDown, WindowsMessage.WM_RBUTTONDOWN => RawPointerEventType.RightButtonDown, WindowsMessage.WM_MBUTTONDOWN => RawPointerEventType.MiddleButtonDown, WindowsMessage.WM_XBUTTONDOWN => HighWord(ToInt32(wParam)) == 1 ? RawPointerEventType.XButton1Down : RawPointerEventType.XButton2Down }, DipFromLParam(lParam), GetMouseModifiers(wParam)); break; }
public static IntPtr ReturnRawElementProvider(IntPtr hwnd, IntPtr wParam, IntPtr lParam, IRawElementProviderSimple el) { AutomationInteropProvider.ValidateArgument(hwnd != IntPtr.Zero, "HwndMustBeNonNULL"); AutomationInteropProvider.ValidateArgumentNonNull(el, "el"); return(UiaCoreProviderApi.UiaReturnRawElementProvider(hwnd, wParam, lParam, el)); }