public void Hide() { var appBarData = new NativeMethods.APPBARDATA(this.Handle, uEdge: NativeMethods.ABE.ABE_TOP); NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_QUERYPOS, ref appBarData); NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_SETPOS, ref appBarData); this.visible = false; }
public void Destroy() { // unregister as AppBar var appBarData = new NativeMethods.APPBARDATA(this.Handle); NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_REMOVE, ref appBarData); DestroyHandle(); }
private static void InternalSetAutoHide(bool hide) { var data = new NativeMethods.APPBARDATA { lParam = hide ? NativeMethods.ABS.Autohide : NativeMethods.ABS.AlwaysOnTop }; NativeMethods.SHAppBarMessage(NativeMethods.ABM.SetState, ref data); UpdateTaskbar(); }
public static void AppBarWindowPosChanged(IntPtr hwnd) { NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA(); abd.cbSize = (int)Marshal.SizeOf(typeof(NativeMethods.APPBARDATA)); abd.hWnd = hwnd; prepareForInterop(); NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_WINDOWPOSCHANGED, ref abd); interopDone(); }
public static void AppBarActivate(IntPtr hwnd) { NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA(); abd.cbSize = (int)Marshal.SizeOf(typeof(NativeMethods.APPBARDATA)); abd.hWnd = hwnd; abd.lParam = (IntPtr)Convert.ToInt32(true); NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_ACTIVATE, ref abd); // apparently the taskbars like to pop up when app bars change if (Settings.EnableTaskbar) { SetSecondaryTaskbarVisibility(NativeMethods.WindowShowStyle.Hide); } }
/// <summary> /// Retrieves taskbar position and alignment. /// </summary> /// <returns>Taskbar position and alignment.</returns> public static TaskBarInfo GetTaskBarInfo() { // allocate appbardata structure NativeMethods.APPBARDATA abdata = new NativeMethods.APPBARDATA() { hWnd = IntPtr.Zero }; abdata.cbSize = (uint)Marshal.SizeOf(abdata); // get task bar info IntPtr result = NativeMethods.SHAppBarMessage(NativeMethods.ABMsg.ABM_GETTASKBARPOS, ref abdata); // return null if the call failed if (result == IntPtr.Zero) { throw new Exception("Could not retrieve taskbar information."); } Rectangle position = abdata.rc; TaskBarAlignment alignment; switch (abdata.uEdge) { case NativeMethods.ABEdge.ABE_BOTTOM: alignment = TaskBarAlignment.Bottom; break; case NativeMethods.ABEdge.ABE_TOP: alignment = TaskBarAlignment.Top; break; case NativeMethods.ABEdge.ABE_LEFT: alignment = TaskBarAlignment.Left; break; case NativeMethods.ABEdge.ABE_RIGHT: alignment = TaskBarAlignment.Right; break; default: throw new ArgumentOutOfRangeException("Couldn't retrieve location of taskbar."); } return(new TaskBarInfo() { Position = position, Alignment = alignment }); }
protected void Reposition(int width = 0) { if (this.IsRepositioning || !this.IsRegistered) { return; } try { this.IsRepositioning = true; if (width == 0) { width = this.Width; } var workingArea = Screen.FromControl(this).Bounds; var edge = (this.Location.X < workingArea.Width / 2 ? ABEdge.ABE_LEFT : ABEdge.ABE_RIGHT); var abd = new NativeMethods.APPBARDATA(); abd.cbSize = Marshal.SizeOf(abd); abd.hWnd = Handle; abd.uEdge = (int)edge; abd.rc.top = workingArea.Top; abd.rc.bottom = workingArea.Height; if (edge == ABEdge.ABE_LEFT) { abd.rc.left = workingArea.Left; abd.rc.right = workingArea.Left + width; } else { abd.rc.right = workingArea.Right; abd.rc.left = workingArea.Right - width; } NativeMethods.SHAppBarMessage((int)ABMsg.ABM_QUERYPOS, ref abd); if (edge == ABEdge.ABE_LEFT) { abd.rc.right = abd.rc.left + width; } NativeMethods.SHAppBarMessage((int)ABMsg.ABM_SETPOS, ref abd); this.Bounds = new Rectangle(abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top); } finally { this.IsRepositioning = false; } }
public static void SetWinTaskbarState(WinTaskbarState state) { NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA(); abd.cbSize = (int)Marshal.SizeOf(typeof(NativeMethods.APPBARDATA)); abd.hWnd = NativeMethods.FindWindow("Shell_TrayWnd"); if (NotificationArea.Instance.Handle != null && NotificationArea.Instance.Handle != IntPtr.Zero) { while (abd.hWnd == NotificationArea.Instance.Handle) { abd.hWnd = NativeMethods.FindWindowEx(IntPtr.Zero, abd.hWnd, "Shell_TrayWnd", ""); } } abd.lParam = (IntPtr)state; NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_SETSTATE, ref abd); }
public AppBarNativeWindow(int barHeight, bool topBar) { this.height = barHeight; visible = false; isTopMost = false; edge = topBar ? NativeMethods.ABE.ABE_TOP : NativeMethods.ABE.ABE_BOTTOM; this.CreateHandle(new CreateParams { Parent = NativeMethods.HWND_MESSAGE, ClassName = "Message" }); callbackMessageNum = NativeMethods.WM_USER + count++; // register as AppBar var appBarData = new NativeMethods.APPBARDATA(this.Handle, callbackMessageNum); NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_NEW, ref appBarData); }
internal static void ShowHideWindowsTaskbar(bool showWindowsTaskbar) { var appBarData = new NativeMethods.APPBARDATA(SystemAndProcessInformation.taskbarHandle); var state = (NativeMethods.ABS)(uint) NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_GETSTATE, ref appBarData); appBarData.lParam = (IntPtr)(showWindowsTaskbar ? state & ~NativeMethods.ABS.ABS_AUTOHIDE : state | NativeMethods.ABS.ABS_AUTOHIDE); NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_SETSTATE, ref appBarData); var showHide = showWindowsTaskbar ? NativeMethods.SW.SW_SHOWNA : NativeMethods.SW.SW_HIDE; NativeMethods.ShowWindow(SystemAndProcessInformation.taskbarHandle, showHide); if (SystemAndProcessInformation.isAtLeastVista) { NativeMethods.ShowWindow(SystemAndProcessInformation.startButtonHandle, showHide); } isWindowsTaskbarShown = showWindowsTaskbar; }
public bool SetPosition(Monitor monitor) { this.monitor = monitor; var appBarData = new NativeMethods.APPBARDATA(this.Handle, uEdge: edge, rc: new NativeMethods.RECT { left = monitor.Bounds.Left, right = monitor.Bounds.Right }); if (edge == NativeMethods.ABE.ABE_TOP) { appBarData.rc.top = monitor.Bounds.Top; appBarData.rc.bottom = appBarData.rc.top + this.height; } else { appBarData.rc.bottom = monitor.Bounds.Bottom; appBarData.rc.top = appBarData.rc.bottom - this.height; } NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_QUERYPOS, ref appBarData); if (edge == NativeMethods.ABE.ABE_TOP) { appBarData.rc.bottom = appBarData.rc.top + this.height; } else { appBarData.rc.top = appBarData.rc.bottom - this.height; } NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_SETPOS, ref appBarData); var changedPosition = appBarData.rc.bottom != rect.bottom || appBarData.rc.top != rect.top || appBarData.rc.left != rect.left || appBarData.rc.right != rect.right; this.rect = appBarData.rc; this.visible = true; return(changedPosition); }
private void RegisterOrUnregisterBar(bool register) { if (this.IsRegistering) { return; } try { this.IsRegistering = true; var abd = new NativeMethods.APPBARDATA(); abd.cbSize = Marshal.SizeOf(abd); abd.hWnd = Handle; if (register == this.IsRegistered) { return; } else if (register) { abd.uCallbackMessage = this.callBackId; NativeMethods.SHAppBarMessage((int)ABMsg.ABM_NEW, ref abd); this.IsRegistered = true; this.Reposition(); } else { NativeMethods.SHAppBarMessage((int)ABMsg.ABM_REMOVE, ref abd); this.IsRegistered = false; } } finally { this.IsRegistering = false; } }
//This file is from before r416 public static int RegisterBar(IntPtr handle, Size size) { NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA(); abd.cbSize = Marshal.SizeOf(abd); abd.hWnd = handle; if (!isBarRegistered) { uCallBack = NativeMethods.RegisterWindowMessage("AppBarMessage" + Guid.NewGuid().ToString()); abd.uCallbackMessage = uCallBack; uint ret = NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_NEW, ref abd); isBarRegistered = true; ABSetPos(handle, size); } else { NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_REMOVE, ref abd); isBarRegistered = false; } return(uCallBack); }
private static void InvalidateInternal() { _handle = Interop.FindWindow("Shell_TrayWnd", null); var data = new NativeMethods.APPBARDATA(_handle); Interop.SHAppBarMessage(NativeMethods.ShellMessages.ABM_GETTASKBARPOS, ref data); _position = (TaskbarPosition)data.uEdge; _left = data.rc.left; _top = data.rc.top; _right = data.rc.right; _bottom = data.rc.bottom; data = new NativeMethods.APPBARDATA(_handle); var state = (NativeMethods.TaskbarState)Interop.SHAppBarMessage(NativeMethods.ShellMessages.ABM_GETSTATE, ref data).ToInt32(); _alwaysOnTop = state == NativeMethods.TaskbarState.ABS_ALWAYSONTOP || Windows.IsWindows7OrHigher; _autoHide = state == NativeMethods.TaskbarState.ABS_AUTOHIDE; _isCacheValid = true; }
public static int RegisterBar(Window abWindow, Screen screen, double width, double height, ABEdge edge = ABEdge.ABE_TOP) { lock (appBarLock) { NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA(); abd.cbSize = Marshal.SizeOf(typeof(NativeMethods.APPBARDATA)); IntPtr handle = new WindowInteropHelper(abWindow).Handle; abd.hWnd = handle; if (!appBars.Contains(handle)) { uCallBack = NativeMethods.RegisterWindowMessage("AppBarMessage"); abd.uCallbackMessage = uCallBack; prepareForInterop(); uint ret = NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_NEW, ref abd); interopDone(); appBars.Add(handle); CairoLogger.Instance.Debug("Created AppBar for handle " + handle.ToString()); ABSetPos(abWindow, screen, width, height, edge, true); } else { prepareForInterop(); NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_REMOVE, ref abd); interopDone(); appBars.Remove(handle); CairoLogger.Instance.Debug("Removed AppBar for handle " + handle.ToString()); return(0); } } return(uCallBack); }
/// <summary> /// Retrieves taskbar position and alignment. /// </summary> /// <returns>Taskbar position and alignment.</returns> public static TaskBarInfo GetTaskBarInfo() { // allocate appbardata structure NativeMethods.APPBARDATA abdata = new NativeMethods.APPBARDATA() { hWnd = IntPtr.Zero }; abdata.cbSize = (uint)Marshal.SizeOf(abdata); // get task bar info IntPtr result = NativeMethods.SHAppBarMessage(NativeMethods.ABMsg.ABM_GETTASKBARPOS, ref abdata); // return null if the call failed if (result == IntPtr.Zero) throw new Exception("Could not retrieve taskbar information."); Rect position = abdata.rc; TaskBarAlignment alignment; switch (abdata.uEdge) { case NativeMethods.ABEdge.ABE_BOTTOM: alignment = TaskBarAlignment.Bottom; break; case NativeMethods.ABEdge.ABE_TOP: alignment = TaskBarAlignment.Top; break; case NativeMethods.ABEdge.ABE_LEFT: alignment = TaskBarAlignment.Left; break; case NativeMethods.ABEdge.ABE_RIGHT: alignment = TaskBarAlignment.Right; break; default: throw new ArgumentOutOfRangeException("Couldn't retrieve location of taskbar."); } return new TaskBarInfo() { Position = position, Alignment = alignment }; }
public static extern IntPtr SHAppBarMessage([MarshalAs(UnmanagedType.U4)] NativeMethods.ShellMessages dwMessage, ref NativeMethods.APPBARDATA pData);
protected void Reposition(int width=0) { if (this.IsRepositioning || !this.IsRegistered) return; try { this.IsRepositioning = true; if (width == 0) width = this.Width; var workingArea = Screen.FromControl(this).Bounds; var edge = (this.Location.X < workingArea.Width / 2 ? ABEdge.ABE_LEFT : ABEdge.ABE_RIGHT); var abd = new NativeMethods.APPBARDATA(); abd.cbSize = Marshal.SizeOf(abd); abd.hWnd = Handle; abd.uEdge = (int)edge; abd.rc.top = workingArea.Top; abd.rc.bottom = workingArea.Height; if (edge == ABEdge.ABE_LEFT) { abd.rc.left = workingArea.Left; abd.rc.right = workingArea.Left + width; } else { abd.rc.right = workingArea.Right; abd.rc.left = workingArea.Right - width; } NativeMethods.SHAppBarMessage((int)ABMsg.ABM_QUERYPOS, ref abd); if (edge == ABEdge.ABE_LEFT) { abd.rc.right = abd.rc.left + width; } NativeMethods.SHAppBarMessage((int)ABMsg.ABM_SETPOS, ref abd); this.Bounds = new Rectangle(abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top); } finally { this.IsRepositioning = false; } }
public static void ABSetPos(Window abWindow, double width, double height, ABEdge edge) { NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA(); abd.cbSize = Marshal.SizeOf(typeof(NativeMethods.APPBARDATA)); IntPtr handle = new WindowInteropHelper(abWindow).Handle; abd.hWnd = handle; abd.uEdge = (int)edge; int sWidth; int sHeight; // adjust size for dpi TransformToPixels(width, height, out sWidth, out sHeight); if (abd.uEdge == (int)ABEdge.ABE_LEFT || abd.uEdge == (int)ABEdge.ABE_RIGHT) { abd.rc.top = 0; abd.rc.bottom = SystemInformation.WorkingArea.Bottom; if (abd.uEdge == (int)ABEdge.ABE_LEFT) { abd.rc.left = SystemInformation.WorkingArea.Left; abd.rc.right = abd.rc.left + sWidth; } else { abd.rc.right = SystemInformation.WorkingArea.Right; abd.rc.left = abd.rc.right - sWidth; } } else { abd.rc.left = SystemInformation.WorkingArea.Left; abd.rc.right = SystemInformation.WorkingArea.Right; if (abd.uEdge == (int)ABEdge.ABE_TOP) { abd.rc.top = 0; abd.rc.bottom = abd.rc.top + sHeight; } else { abd.rc.bottom = SystemInformation.WorkingArea.Bottom; abd.rc.top = abd.rc.bottom - sHeight; } } NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_QUERYPOS, ref abd); // system doesn't adjust all edges for us, do some adjustments switch (abd.uEdge) { case (int)ABEdge.ABE_LEFT: abd.rc.right = abd.rc.left + sWidth; break; case (int)ABEdge.ABE_RIGHT: abd.rc.left = abd.rc.right - sWidth; break; case (int)ABEdge.ABE_TOP: abd.rc.bottom = abd.rc.top + sHeight; break; case (int)ABEdge.ABE_BOTTOM: abd.rc.top = abd.rc.bottom - sHeight; break; } NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_SETPOS, ref abd); // tracing int h = abd.rc.bottom - abd.rc.top; Trace.WriteLineIf(abd.uEdge == (int)ABEdge.ABE_TOP, "Top AppBar height is " + h.ToString()); Trace.WriteLineIf(abd.uEdge == (int)ABEdge.ABE_BOTTOM, "Bottom AppBar height is " + h.ToString()); abWindow.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new ResizeDelegate(DoResize), abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top); if (h < sHeight) { ABSetPos(abWindow, width, height, edge); } }
public static void ABSetPos(IntPtr handle, Size size) { NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA(); abd.cbSize = Marshal.SizeOf(abd); abd.hWnd = handle; abd.uEdge = (int)NativeMethods.ABEdge.ABE_TOP; if (abd.uEdge == (int)NativeMethods.ABEdge.ABE_LEFT || abd.uEdge == (int)NativeMethods.ABEdge.ABE_RIGHT) { abd.rc.top = 0; abd.rc.bottom = PrimaryMonitorSize.Height; if (abd.uEdge == (int)NativeMethods.ABEdge.ABE_LEFT) { abd.rc.left = 0; abd.rc.right = size.Width; } else { abd.rc.right = PrimaryMonitorSize.Width; abd.rc.left = abd.rc.right - size.Width; } } else { abd.rc.left = 0; abd.rc.right = PrimaryMonitorSize.Width; if (abd.uEdge == (int)NativeMethods.ABEdge.ABE_TOP) { abd.rc.top = 0; abd.rc.bottom = size.Height; } else { abd.rc.bottom = PrimaryMonitorSize.Height; abd.rc.top = abd.rc.bottom - size.Height; } } NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_QUERYPOS, ref abd); switch (abd.uEdge) { case (int)NativeMethods.ABEdge.ABE_LEFT: abd.rc.right = abd.rc.left + size.Width; break; case (int)NativeMethods.ABEdge.ABE_RIGHT: abd.rc.left = abd.rc.right - size.Width; break; case (int)NativeMethods.ABEdge.ABE_TOP: abd.rc.bottom = abd.rc.top + size.Height; break; case (int)NativeMethods.ABEdge.ABE_BOTTOM: abd.rc.top = abd.rc.bottom - size.Height; break; } NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_SETPOS, ref abd); Trace.WriteLineIf(abd.uEdge == (int)NativeMethods.ABEdge.ABE_TOP, "*** TOP EDGE - CX is: " + (abd.rc.bottom - abd.rc.top).ToString()); NativeMethods.MoveWindow(abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, true); }
private void RegisterOrUnregisterBar(bool register) { if (this.IsRegistering) return; try { this.IsRegistering = true; var abd = new NativeMethods.APPBARDATA(); abd.cbSize = Marshal.SizeOf(abd); abd.hWnd = Handle; if (register == this.IsRegistered) { return; } else if (register) { abd.uCallbackMessage = this.callBackId; NativeMethods.SHAppBarMessage((int)ABMsg.ABM_NEW, ref abd); this.IsRegistered = true; this.Reposition(); } else { NativeMethods.SHAppBarMessage((int)ABMsg.ABM_REMOVE, ref abd); this.IsRegistered = false; } } finally { this.IsRegistering = false; } }
public static void ABSetPos(Window abWindow, Screen screen, double width, double height, ABEdge edge) { NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA(); abd.cbSize = Marshal.SizeOf(typeof(NativeMethods.APPBARDATA)); IntPtr handle = new WindowInteropHelper(abWindow).Handle; abd.hWnd = handle; abd.uEdge = (int)edge; int sWidth = (int)width; int sHeight = (int)height; int top = 0; int left = SystemInformation.WorkingArea.Left; int right = SystemInformation.WorkingArea.Right; int bottom = PrimaryMonitorDeviceSize.Height; if (screen != null) { top = screen.Bounds.Y; left = screen.WorkingArea.Left; right = screen.WorkingArea.Right; bottom = screen.Bounds.Bottom; } if (abd.uEdge == (int)ABEdge.ABE_LEFT || abd.uEdge == (int)ABEdge.ABE_RIGHT) { abd.rc.top = top; abd.rc.bottom = bottom; if (abd.uEdge == (int)ABEdge.ABE_LEFT) { abd.rc.left = left; abd.rc.right = abd.rc.left + sWidth; } else { abd.rc.right = right; abd.rc.left = abd.rc.right - sWidth; } } else { abd.rc.left = left; abd.rc.right = right; if (abd.uEdge == (int)ABEdge.ABE_TOP) { if (abWindow is Taskbar) { abd.rc.top = top + Convert.ToInt32(Startup.MenuBarWindow.Height); } else { abd.rc.top = top; } abd.rc.bottom = abd.rc.top + sHeight; } else { abd.rc.bottom = bottom; abd.rc.top = abd.rc.bottom - sHeight; } } NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_QUERYPOS, ref abd); // system doesn't adjust all edges for us, do some adjustments switch (abd.uEdge) { case (int)ABEdge.ABE_LEFT: abd.rc.right = abd.rc.left + sWidth; break; case (int)ABEdge.ABE_RIGHT: abd.rc.left = abd.rc.right - sWidth; break; case (int)ABEdge.ABE_TOP: abd.rc.bottom = abd.rc.top + sHeight; break; case (int)ABEdge.ABE_BOTTOM: abd.rc.top = abd.rc.bottom - sHeight; break; } NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_SETPOS, ref abd); // tracing int h = abd.rc.bottom - abd.rc.top; Trace.WriteLineIf(abd.uEdge == (int)ABEdge.ABE_TOP, "Top AppBar height is " + h.ToString()); Trace.WriteLineIf(abd.uEdge == (int)ABEdge.ABE_BOTTOM, "Bottom AppBar height is " + h.ToString()); abWindow.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new ResizeDelegate(DoResize), abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top); if (h < sHeight) { ABSetPos(abWindow, screen, width, height, edge); } }
public static void ABSetPos(Window abWindow, Screen screen, double width, double height, ABEdge edge, bool isCreate = false) { lock (appBarLock) { NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA(); abd.cbSize = Marshal.SizeOf(typeof(NativeMethods.APPBARDATA)); IntPtr handle = new WindowInteropHelper(abWindow).Handle; abd.hWnd = handle; abd.uEdge = (int)edge; int sWidth = (int)width; int sHeight = (int)height; int top = 0; int left = SystemInformation.WorkingArea.Left; int right = SystemInformation.WorkingArea.Right; int bottom = PrimaryMonitorDeviceSize.Height; double dpiScale = PresentationSource.FromVisual(abWindow).CompositionTarget.TransformToDevice.M11; if (screen != null) { top = screen.Bounds.Y; left = screen.WorkingArea.Left; right = screen.WorkingArea.Right; bottom = screen.Bounds.Bottom; } if (abd.uEdge == (int)ABEdge.ABE_LEFT || abd.uEdge == (int)ABEdge.ABE_RIGHT) { abd.rc.top = top; abd.rc.bottom = bottom; if (abd.uEdge == (int)ABEdge.ABE_LEFT) { abd.rc.left = left; abd.rc.right = abd.rc.left + sWidth; } else { abd.rc.right = right; abd.rc.left = abd.rc.right - sWidth; } } else { abd.rc.left = left; abd.rc.right = right; if (abd.uEdge == (int)ABEdge.ABE_TOP) { if (abWindow is Taskbar) { abd.rc.top = top + Convert.ToInt32(Startup.MenuBarWindow.Height); } else { abd.rc.top = top; } abd.rc.bottom = abd.rc.top + sHeight; } else { abd.rc.bottom = bottom; abd.rc.top = abd.rc.bottom - sHeight; } } prepareForInterop(); NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_QUERYPOS, ref abd); interopDone(); // system doesn't adjust all edges for us, do some adjustments switch (abd.uEdge) { case (int)ABEdge.ABE_LEFT: abd.rc.right = abd.rc.left + sWidth; break; case (int)ABEdge.ABE_RIGHT: abd.rc.left = abd.rc.right - sWidth; break; case (int)ABEdge.ABE_TOP: abd.rc.bottom = abd.rc.top + sHeight; break; case (int)ABEdge.ABE_BOTTOM: abd.rc.top = abd.rc.bottom - sHeight; break; } prepareForInterop(); NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_SETPOS, ref abd); interopDone(); // tracing bool isSameCoords = false; if (!isCreate) { isSameCoords = abd.rc.top == (abWindow.Top * dpiScale) && abd.rc.left == (abWindow.Left * dpiScale) && abd.rc.bottom == (abWindow.Top * dpiScale) + sHeight && abd.rc.right == (abWindow.Left * dpiScale) + sWidth; } int h = abd.rc.bottom - abd.rc.top; if (!isSameCoords) { CairoLogger.Instance.Debug(abWindow.Name + " AppBar height is " + h.ToString()); } abWindow.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new ResizeDelegate(DoResize), abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, isSameCoords); if (h < sHeight) { ABSetPos(abWindow, screen, width, height, edge); } } }
public static TaskbarLocation Detect() { var abd = new NativeMethods.APPBARDATA(); abd.cbSize = Marshal.SizeOf(abd); Win32.NativeMethods.SHAppBarMessage(Win32.NativeMethods.ABM_GETTASKBARPOS, ref abd); var taskbar = (Rectangle)abd.rc; var p = new Point( abd.rc.left + (abd.rc.right - abd.rc.left) / 2, abd.rc.top + (abd.rc.bottom - abd.rc.top) / 2 ); var workArea = Screen.GetWorkingArea(p); // Windows 7 reports the work area as including the taskbar, but we need // it exclusing the taskbar. Correct. if (workArea.Contains(p)) { var pMon = new Point( workArea.Left + workArea.Width / 2, workArea.Top + workArea.Height / 2 ); // Whether the taskbar is horizontal or vertical. if ((abd.rc.right - abd.rc.left) > (abd.rc.bottom - abd.rc.top)) { // Whether the baskbar is at the top or the bottom. if (p.Y < pMon.Y) { workArea = new Rectangle( workArea.Left, abd.rc.bottom, workArea.Width, workArea.Bottom - abd.rc.bottom ); } else { workArea = new Rectangle( workArea.Left, workArea.Top, workArea.Width, abd.rc.top ); } } else { // Whether the taskbar is at the left or right. if (p.X < pMon.X) { workArea = new Rectangle( abd.rc.right, workArea.Top, workArea.Right - abd.rc.right, workArea.Height ); } else { workArea = new Rectangle( workArea.Left, abd.rc.left, workArea.Top, workArea.Height ); } } } var pBar = new Point( taskbar.Left + taskbar.Width / 2, taskbar.Top + taskbar.Height / 2 ); TaskbarLocationEdge edge; if (pBar.X > workArea.Right) { edge = TaskbarLocationEdge.Right; } else if (pBar.X < workArea.Left) { edge = TaskbarLocationEdge.Left; } else if (pBar.Y > workArea.Bottom) { edge = TaskbarLocationEdge.Bottom; } else if (pBar.Y < workArea.Top) { edge = TaskbarLocationEdge.Top; } else { edge = TaskbarLocationEdge.Bottom; } return(new TaskbarLocation(taskbar, workArea, edge)); }
internal static void ShowHideWindowsTaskbar(bool showWindowsTaskbar) { var appBarData = new NativeMethods.APPBARDATA(SystemAndProcessInformation.taskbarHandle); var state = (NativeMethods.ABS) (uint) NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_GETSTATE, ref appBarData); appBarData.lParam = (IntPtr) (showWindowsTaskbar ? state & ~NativeMethods.ABS.ABS_AUTOHIDE : state | NativeMethods.ABS.ABS_AUTOHIDE); NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_SETSTATE, ref appBarData); var showHide = showWindowsTaskbar ? NativeMethods.SW.SW_SHOWNA : NativeMethods.SW.SW_HIDE; NativeMethods.ShowWindow(SystemAndProcessInformation.taskbarHandle, showHide); if (SystemAndProcessInformation.isAtLeastVista) { NativeMethods.ShowWindow(SystemAndProcessInformation.startButtonHandle, showHide); } isWindowsTaskbarShown = showWindowsTaskbar; }
internal static IntPtr SHAppBarMessage(NativeMethods.ShellMessages dwMessage, ref NativeMethods.APPBARDATA pData) { Contract.Ensures(dwMessage != NativeMethods.ShellMessages.ABM_GETTASKBARPOS || Contract.Result <IntPtr>() != IntPtr.Zero); var result = UnsafeNativeMethods.SHAppBarMessage(dwMessage, ref pData); ThrowInvalidOperationException(dwMessage == NativeMethods.ShellMessages.ABM_GETTASKBARPOS && result == IntPtr.Zero); return(result); }
public bool SetPosition(Monitor monitor) { this.monitor = monitor; var appBarData = new NativeMethods.APPBARDATA(this.Handle, uEdge: edge, rc: new NativeMethods.RECT { left = monitor.Bounds.Left, right = monitor.Bounds.Right }); if (edge == NativeMethods.ABE.ABE_TOP) { appBarData.rc.top = monitor.Bounds.Top; appBarData.rc.bottom = appBarData.rc.top + this.height; } else { appBarData.rc.bottom = monitor.Bounds.Bottom; appBarData.rc.top = appBarData.rc.bottom - this.height; } NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_QUERYPOS, ref appBarData); if (edge == NativeMethods.ABE.ABE_TOP) { appBarData.rc.bottom = appBarData.rc.top + this.height; } else { appBarData.rc.top = appBarData.rc.bottom - this.height; } NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_SETPOS, ref appBarData); var changedPosition = appBarData.rc.bottom != rect.bottom || appBarData.rc.top != rect.top || appBarData.rc.left != rect.left || appBarData.rc.right != rect.right; this.rect = appBarData.rc; this.visible = true; return changedPosition; }
public static void ABSetPos(AppBarWindow abWindow, Screen screen, double width, double height, ABEdge edge, bool isCreate = false) { lock (appBarLock) { NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA(); abd.cbSize = Marshal.SizeOf(typeof(NativeMethods.APPBARDATA)); IntPtr handle = new WindowInteropHelper(abWindow).Handle; abd.hWnd = handle; abd.uEdge = (int)edge; int sWidth = (int)width; int sHeight = (int)height; int top = 0; int left = 0; int right = WindowManager.PrimaryMonitorDeviceSize.Width; int bottom = WindowManager.PrimaryMonitorDeviceSize.Height; /*PresentationSource ps = PresentationSource.FromVisual(abWindow); * * if (ps == null) * { * // if we are racing with screen setting changes, this will be null * CairoLogger.Instance.Debug("AppBarHelper: Aborting ABSetPos due to window destruction"); * return; * } * * double dpiScale = ps.CompositionTarget.TransformToDevice.M11;*/ if (screen != null) { top = screen.Bounds.Y; left = screen.Bounds.X; right = screen.Bounds.Right; bottom = screen.Bounds.Bottom; } if (abd.uEdge == (int)ABEdge.ABE_LEFT || abd.uEdge == (int)ABEdge.ABE_RIGHT) { abd.rc.top = top; abd.rc.bottom = bottom; if (abd.uEdge == (int)ABEdge.ABE_LEFT) { abd.rc.left = left; abd.rc.right = abd.rc.left + sWidth; } else { abd.rc.right = right; abd.rc.left = abd.rc.right - sWidth; } } else { abd.rc.left = left; abd.rc.right = right; if (abd.uEdge == (int)ABEdge.ABE_TOP) { if (!abWindow.requiresScreenEdge) { abd.rc.top = top + Convert.ToInt32(GetAppBarEdgeWindowsHeight((ABEdge)abd.uEdge, screen)); } else { abd.rc.top = top; } abd.rc.bottom = abd.rc.top + sHeight; } else { if (!abWindow.requiresScreenEdge) { abd.rc.bottom = bottom - Convert.ToInt32(GetAppBarEdgeWindowsHeight((ABEdge)abd.uEdge, screen)); } else { abd.rc.bottom = bottom; } abd.rc.top = abd.rc.bottom - sHeight; } } prepareForInterop(); NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_QUERYPOS, ref abd); interopDone(); // system doesn't adjust all edges for us, do some adjustments switch (abd.uEdge) { case (int)ABEdge.ABE_LEFT: abd.rc.right = abd.rc.left + sWidth; break; case (int)ABEdge.ABE_RIGHT: abd.rc.left = abd.rc.right - sWidth; break; case (int)ABEdge.ABE_TOP: abd.rc.bottom = abd.rc.top + sHeight; break; case (int)ABEdge.ABE_BOTTOM: abd.rc.top = abd.rc.bottom - sHeight; break; } prepareForInterop(); NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_SETPOS, ref abd); interopDone(); // check if new coords bool isSameCoords = false; if (!isCreate) { isSameCoords = abd.rc.top == (abWindow.Top * abWindow.dpiScale) && abd.rc.left == (abWindow.Left * abWindow.dpiScale) && abd.rc.bottom == (abWindow.Top * abWindow.dpiScale) + sHeight && abd.rc.right == (abWindow.Left * abWindow.dpiScale) + sWidth; } if (!isSameCoords) { CairoLogger.Instance.Debug(string.Format("AppBarHelper: {0} changing position (TxLxBxR) to {1}x{2}x{3}x{4} from {5}x{6}x{7}x{8}", abWindow.Name, abd.rc.top, abd.rc.left, abd.rc.bottom, abd.rc.right, (abWindow.Top * abWindow.dpiScale), (abWindow.Left * abWindow.dpiScale), (abWindow.Top * abWindow.dpiScale) + sHeight, (abWindow.Left * abWindow.dpiScale) + sWidth)); abWindow.setAppBarPosition(abd.rc); } abWindow.afterAppBarPos(isSameCoords, abd.rc); if (abd.rc.bottom - abd.rc.top < sHeight) { ABSetPos(abWindow, screen, width, height, edge); } } }