I’ll first walk through the plethora of options for each, and then dive into how to use them more effectively. However, they also offer a slew of additional capabilities and customization options that aren’t obvious when you first look at them.
2+ is very rare, it means that we have multiple monitors, and we are not using Extend these displays to create a single virtual desktop.In Windows 7, the Start menu and the taskbar have become both easier to use and more sophisticated.1 rectangle is the position of the taskbar.0 rectangles means the taskbar is hidden.
This code brings back all of the task bars as a list of rectanges: This is the answer from Mark McGinty in C#. Private static extern int ShowWindow(IntPtr hwnd, int command) Private static extern IntPtr SHAppBarMessage(AppBarMessage dwMessage, ref APPBARDATA pData) Private static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect) Private static extern IntPtr FindWindow(string lpClassName, string lpWindowName) Return SHAppBarMessage(AppBarMessage.GetTaskbarPos, ref _appBarData) != IntPtr.Zero ! SHAppBarMessage returns IntPtr.Zero **if it fails** Private static bool RefreshBoundsAndPosition() Return (TaskbarPosition)_appBarData.uEdge / Gets the taskbar's position on the screen. / Gets the display bounds when the taskbar is fully visible. Return Rectangle.FromLTRB(rect.Left, rect.Top, rect.Right, rect.Bottom) / Gets the current display bounds of the taskbar. Return ((ABS)state).HasFlag(ABS.AutoHide) / true if the taskbar is set to auto-hide is enabled otherwise, false. / Gets a value indicating whether the taskbar is automatically hidden when inactive. Return ((ABS)state).HasFlag(ABS.AlwaysOnTop) Int state = SHAppBarMessage(AppBarMessage.GetState, ref _appBarData).ToInt32()
/ This property always returns false on Windows 7 and newer. / true if the taskbar is always on top of other windows otherwise, false. / Gets a value indicating whether the taskbar is always on top of other windows. HWnd = FindWindow(Taskbar.ClassName, null) Private const string ClassName = "Shell_TrayWnd" ĬbSize = (uint)Marshal.SizeOf(typeof(APPBARDATA)), * Description: Class to get the taskbar's position, size and other properties. The code with all subsequent updates is available as a gist at. The only limitation I know of so far is that it does not return the correct bounds when multiple monitors are set to display in extended mode. RightDockedWidth = ( - LeftDockedWidth) - īottomDockedHeight = ( - TopDockedHeight) - ĭockedRects.X = ĭockedRects.Y = ĭockedRects.Width = LeftDockedWidth ĭockedRects.Height = ĭockedRects.X = ĭockedRects.Width = RightDockedWidth ĭockedRects.X = ĭockedRects.Width = ĭockedRects.Height = TopDockedHeight ĭockedRects.Y = ĭockedRects.Height = BottomDockedHeight īased on David's answer, here is a better implementation that uses P/Invoke to correctly determine the placement and size of the taskbar. TopDockedHeight = Math.Abs(Math.Abs() - Math.Abs()) LeftDockedWidth = Math.Abs(Math.Abs() - Math.Abs()) Rectangle DockedRects = new Rectangle įoreach (Screen TmpScrn in Screen.AllScreens) Public Rectangle FindDockedTaskBars(ref int DockedRectCounter) (Note: this ported code is untested) using System.Drawing RightDockedWidth = ( - LeftDockedWidth) - īottomDockedHeight = ( - TopDockedHeight) - ĭockedRects(DockedRectCounter).X = ĭockedRects(DockedRectCounter).Y = ĭockedRects(DockedRectCounter).Width = LeftDockedWidthĭockedRects(DockedRectCounter).Height = ĭockedRects(DockedRectCounter).X = ĭockedRects(DockedRectCounter).Width = RightDockedWidthĭockedRects(DockedRectCounter).X = ĭockedRects(DockedRectCounter).Width = ĭockedRects(DockedRectCounter).Height = TopDockedHeightĭockedRects(DockedRectCounter).Y = ĭockedRects(DockedRectCounter).Height = BottomDockedHeight If greater than 1, time to guess? Public Function FindDockedTaskBars(ByRef DockedRectCounter As Integer) As Rectangle()ĭim DockedRects( * 4) As Rectangle If that count is 1, element 0 of the returned array is the Rectangle occupied by the task bar. The following function returns an array of Rectangles, each representing a docked task bar, and writes the count to its byref parameter. The only way the location of the task bar could be definitively derived from bounds vs workingarea, would be if only one edge out of all screens had something docked to it. The code above incorrectly assumes that finding something docked to one edge excludes all other edges. For another, in theory there could be something docked on each edge of each given screen. For one thing, the task bar doesn't have to be on the primary screen, it can be dragged to any screen. It's actually way more complicated than is shown above.