/// <summary> /// Extends the glass frame of a window. Only works on operating systems that support composition. /// </summary> /// <param name="window">The window to modify.</param> /// <param name="margin">The margins of the new frame.</param> /// <returns>Whether the frame was successfully extended.</returns> /// <remarks> /// This function adds hooks to the Window to respond to changes to whether composition is enabled. /// </remarks> public static bool ExtendGlassFrame(Window window, Thickness margin) { Verify.IsNotNull(window, "window"); window.VerifyAccess(); IntPtr hwnd = new WindowInteropHelper(window).Handle; if (_extendedWindows.ContainsKey(hwnd)) { // The hook into the HWND's WndProc has the original margin cached. // Don't want to support dynamically adjusting that unless there's a need. throw new InvalidOperationException("Multiple calls to this function for the same Window are not supported."); } return _ExtendGlassFrameInternal(window, margin); }
public static void RegisterHotKey(Window window, Key key, ModifierKeys modifiers, int keyId) { window.VerifyAccess(); int winMods = 0; if ((modifiers & ModifierKeys.Alt) == ModifierKeys.Alt) winMods = winMods | MOD_ALT; if ((modifiers & ModifierKeys.Control) == ModifierKeys.Control) winMods = winMods | MOD_CONTROL; if ((modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) winMods = winMods | MOD_SHIFT; if ((modifiers & ModifierKeys.Windows) == ModifierKeys.Windows) winMods = winMods | MOD_WIN; var helper = new WindowInteropHelper(window); RegisterHotKey(helper.Handle, keyId, winMods, KeyInterop.VirtualKeyFromKey(key)); }
public static bool SetWindowThemeAttribute(Window window, bool showCaption, bool showIcon) { Verify.IsNotNull(window, "window"); window.VerifyAccess(); IntPtr hwnd = new WindowInteropHelper(window).Handle; if (_attributedWindows.ContainsKey(hwnd)) { // The hook into the HWND's WndProc has the original settings cached. // Don't want to support dynamically adjusting that unless there's a need. throw new InvalidOperationException("Multiple calls to this function for the same Window are not supported."); } return _SetWindowThemeAttribute(window, showCaption, showIcon); }
public static void UnregisterHotKey(Window window, int keyId) { window.VerifyAccess(); var helper = new WindowInteropHelper(window); UnregisterHotKey(helper.Handle, keyId); }