/// <summary> /// /// </summary> /// <param name="keyMessage"></param> /// <param name="keyCode"></param> /// <param name="scanCode"></param> /// <param name="timeStamp"></param> public KeyDataEventArgs(WM keyMessage, int keyCode, int scanCode, int timeStamp) { KeyMessage = keyMessage; KeyCode = keyCode; ScanCode = scanCode; TimeStamp = timeStamp; }
private static IntPtr KeyboardHookProc(int nCode, WM wParam, IntPtr lParam) { bool handled = false; if (nCode >= 0) { KeyboardHookStruct kbHookStruct = (KeyboardHookStruct) Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct)); Keys keyData = (Keys)kbHookStruct.vkCode; KeyEventArgs e = new KeyEventArgs(keyData); if (s_KeyDown != null && (wParam == WM.KEYDOWN || wParam == WM.SYSKEYDOWN)) { s_KeyDown.Invoke(null, e); handled = e.Handled; } if (s_KeyUp != null && (wParam == WM.KEYUP || wParam == WM.SYSKEYUP)) { s_KeyUp.Invoke(null, e); handled = e.Handled; } if (handled) { return new IntPtr(-1); } } return CallNextHookEx(s_KeyboardHookHandle, nCode, wParam, lParam); }
private static int OnKey(HC nCode, WM wParam, IntPtr lParam) { bool is_key = (wParam == WM.KEYDOWN || wParam == WM.SYSKEYDOWN || wParam == WM.KEYUP || wParam == WM.SYSKEYUP); if (nCode == HC.ACTION && is_key) { // Retrieve key event data from native structure var data = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT)); bool is_injected = (data.flags & LLKHF.INJECTED) != 0; Log.Debug("{0}: OnKey(HC.{1}, WM.{2}, [vk:0x{3:X02} sc:0x{4:X02} flags:{5}])", is_injected ? "Ignored Injected Event" : "Event", nCode, wParam, (int)data.vk, (int)data.sc, data.flags); if (!is_injected) { if (Composer.OnKey(wParam, data.vk, data.sc, data.flags)) { // Do not process further: that key was for us. return -1; } } } else { Log.Debug("Ignored Event: OnKey({0}, {1})", nCode, wParam); } return NativeMethods.CallNextHookEx(m_hook, nCode, wParam, lParam); }
bool OnKeyHook(int code, WM wParam, KBDLLHOOKSTRUCT lParam, Hooker hooker) { if (lParam.vkCode == 44 && wParam == WM.KEYUP) { takeScreenshot(); } return false; }
/// <summary> /// Get input from the keyboard hook; return true if the key was handled /// and needs to be removed from the input chain. /// </summary> public static bool OnKey(WM ev, VK vk, SC sc, LLKHF flags) { // Remember when the user touched a key for the last time m_last_key_time = DateTime.Now; // Do nothing if we are disabled if (m_disabled) { return false; } int dead_key = SaveDeadKey(); bool ret = OnKeyInternal(ev, vk, sc, flags); RestoreDeadKey(dead_key); return ret; }
private static int OnKey(HC nCode, WM wParam, IntPtr lParam) { if (nCode == HC.ACTION) { // Retrieve event data from native structure var data = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT)); bool is_key = (wParam == WM.KEYDOWN || wParam == WM.SYSKEYDOWN || wParam == WM.KEYUP || wParam == WM.SYSKEYUP); bool is_injected = (data.flags & LLKHF.INJECTED) != 0; if (is_key && !is_injected) { if (Composer.OnKey(wParam, data.vk, data.sc, data.flags)) { // Do not process further: that key was for us. return -1; } } } return NativeMethods.CallNextHookEx(m_hook, nCode, wParam, lParam); }
private IntPtr _HandleSettingChange(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) { this._FixupFrameworkIssues(); handled = false; return(IntPtr.Zero); }
private IntPtr _HandleMouseMove(IntPtr hWnd, WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) { //Mouse move in header area if (_isDrag) { var deltaTine = DateTime.Now - _hitTime; if (deltaTine.TotalMilliseconds < _dragDelay) { handled = false; return(IntPtr.Zero); } _hitTime = DateTime.Now; var currentPoint = CursorPosition.GetCursorPosition(); var delta = currentPoint - _startPoint; NativeMethods.MoveWindow(hWnd, _windowPosition.Left + (int)delta.X, _windowPosition.Top + (int)delta.Y, _windowPosition.Width, _windowPosition.Height, true); var args = new RoutedEventArgs(ChromeBase.DragMoveEvent, this); _window?.RaiseEvent(args); } else if (_isResize) { var deltaTine = DateTime.Now - _hitTime; if (deltaTine.TotalMilliseconds < _resizeDelay) { handled = false; return(IntPtr.Zero); } _hitTime = DateTime.Now; var currentPoint = CursorPosition.GetCursorPosition(); var delta = currentPoint - _startPoint; switch (_rDirection) { case ResizeDirection.Right: NativeMethods.MoveWindow(hWnd, _windowPosition.Left, _windowPosition.Top, _windowPosition.Width + (int)delta.X, _windowPosition.Height, true); break; case ResizeDirection.Left: NativeMethods.MoveWindow(hWnd, _windowPosition.Left + (int)delta.X, _windowPosition.Top, _windowPosition.Width - (int)delta.X, _windowPosition.Height, true); break; case ResizeDirection.Bottom: NativeMethods.MoveWindow(hWnd, _windowPosition.Left, _windowPosition.Top, _windowPosition.Width, _windowPosition.Height + (int)delta.Y, true); break; case ResizeDirection.Top: NativeMethods.MoveWindow(hWnd, _windowPosition.Left, _windowPosition.Top + (int)delta.Y, _windowPosition.Width, _windowPosition.Height - (int)delta.Y, true); break; case ResizeDirection.TopRight: NativeMethods.MoveWindow(hWnd, _windowPosition.Left, _windowPosition.Top + (int)delta.Y, _windowPosition.Width + (int)delta.X, _windowPosition.Height - (int)delta.Y, true); break; case ResizeDirection.BottomRight: NativeMethods.MoveWindow(hWnd, _windowPosition.Left, _windowPosition.Top, _windowPosition.Width + (int)delta.X, _windowPosition.Height + (int)delta.Y, true); break; case ResizeDirection.TopLeft: NativeMethods.MoveWindow(hWnd, _windowPosition.Left + (int)delta.X, _windowPosition.Top + (int)delta.Y, _windowPosition.Width - (int)delta.X, _windowPosition.Height - (int)delta.Y, true); break; case ResizeDirection.BottomLeft: NativeMethods.MoveWindow(hWnd, _windowPosition.Left + (int)delta.X, _windowPosition.Top, _windowPosition.Width - (int)delta.X, _windowPosition.Height + (int)delta.Y, true); break; } } handled = false; return(IntPtr.Zero); }
protected virtual IntPtr OnMessage(WM message, IntPtr wParam, IntPtr lParam) { return(NativeMethods.DefWindowProc(_hwnd, message, wParam, lParam)); }
public static extern IntPtr SendMessage(IntPtr hWnd, WM Msg, IntPtr wParam, IntPtr lParam);
internal static extern long WindowProc(IntPtr hwnd, WM uMsg, IntPtr wParam, IntPtr lParam);
public static extern int SendMessage(IntPtr hWnd, WM Msg, int wParam, int lParam);
public static HRESULT ChangeWindowMessageFilterEx(IntPtr hwnd, WM message, MSGFLT action, out MSGFLTINFO filterInfo) { filterInfo = MSGFLTINFO.NONE; bool ret; // This origins of this API were added for Vista. The Ex version was added for Windows 7. // If we're not on either, then this message filter isolation doesn't exist. if (!Utility.IsOSVistaOrNewer) { return HRESULT.S_FALSE; } // If we're on Vista rather than Win7 then we can't use the Ex version of this function. // The Ex version is preferred if possible because this results in process-wide modifications of the filter // and is deprecated as of Win7. if (!Utility.IsOSWindows7OrNewer) { // Note that the Win7 MSGFLT_ALLOW/DISALLOW enum values map to the Vista MSGFLT_ADD/REMOVE ret = _ChangeWindowMessageFilter(message, action); if (!ret) { return (HRESULT)Win32Error.GetLastError(); } return HRESULT.S_OK; } var filterstruct = new CHANGEFILTERSTRUCT { cbSize = (uint)Marshal.SizeOf(typeof(CHANGEFILTERSTRUCT)) }; ret = _ChangeWindowMessageFilterEx(hwnd, message, action, ref filterstruct); if (!ret) { return (HRESULT)Win32Error.GetLastError(); } filterInfo = filterstruct.ExtStatus; return HRESULT.S_OK; }
private static extern bool PostThreadMessage(int id, WM msg, IntPtr wParam, IntPtr lParam);
internal static extern IntPtr CallWindowProcW( IntPtr wndProc, IntPtr hWnd, WM msg, IntPtr wParam, IntPtr lParam);
public static IntPtr SendMessage([NotNull] this Window window, WM Msg, SC wParam, IntPtr lParam = default) => SendMessage(window.GetWindowHandle(), (uint)Msg, (IntPtr)wParam, lParam == default ? (IntPtr)' ' : lParam);
internal static extern IntPtr SendMessage(IntPtr hWnd, WM msg, IntPtr wParam, IntPtr lParam);
public static IntPtr SendMessage([NotNull] this Window window, WM Msg, IntPtr wParam, IntPtr lParam) => SendMessage(window.GetWindowHandle(), Msg, wParam, lParam);
protected override IntPtr WndProc(IntPtr hWnd, uint message, IntPtr wParam, IntPtr lParam) { WM wmMsg = (WM)message; switch (wmMsg) { case WM.PARENTNOTIFY: { WM wParmLw = (WM)LOWORD((int)wParam); switch (wParmLw) { case WM.LBUTTONDOWN: _dwmFramelessController?.InitiateWindowDrag(hWnd, lParam); return(IntPtr.Zero); default: break; } } break; case WM.DWMCOMPOSITIONCHANGED: _dwmFramelessController?.HandleCompositionchanged(); return(IntPtr.Zero); case WM.LBUTTONDOWN: /* Allow window dragging from any point */ var handlerNullable = _framelessInfo?.Handle; if (handlerNullable.HasValue) { ReleaseCapture(); SendMessageW(handlerNullable.Value, WM.NCLBUTTONDOWN, (IntPtr)HT.CAPTION, IntPtr.Zero); } return(IntPtr.Zero); case WM.NCACTIVATE: /* DefWindowProc won't repaint the window border if lParam (normally a * HRGN) is -1. This is recommended in: * https://blogs.msdn.microsoft.com/wpfsdk/2008/09/08/custom-window-chrome-in-wpf/ */ return(base.WndProc(hWnd, message, wParam, new IntPtr(-1))); case WM.NCCALCSIZE: _dwmFramelessController?.HandleNCCalcsize(wParam, lParam); return(IntPtr.Zero); case WM.NCHITTEST: if (_framelessInfo != null) { _framelessInfo.ResizeInMotion = true; var hitTestResultNullable = _dwmFramelessController?.HandleNCHittest(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); _framelessInfo.ResizeInMotion = false; return(hitTestResultNullable.HasValue ? hitTestResultNullable.Value : IntPtr.Zero); } return(IntPtr.Zero); case WM.NCPAINT: /* Only block WM_NCPAINT when composition is disabled. If it's blocked * when composition is enabled, the window shadow won't be drawn. */ var isComposistionEnabedNullable = _framelessInfo?.IsCompositionEnabled; var isComposistionEnabed = isComposistionEnabedNullable.HasValue ? isComposistionEnabedNullable.Value : false; if (!isComposistionEnabed) { return(IntPtr.Zero); } break; case WM.NCUAHDRAWCAPTION: case WM.NCUAHDRAWFRAME: /* These undocumented messages are sent to draw themed window borders. * Block them to prevent drawing borders over the client area. */ return(IntPtr.Zero); case WM.SETICON: case WM.SETTEXT: /* Disable painting while these messages are handled to prevent them * from drawing a window caption over the client area, but only when * composition and theming are disabled. These messages don't paint * when composition is enabled and blocking WM_NCUAHDRAWCAPTION should * be enough to prevent painting when theming is enabled. */ isComposistionEnabedNullable = _framelessInfo?.IsCompositionEnabled; isComposistionEnabed = isComposistionEnabedNullable.HasValue ? isComposistionEnabedNullable.Value : false; var isThemeEnabledNullable = _framelessInfo?.IsThemeEnabled; var isThemeEnabledEnabed = isThemeEnabledNullable.HasValue ? isThemeEnabledNullable.Value : false; if (!isComposistionEnabed && !isThemeEnabledEnabed) { var msgResult = _dwmFramelessController?.HandleMessageInvisible(wmMsg, wParam, lParam); return(msgResult.HasValue ? msgResult.Value : IntPtr.Zero); } break; case WM.THEMECHANGED: _dwmFramelessController?.HandleThemechanged(); break; case WM.WINDOWPOSCHANGED: WINDOWPOS windPos = (WINDOWPOS)Marshal.PtrToStructure(lParam, typeof(WINDOWPOS)); _dwmFramelessController?.HandleWindowPosChanged(windPos); return(IntPtr.Zero); case WM.CAPTURECHANGED: if (lParam == IntPtr.Zero) { _dwmFramelessController?.ResetDragOperation(); } return(IntPtr.Zero); default: break; } return(base.WndProc(hWnd, message, wParam, lParam)); }
public static extern nint SendMessageW( IntPtr hWnd, WM Msg, nint wParam = default, nint lParam = default);
private IntPtr _HandleWindowPosChanged(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) { // http://blogs.msdn.com/oldnewthing/archive/2008/01/15/7113860.aspx // The WM_WINDOWPOSCHANGED message is sent at the end of the window // state change process. It sort of combines the other state change // notifications, WM_MOVE, WM_SIZE, and WM_SHOWWINDOW. But it doesn't // suffer from the same limitations as WM_SHOWWINDOW, so you can // reliably use it to react to the window being shown or hidden. _UpdateSystemMenu(null); if (!_isGlassEnabled) { Assert.IsNotDefault(lParam); var wp = (WINDOWPOS)Marshal.PtrToStructure(lParam, typeof(WINDOWPOS)); _SetRoundingRegion(wp); } // Still want to pass this to DefWndProc handled = false; return IntPtr.Zero; }
public static extern IntPtr SendDlgItemMessageW(IntPtr hDlg, DialogItemID nIDDlgItem, WM Msg, IntPtr wParam = default, IntPtr lParam = default);
private IntPtr WndProc(HWND hwnd, WM msg, IntPtr wParam, IntPtr lParam, IntPtr id, IntPtr data) { IntPtr retval = IntPtr.Zero; try { retval = WndProcOverride(hwnd, msg, wParam, lParam, id, data); } finally { if (_hwnd != HWND.NULL) { Debug.Assert(_hwnd == hwnd); if (msg == WM.NCDESTROY) { Dispose(); } else if (msg == _disposeMessage && wParam == _wndprocPtr) { DisposeHelper(lParam == IntPtr.Zero ? false : true); } } } return retval; }
public static int GetMessageInt(IntPtr hwnd, WM msg) { return((int)SendMessage(hwnd, (uint)msg, (uint)0, (uint)0)); }
private static IntPtr _WndProc(IntPtr hwnd, WM msg, IntPtr wParam, IntPtr lParam) { var ret = IntPtr.Zero; MessageWindow hwndWrapper = null; if (msg == WM.CREATE) { var createStruct = (CREATESTRUCT)Marshal.PtrToStructure(lParam, typeof(CREATESTRUCT)); var gcHandle = GCHandle.FromIntPtr(createStruct.lpCreateParams); hwndWrapper = (MessageWindow)gcHandle.Target; SWindowLookup.Add(hwnd, hwndWrapper); } else { if (!SWindowLookup.TryGetValue(hwnd, out hwndWrapper)) { return NativeMethods.DefWindowProc(hwnd, msg, wParam, lParam); } } Assert.IsNotNull(hwndWrapper); var callback = hwndWrapper._wndProcCallback; if (callback != null) { ret = callback(hwnd, msg, wParam, lParam); } else { ret = NativeMethods.DefWindowProc(hwnd, msg, wParam, lParam); } if (msg != WM.NCDESTROY) return ret; hwndWrapper._Dispose(true, true); GC.SuppressFinalize(hwndWrapper); return ret; }
public static int SendMessage(IntPtr hwnd, WM msg, uint param1, uint param2) { return((int)SendMessage(hwnd, (uint)msg, param1, param2)); }
public static extern bool DwmDefWindowProc(IntPtr hwnd, WM msg, IntPtr wParam, IntPtr lParam, out IntPtr plResult);
private IntPtr _HandleMove(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) { // This is only intercepted to deal with bugs in Window in .Net 3.5 and below. Assert.IsTrue(Utility.IsPresentationFrameworkVersionLessThan4); if (_isUserResizing) { _hasUserMovedWindow = true; } handled = false; return IntPtr.Zero; }
private static extern bool _ChangeWindowMessageFilterEx(IntPtr hwnd, WM message, MSGFLT action, [In, Out, Optional] ref CHANGEFILTERSTRUCT pChangeFilterStruct);
private IntPtr _HandleNCCalcSize(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) { // lParam is an [in, out] that can be either a RECT* (wParam == FALSE) or an NCCALCSIZE_PARAMS*. // Since the first field of NCCALCSIZE_PARAMS is a RECT and is the only field we care about // we can unconditionally treat it as a RECT. // Since we always want the client size to equal the window size, we can unconditionally handle it // without having to modify the parameters. handled = true; return new IntPtr((int)WVR.REDRAW); }
private IntPtr _HandleNCCalcSize(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) { handled = true; return(new IntPtr(768)); }
private IntPtr _HandleNCRButtonUp(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) { // Emulate the system behavior of clicking the right mouse button over the caption area // to bring up the system menu. if (HT.CAPTION == (HT)wParam.ToInt32()) { if (_window.ContextMenu != null) { _window.ContextMenu.Placement = PlacementMode.MousePoint; _window.ContextMenu.IsOpen = true; } else if (WindowChrome.GetWindowChrome(_window).ShowSystemMenu) SystemCommands.ShowSystemMenuPhysicalCoordinates(_window, new Point(Utility.GET_X_LPARAM(lParam), Utility.GET_Y_LPARAM(lParam))); } handled = false; return IntPtr.Zero; }
protected virtual IntPtr WndProc(IntPtr hWnd, uint message, IntPtr wParam, IntPtr lParam) { WM wmMsg = (WM)message; switch (wmMsg) { case WM.NCCREATE: { NativeInstance = this; _handle = hWnd; PreCreated(hWnd); break; } case WM.CREATE: { OnCreated(hWnd); var createdEvent = new CreatedEventArgs(_handle, _handle); HostCreated?.Invoke(this, createdEvent); _isInitialized = true; break; } case WM.ERASEBKGND: return(new IntPtr(1)); case WM.NCHITTEST: if (_options.WindowFrameless) { return((IntPtr)HT.CAPTION); } break; case WM.MOVING: { HostMoving?.Invoke(this, new MovingEventArgs()); return(IntPtr.Zero); } case WM.MOVE: { var position = new RECT((int)(short)Interop.PARAM.LOWORD(lParam), (int)(short)Interop.PARAM.HIWORD(lParam), 0, 0); var windowStyle = GetWindowStylePlacement(_options.WindowState); Interop.User32.AdjustWindowRectEx(ref position, (int)windowStyle.Styles, BOOL.FALSE, (int)windowStyle.ExStyles); HostMoved?.Invoke(this, new MovedEventArgs(position.X, position.Y)); return(IntPtr.Zero); } case WM.SIZE: { var innerSize = GetClientSize(); var outerSize = new RECT(0, 0, (int)(short)Interop.PARAM.LOWORD(lParam), (int)(short)Interop.PARAM.HIWORD(lParam)); var windowStyle = GetWindowStylePlacement(_options.WindowState); Interop.User32.AdjustWindowRectEx(ref outerSize, (int)windowStyle.Styles, BOOL.FALSE, (int)windowStyle.ExStyles); HandleSizeChanged(innerSize.Width, innerSize.Height, outerSize.Width, outerSize.Height); break; } case WM.GETMINMAXINFO: { if (HandleMinMaxSizes(lParam)) { return(IntPtr.Zero); } break; } case WM.CLOSE: { if (_handle != IntPtr.Zero && _isInitialized) { HostClose?.Invoke(this, new CloseEventArgs()); } DetachHooks(); DestroyWindow(_handle); break; } case WM.DESTROY: { if (_options.UseOnlyCefMessageLoop) { CefRuntime.QuitMessageLoop(); } PostQuitMessage(0); break; } default: break; } return(DefWindowProcW(hWnd, wmMsg, wParam, lParam)); }
private IntPtr _HandleSettingChange(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) { // There are several settings that can cause fixups for the template to become invalid when changed. // These shouldn't be required on the v4 framework. Assert.IsTrue(Utility.IsPresentationFrameworkVersionLessThan4); _FixupFrameworkIssues(); handled = false; return IntPtr.Zero; }
public static partial BOOL PostMessageW( IntPtr hWnd, WM Msg, nint wParam = default, nint lParam = default);
private IntPtr _HandleDwmCompositionChanged(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) { this._UpdateFrameState(false); handled = false; return(IntPtr.Zero); }
private IntPtr _HandleNCActivate(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) { // Despite MSDN's documentation of lParam not being used, // calling DefWindowProc with lParam set to -1 causes Windows not to draw over the caption. // Directly call DefWindowProc with a custom parameter // which bypasses any other handling of the message. IntPtr lRet = NativeMethods.DefWindowProc(_hwnd, WM.NCACTIVATE, wParam, new IntPtr(-1)); handled = true; return lRet; }
public static extern IntPtr DefWindowProcW(IntPtr hWnd, WM Msg, IntPtr wParam, IntPtr lParam);
private IntPtr _HandleNCHitTest(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) { IntPtr lRet = IntPtr.Zero; handled = false; // Give DWM a chance at this first. if (Utility.IsOSVistaOrNewer && _chromeInfo.GlassFrameThickness != default(Thickness) && _isGlassEnabled) { // If we're on Vista, give the DWM a chance to handle the message first. handled = NativeMethods.DwmDefWindowProc(_hwnd, uMsg, wParam, lParam, out lRet); } // Handle letting the system know if we consider the mouse to be in our effective non-client area. // If DWM already handled this by way of DwmDefWindowProc, then respect their call. if (IntPtr.Zero == lRet) { var mousePosScreen = new Point(Utility.GET_X_LPARAM(lParam), Utility.GET_Y_LPARAM(lParam)); Rect windowPosition = _GetWindowRect(); HT ht = _HitTestNca( DpiHelper.DeviceRectToLogical(windowPosition), DpiHelper.DevicePixelsToLogical(mousePosScreen)); // Don't blindly respect HTCAPTION. // We want UIElements in the caption area to be actionable so run through a hittest first. if (ht != HT.CLIENT) { Point mousePosWindow = mousePosScreen; mousePosWindow.Offset(-windowPosition.X, -windowPosition.Y); mousePosWindow = DpiHelper.DevicePixelsToLogical(mousePosWindow); IInputElement inputElement = _window.InputHitTest(mousePosWindow); if (inputElement != null && WindowChrome.GetIsHitTestVisibleInChrome(inputElement)) { ht = HT.CLIENT; } } handled = true; lRet = new IntPtr((int)ht); } return lRet; }
private IntPtr _HandleSetTextOrIcon(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) { bool modified = _ModifyStyle(WS.VISIBLE, 0); // Setting the caption text and icon cause Windows to redraw the caption. // Letting the default WndProc handle the message without the WS_VISIBLE // style applied bypasses the redraw. IntPtr lRet = NativeMethods.DefWindowProc(_hwnd, uMsg, wParam, lParam); // Put back the style we removed. if (modified) { _ModifyStyle(0, WS.VISIBLE); } handled = true; return lRet; }
private static extern bool _ChangeWindowMessageFilter(WM message, MSGFLT dwFlag);
private IntPtr _HandleSize(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) { const int SIZE_MAXIMIZED = 2; // Force when maximized. // We can tell what's happening right now, but the Window doesn't yet know it's // maximized. Not forcing this update will eventually cause the // default caption to be drawn. WindowState? state = null; if (wParam.ToInt32() == SIZE_MAXIMIZED) { state = WindowState.Maximized; } _UpdateSystemMenu(state); // Still let the default WndProc handle this. handled = false; return IntPtr.Zero; }
private static extern bool _ChangeWindowMessageFilterEx(IntPtr hwnd, WM message, MSGFLT action, [In][Out] ref CHANGEFILTERSTRUCT pChangeFilterStruct);
protected virtual IntPtr WndProcOverride(HWND hwnd, WM msg, IntPtr wParam, IntPtr lParam, IntPtr id, IntPtr data) { // Call the next window proc in the subclass chain. return NativeMethods.DefSubclassProc(hwnd, msg, wParam, lParam); }
private static extern bool _PostMessage(IntPtr hWnd, WM Msg, IntPtr wParam, IntPtr lParam);
static WindowSubclass() { _disposeMessage = NativeMethods.RegisterWindowMessage("WindowSubclass.DisposeMessage"); }
private IntPtr _WndProc(IntPtr hwnd, WM msg, IntPtr wParam, IntPtr lParam) { // Don't do this if called within the SystemParameters2 constructor if (_UpdateTable != null) { List<_SystemMetricUpdate> handlers; if (_UpdateTable.TryGetValue(msg, out handlers)) { Assert.IsNotNull(handlers); foreach (var handler in handlers) { handler(wParam, lParam); } } } return NativeMethods.DefWindowProc(hwnd, msg, wParam, lParam); }
protected virtual IntPtr WndProc(IntPtr hWnd, uint message, IntPtr wParam, IntPtr lParam) { WM wmMsg = (WM)message; switch (wmMsg) { case WM.CREATE: { NativeInstance = this; _handle = hWnd; OnCreated(hWnd); var createdEvent = new CreatedEventArgs(_handle, _handle); HostCreated?.Invoke(this, createdEvent); _isInitialized = true; break; } case WM.ERASEBKGND: return(new IntPtr(1)); case WM.NCHITTEST: if (_options.WindowFrameless) { return((IntPtr)HT.CAPTION); } break; case WM.MOVING: case WM.MOVE: { HostMoving?.Invoke(this, new MovingEventArgs()); return(IntPtr.Zero); } case WM.SIZING: case WM.SIZE: { var size = GetClientSize(); OnSizeChanged(size.Width, size.Height); break; } case WM.GETMINMAXINFO: { if (HandleMinMaxSizes(lParam)) { return(IntPtr.Zero); } break; } case WM.CLOSE: { if (_handle != IntPtr.Zero && _isInitialized) { HostClose?.Invoke(this, new CloseEventArgs()); } DetachHooks(); DestroyWindow(_handle); break; } case WM.DESTROY: { if (_options.UseOnlyCefMessageLoop) { CefRuntime.QuitMessageLoop(); } PostQuitMessage(0); break; } default: break; } return(DefWindowProcW(hWnd, wmMsg, wParam, lParam)); }
public static extern uint SHChangeNotifyRegister(IntPtr hwnd, SHCNRF fSources, SHCNE fEvents, WM wMsg, int cEntries, [MarshalAs(UnmanagedType.LPArray)] SHChangeNotifyEntry[] pfsne);
public static extern IntPtr DefWindowProc(IntPtr hwnd, WM uMsg, IntPtr wParam, IntPtr lParam);
public static extern IntPtr DefWindowProc(IntPtr hWnd, WM Msg, IntPtr wParam, IntPtr lParam);
public static extern bool ChangeWindowMessageFilterEx(IntPtr hWnd, WM msg, ChangeWindowMessageFilterExAction action, IntPtr changeInfo);
public static void PostMessage(IntPtr hWnd, WM Msg, IntPtr wParam, IntPtr lParam) { if (!_PostMessage(hWnd, Msg, wParam, lParam)) { throw new Win32Exception(); } }
private IntPtr _HandleNCCALCSIZE(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) { // lParam is an [in, out] that can be either a RECT* (wParam == FALSE) or an NCCALCSIZE_PARAMS*. // Since the first field of NCCALCSIZE_PARAMS is a RECT and is the only field we care about // we can unconditionally treat it as a RECT. if (this.dpiChanged) { this.dpiChanged = false; handled = this.IgnoreTaskbarOnMaximize == false; return(IntPtr.Zero); } if (this.MinimizeAnimation && this._GetHwndState() == WindowState.Maximized) { var monitor = NativeMethods.MonitorFromWindow(this.windowHandle, MonitorOptions.MONITOR_DEFAULTTONEAREST); var monitorInfo = NativeMethods.GetMonitorInfo(monitor); var monitorRect = this.IgnoreTaskbarOnMaximize ? monitorInfo.rcMonitor : monitorInfo.rcWork; var rc = (RECT)Marshal.PtrToStructure(lParam, typeof(RECT)); rc.Left = monitorRect.Left; rc.Top = monitorRect.Top; rc.Right = monitorRect.Right; rc.Bottom = monitorRect.Bottom; // monitor and work area will be equal if taskbar is hidden if (monitorInfo.rcMonitor.Height == monitorInfo.rcWork.Height && monitorInfo.rcMonitor.Width == monitorInfo.rcWork.Width) { rc = AdjustWorkingAreaForAutoHide(monitor, rc); } Marshal.StructureToPtr(rc, lParam, true); } else if (this.TryToBeFlickerFree && this._GetHwndState() == WindowState.Normal && wParam.ToInt32() != 0) { var rc = (RECT)Marshal.PtrToStructure(lParam, typeof(RECT)); // We have to add or remove one pixel on any side of the window to force a flicker free resize. // Removing pixels would result in a smaller client area. // Adding pixels does not seem to really increase the client area. rc.Bottom += 1; Marshal.StructureToPtr(rc, lParam, true); } handled = true; // Per MSDN for NCCALCSIZE, always return 0 when wParam == FALSE // // Returning 0 when wParam == TRUE is not appropriate - it will preserve // the old client area and align it with the upper-left corner of the new // client area. So we simply ask for a redraw (WVR_REDRAW) var retVal = IntPtr.Zero; if (wParam.ToInt32() != 0) // wParam == TRUE { // Using the combination of WVR.VALIDRECTS and WVR.REDRAW gives the smoothest // resize behavior we can achieve here. retVal = new IntPtr((int)(WVR.VALIDRECTS | WVR.REDRAW)); } return(retVal); }
private IntPtr _HandleNCPAINT(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) { handled = false; return(IntPtr.Zero); }
private IntPtr _HandleWINDOWPOSCHANGING(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) { Assert.IsNotDefault(lParam); var wp = (WINDOWPOS)Marshal.PtrToStructure(lParam, typeof(WINDOWPOS)); // we don't do bitwise operations cuz we're checking for this flag being the only one there // I have no clue why this works, I tried this because VS2013 has this flag removed on fullscreen window movws if (this.IgnoreTaskbarOnMaximize && this._GetHwndState() == WindowState.Maximized && wp.flags == SWP.FRAMECHANGED) { wp.flags = 0; Marshal.StructureToPtr(wp, lParam, true); handled = true; return(IntPtr.Zero); } if ((wp.flags & SWP.NOMOVE) != 0) { handled = false; return(IntPtr.Zero); } var wnd = this.AssociatedObject; if (wnd is null || this.hwndSource?.CompositionTarget is null) { handled = false; return(IntPtr.Zero); } var changedPos = false; // Convert the original to original size based on DPI setting. Need for x% screen DPI. var matrix = this.hwndSource.CompositionTarget.TransformToDevice; var minWidth = wnd.MinWidth * matrix.M11; var minHeight = wnd.MinHeight * matrix.M22; if (wp.cx < minWidth) { wp.cx = (int)minWidth; changedPos = true; } if (wp.cy < minHeight) { wp.cy = (int)minHeight; changedPos = true; } var maxWidth = wnd.MaxWidth * matrix.M11; var maxHeight = wnd.MaxHeight * matrix.M22; if (wp.cx > maxWidth && maxWidth > 0) { wp.cx = (int)Math.Round(maxWidth); changedPos = true; } if (wp.cy > maxHeight && maxHeight > 0) { wp.cy = (int)Math.Round(maxHeight); changedPos = true; } if (changedPos == false) { handled = false; return(IntPtr.Zero); } Marshal.StructureToPtr(wp, lParam, true); handled = false; return(IntPtr.Zero); }