private void UpdateAppBarState() { if (_suppressingUIToSysUpdate) { return; } var autohide = ChkAutoHide.Checked; var alwaysOnTop = ChkAlwaysOnTop.Checked; var abd = new WinApi.APPBARDATA(); abd.hWnd = _taskBarHwnd; if (autohide) { abd.lParam = (int)(alwaysOnTop ? WinApi.ABState.ABS_AUTOHIDEANDONTOP : WinApi.ABState.ABS_AUTOHIDE); } else { abd.lParam = (int)(alwaysOnTop ? WinApi.ABState.ABS_ALWAYSONTOP : WinApi.ABState.ABS_MANUAL); } WinApi.SHAppBarMessage((uint)WinApi.ABMsg.ABM_SETSTATE, ref abd); }
private static void AppBarMessage(WinApi.ABMessage message, ref WinApi.APPBARDATA appBarData) { WinApi.SHAppBarMessage((int)message, ref appBarData); }
/// <summary> /// Removes the app bar. /// </summary> private void Remove() { WinApi.APPBARDATA appBarData = this.AppBarData(); AppBarMessage(WinApi.ABMessage.ABM_REMOVE, ref appBarData); }
/// <summary> /// Set the position of the app bar. /// </summary> private void SetPos() { if (this.positioning) { this.positioning = false; return; } this.positioning = true; WinApi.APPBARDATA appBarData = this.AppBarData(); appBarData.uEdge = (uint)this.Edge; Rect windowRect = this.windowMovement.GetWindowRect(); Rect screen = this.windowMovement.GetScreenSize(); // Request the full length of the screen, at the relevant edge. Rect rect = screen; if (this.Edge.IsHorizontal()) { rect.Height = windowRect.Height; if (this.Edge == Edge.Bottom) { rect.Y = screen.Bottom - windowRect.Height; } } else if (this.Edge.IsVertical()) { rect.Width = windowRect.Width; if (this.Edge == Edge.Right) { rect.X = screen.Right - windowRect.Width; } } // Ask for a suggested rect - Windows will adjust it to be clear of other app bars. appBarData.rc = rect.ToRECT(); AppBarMessage(WinApi.ABMessage.ABM_QUERYPOS, ref appBarData); // Accept the edge position, ignore the rest. switch (this.Edge) { case Edge.Left: appBarData.rc.Right = appBarData.rc.Left + (int)rect.Width; break; case Edge.Top: appBarData.rc.Bottom = appBarData.rc.Top + (int)rect.Height; break; case Edge.Right: appBarData.rc.Left = appBarData.rc.Right - (int)rect.Width; break; case Edge.Bottom: appBarData.rc.Top = appBarData.rc.Bottom - (int)rect.Height; break; } // Move the window. this.windowMovement.NoMove = true; this.windowMovement.SetWindowRect(appBarData.rc); // Set the app-bar position. AppBarMessage(WinApi.ABMessage.ABM_SETPOS, ref appBarData); Task.Delay(500).ContinueWith(t => { this.windowMovement.NoMove = false; this.windowMovement.SetWindowRect(appBarData.rc); }); this.positioning = false; }