protected void UpdateClipRegion(ClipRegionChangeType regionChangeType = ClipRegionChangeType.FromPropertyChange) { var hwndSource = (HwndSource)PresentationSource.FromVisual(this); if (hwndSource == null) { return; } RECT lpRect; NativeMethods.GetWindowRect(hwndSource.Handle, out lpRect); var windowPlacement = NativeMethods.GetWindowPlacement(hwndSource.Handle); UpdateClipRegion(hwndSource.Handle, windowPlacement, regionChangeType, lpRect); }
public void UpdateWindowPos() { var targetWindowHandle = TargetWindowHandle; RECT lpRect; NativeMethods.GetWindowRect(targetWindowHandle, out lpRect); NativeMethods.GetWindowPlacement(targetWindowHandle); if (!IsVisible) { return; } switch (_direction) { case Dock.Left: Border.Height = lpRect.Height; Left = lpRect.Left - 9; Top = lpRect.Top - 9; Width = 9; Height = lpRect.Height + 18; break; case Dock.Top: Border.Width = lpRect.Width + 2; Left = lpRect.Left - 9; Top = lpRect.Top - 9; Width = lpRect.Width + 18; Height = 9; break; case Dock.Right: Border.Height = lpRect.Height; Left = lpRect.Right; Top = lpRect.Top - 9; Width = 9; Height = lpRect.Height + 18; break; default: Border.Width = lpRect.Width + 2; Left = lpRect.Left - 9; Top = lpRect.Bottom; Width = lpRect.Width + 18; Height = 9; break; } }
protected static void ShowWindowMenu(HwndSource source, Point screenPoint, bool canMinimize) { var systemMetrics = NativeMethods.GetSystemMetrics(40); var systemMenu = NativeMethods.GetSystemMenu(source.Handle, false); var windowPlacement = NativeMethods.GetWindowPlacement(source.Handle); var flag = VisualUtilities.ModifyStyle(source.Handle, 268435456, 0); var uEnable = canMinimize ? 0U : 1U; if (windowPlacement.showCmd == 1) { NativeMethods.EnableMenuItem(systemMenu, 61728U, 1U); NativeMethods.EnableMenuItem(systemMenu, 61456U, 0U); NativeMethods.EnableMenuItem(systemMenu, 61440U, 0U); NativeMethods.EnableMenuItem(systemMenu, 61488U, 0U); NativeMethods.EnableMenuItem(systemMenu, 61472U, uEnable); NativeMethods.EnableMenuItem(systemMenu, 61536U, 0U); } else if (windowPlacement.showCmd == 3) { NativeMethods.EnableMenuItem(systemMenu, 61728U, 0U); NativeMethods.EnableMenuItem(systemMenu, 61456U, 1U); NativeMethods.EnableMenuItem(systemMenu, 61440U, 1U); NativeMethods.EnableMenuItem(systemMenu, 61488U, 1U); NativeMethods.EnableMenuItem(systemMenu, 61472U, uEnable); NativeMethods.EnableMenuItem(systemMenu, 61536U, 0U); } if (flag) { VisualUtilities.ModifyStyle(source.Handle, 0, 268435456); } var fuFlags = (uint)(systemMetrics | 256 | 128 | 2); var num = NativeMethods.TrackPopupMenuEx(systemMenu, fuFlags, (int)screenPoint.X, (int)screenPoint.Y, source.Handle, IntPtr.Zero); if (num == 0) { return; } NativeMethods.PostMessage(source.Handle, 274, new IntPtr(num), IntPtr.Zero); }
private void WmWindowPosChanged(IntPtr hWnd, IntPtr lParam) { try { var windowpos = (Windowpos)Marshal.PtrToStructure(lParam, typeof(Windowpos)); var windowPlacement = NativeMethods.GetWindowPlacement(hWnd); var currentBounds = new RECT(windowpos.x, windowpos.y, windowpos.x + windowpos.cx, windowpos.y + windowpos.cy); if (((int)windowpos.flags & 1) != 1) { UpdateClipRegion(hWnd, windowPlacement, ClipRegionChangeType.FromSize, currentBounds); } else if (((int)windowpos.flags & 2) != 2) { UpdateClipRegion(hWnd, windowPlacement, ClipRegionChangeType.FromPosition, currentBounds); } OnWindowPosChanged(hWnd, windowPlacement.showCmd, windowPlacement.rcNormalPosition.ToInt32Rect()); UpdateGlowWindowPositions(true); UpdateZOrderOfThisAndOwner(); } catch (Win32Exception) { } }