public WpfAppBar(Window window) { _currentPosition = new Position(); _window = window; // Show/Hide timers. _showTimer = new Timer(); _showTimer.AutoReset = false; _showTimer.Elapsed += OnShowTimerElapsed; _hideTimer = new Timer(); _hideTimer.AutoReset = true; _hideTimer.Elapsed += OnHideTimerElapsed; // Windows styles and events. _window.WindowStyle = WindowStyle.None; _window.ResizeMode = ResizeMode.NoResize; _window.ShowInTaskbar = false; _window.Closed += OnClose; _window.MouseLeave += OnMouseLeave; _window.AllowDrop = true; _window.PreviewDragEnter += OnDragEnter; _window.DragLeave += OnDragLeave; Microsoft.Win32.SystemEvents.DisplaySettingsChanged += OnDisplaySettingsChanged; // Default Values. PopupDelay = AppBarDefaultValues.PopupDelay; AutoHideDelay = AppBarDefaultValues.AutoHideDelay; ReserveScreen = AppBarDefaultValues.ReserveScreen; Docked = new DockPosition(AppBarDefaultValues.Docked); ActiveScreen = AppBarDefaultValues.Screen; }
/// <summary> /// <para> /// Requests a size and screen position for an appbar. When the request is made, the message proposes a /// screen edge and a bounding rectangle for the appbar. /// </para> /// <para> /// The system adjusts the bounding rectangle so /// that the appbar does not interfere with the Windows taskbar or any other appbars. /// </para> /// </summary> public void QueryPosition(ref Position position, DockPosition dock) { //TODO: //ABM_QUERYPOS seems to do nothing on Windows 10. It gives back the exact //same dimensions, not adjusting for the start bar //When the dock is docked to the left for example, it doesn't take the //entire screen length because the start bar is there. I used ABM_QUERYPOS //to tell me how much space Windows actually assigned to to the dock //Since ABM_QUERYPOS doesn't work properly on Windows 10, I've decided //to only allow the screen to be reserved when docked to top of the screen, //with the assumption that the start bar is always on the botton of the screen //The code is being left "as is" in case I figure out the solution to it APPBARDATA msgData = new APPBARDATA(); msgData.cbSize = Marshal.SizeOf(msgData); msgData.hWnd = _handle; msgData.uEdge = (uint)dock.ToNative(); position.ToNative(ref msgData.rc); Win32AppBar.SHAppBarMessage(ABM.ABM_QUERYPOS, ref msgData); position = Position.FromNative(ref msgData.rc); }
public IntPtr GetAutoHide(DockPosition dock) { if (_toolbar == null) { return(IntPtr.Zero); } return(_toolbar.GetAutoHide(dock)); }
/// <summary> /// Retrieves the handle to the appbar associated to the edge of the screen. /// </summary> /// <returns> /// Returns the handle to the autohide appbar. The return value is 0 if an error occurs or /// if no autohide appbar is associated with the given edge. /// </returns> public IntPtr GetAutoHide(DockPosition dock) { APPBARDATA msgData = new APPBARDATA(); msgData.cbSize = Marshal.SizeOf(msgData); msgData.hWnd = _handle; msgData.uEdge = (uint)dock.ToNative(); return(Win32AppBar.SHAppBarMessage(ABM.ABM_GETAUTOHIDEBAR, ref msgData)); }
public void Dock(DockPosition dock) { if (Docked != dock) { SetAutoHide(Docked, false); } Docked = dock; SetAutoHide(Docked, true); }
/// <summary> /// Registers or unregisters an autohide appbar for an edge of the screen. /// </summary> /// <returns> /// Returns true if successful, or false if an error occurs or /// if an autohide appbar is already registered for the given edge. /// </returns> public bool SetAutoHide(DockPosition dock, bool autohide) { APPBARDATA msgData = new APPBARDATA(); msgData.cbSize = Marshal.SizeOf(msgData); msgData.hWnd = _handle; msgData.lParam = autohide ? Win32.TRUE : Win32.FALSE; msgData.uEdge = (uint)dock.ToNative(); return(Win32AppBar.SHAppBarMessage(ABM.ABM_SETAUTOHIDEBAR, ref msgData).ToInt32() == Win32.TRUE); }
void SetMinimized() { if (_toolbar == null) { return; } Position position = new Position(); _toolbar.SetPosition(ref position, DockPosition.Left()); }
public void SetAutoHide(DockPosition dock, bool autoHide) { if (_toolbar == null) { return; } bool success = _toolbar.SetAutoHide(dock, autoHide); if (!success && autoHide) { //throw new AppBarException("Unable to set autohide on that edge, an autohide bar has already been set"); Debug.WriteLine("Unable to set autohide on that edge, an autohide bar has already been set"); } }
/// <summary> /// <para> /// Sets the size and screen position of an appbar. The message specifies a /// screen edge and the bounding rectangle for the appbar. /// </para> /// <para> /// The system may adjust the bounding rectangle so that the appbar does not /// interfere with the Windows taskbar or any other appbars. /// </para> /// </summary> public void SetPosition(ref Position position, DockPosition dock) { APPBARDATA msgData = new APPBARDATA(); msgData.cbSize = Marshal.SizeOf(msgData); msgData.hWnd = _handle; msgData.uEdge = (uint)dock.ToNative(); position.ToNative(ref msgData.rc); if (dock.Selected == DockEdge.Top) { msgData.rc.bottom = msgData.rc.bottom + 8; } Win32AppBar.SHAppBarMessage(ABM.ABM_SETPOS, ref msgData); position = Position.FromNative(ref msgData.rc); }
public void SetPosition(ref Position position, DockPosition dock) { Dock(dock); CorrectPosition(ref position); Resize(ref position); }