internal static TaskbarPosition GetEdge() { TaskbarPosition result = TaskbarPosition.ScreenBottom; try { int returnCode = NativeMethods.GetTaskbarPosition(); if (returnCode == 0) { result = TaskbarPosition.ScreenLeft; } else if (returnCode == 1) { result = TaskbarPosition.ScreenTop; } else if (returnCode == 2) { result = TaskbarPosition.ScreenBottom; } else { result = TaskbarPosition.ScreenRight; } } catch { result = TaskbarPosition.ScreenBottom; } return(result); }
/// <summary> /// Initialize taskbar information /// </summary> /// <returns></returns> public TaskbarInfo(IntPtr handle, TagRect rect, bool isShow, TaskbarPosition position, IntPtr monitor) { Handle = handle; Rect = rect; IsShow = isShow; Position = position; Monitor = monitor; }
public TaskbarManager() { this.taskbarHwnd = WinAPI.FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", (string)null); this.rebarHwnd = WinAPI.FindWindowEx(this.taskbarHwnd, IntPtr.Zero, "ReBarWindow32", (string)null); this.trayHwnd = WinAPI.FindWindowEx(this.taskbarHwnd, IntPtr.Zero, "TrayNotifyWnd", (string)null); this.minimizeHwnd = WinAPI.FindWindowEx(this.trayHwnd, IntPtr.Zero, "TrayShowDesktopButtonWClass", (string)null); this.currentTaskbarPos = this.DetectTaskbarPos(); this.TrayResized += new EventHandler(this.TaskbarManagerTrayResized); this.RebarResized += new EventHandler(this.TaskbarManagerRebarResized); }
public void CheckTaskbar() { if (this.spaceReserved) { if (this.CheckTrayWidth()) { return; } this.currentTaskbarPos = this.DetectTaskbarPos(); if (this.currentTaskbarPos == TaskbarPosition.Bottom) { this.TrayResized((object)null, EventArgs.Empty); } } else { this.ReserveSpace(36); } }
private void TrayIconOnClick(object sender, EventArgs e) { MouseEventArgs mouseArgs = (MouseEventArgs)e; if (mouseArgs.Button == MouseButtons.Left) { if (!_iconDeactivatedWithClick) { Matrix transform; using (var src = new HwndSource(new HwndSourceParameters())) { transform = src.CompositionTarget.TransformFromDevice; } var rect = _trayIcon.GetRect(); double iconMid = (rect.Left + (rect.Width / 2.0)) * transform.M11; // calculate where to put var xPadding = 0.0; (Alignment align, (double left, double top, double right, double bottom)) = TaskbarPosition.GetTaskbarPosition(); double height = bottom - top; double width = right - left; switch (align) { case Alignment.BOTTOM: // place on bottom right _mini.Top = (rect.Top * transform.M22) - _mini.Height; _mini.Left = iconMid - (_mini.Width / 2.0); break; case Alignment.LEFT: // place on bottom left _mini.Top = bottom - _mini.Height; _mini.Left = left + width + xPadding; break; case Alignment.RIGHT: // place on bottom right, but down more _mini.Top = bottom - _mini.Height; _mini.Left = right - _mini.Width - width - xPadding; break; case Alignment.TOP: // place on top right _mini.Top = (rect.Bottom * transform.M22); _mini.Left = iconMid - (_mini.Width / 2.0); break; } _mini.Show(); _mini.Activate(); } _iconDeactivatedWithClick = false; } }
public static bool IsVertical(this TaskbarPosition position) { return((position == TaskbarPosition.Left) || (position == TaskbarPosition.Right)); }