TaskBar height and location?

  • Thread starter Thread starter Terry Wahl
  • Start date Start date
T

Terry Wahl

I have developed a custom dialog that is popped up when the user hovers over
a notify icon in the system tray. Is there a way to obtain the following:

Taskbar Height
Taskbar Location

Thanks for your help in advance,
Terry
 
Thanks Mattias Sjögren,

Your post help quite a bit. Below is the C# code that I wrote.
Thanks again,
Terry

using System;
using System.Runtime.InteropServices;


namespace Tcm.WinForm.TcmWorkFlowMonitorUi
{
partial class MainForm
{
[DllImport("SHELL32", CallingConvention = CallingConvention.StdCall)]
static extern uint SHAppBarMessage(int dwMessage, ref APPBARDATA
pData);

#region Struct RECT
[StructLayout(LayoutKind.Sequential)]
struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
#endregion

#region Struct APPBARDATA
[StructLayout(LayoutKind.Sequential)]
struct APPBARDATA
{
public int cbSize;
public IntPtr hWnd;
public int uCallbackMessage;
public int uEdge;
public RECT rc;
public IntPtr lParam;
}
#endregion

#region Struct ABMsg
enum ABMsg : int
{
ABM_NEW = 0,
ABM_REMOVE = 1,
ABM_QUERYPOS = 2,
ABM_SETPOS = 3,
ABM_GETSTATE = 4,
ABM_GETTASKBARPOS = 5,
ABM_ACTIVATE = 6,
ABM_GETAUTOHIDEBAR = 7,
ABM_SETAUTOHIDEBAR = 8,
ABM_WINDOWPOSCHANGED = 9,
ABM_SETSTATE = 10
}
#endregion

#region Struct ABEdge
enum ABEdge : int
{
ABE_LEFT = 0,
ABE_TOP,
ABE_RIGHT,
ABE_BOTTOM
}
#endregion

#region Enum ABState
enum ABState : int
{
ABS_MANUAL = 0,
ABS_AUTOHIDE = 1,
ABS_ALWAYSONTOP = 2,
ABS_AUTOHIDEANDONTOP = 3,
}
#endregion

#region Enum TaskBarEdge
private enum TaskBarEdge : int
{
Bottom,
Top,
Left,
Right
}
#endregion

#region GetTaskBarInfo
/// <summary>
/// Method returns information about the Window's TaskBar.
/// </summary>
/// <param name="taskBarEdge">Location of the TaskBar
(Top,Bottom,Left,Right).</param>
/// <param name="height">Height of the TaskBar.</param>
/// <param name="autoHide">AutoHide property of the TaskBar.</param>
private void GetTaskBarInfo(out TaskBarEdge taskBarEdge, out int
height, out bool autoHide)
{
APPBARDATA abd = new APPBARDATA();

height = 0;
taskBarEdge = TaskBarEdge.Bottom;
autoHide = false;

#region TaskBarEdge & Height
uint ret = SHAppBarMessage((int)ABMsg.ABM_GETTASKBARPOS, ref abd);
switch (abd.uEdge)
{
case (int)ABEdge.ABE_BOTTOM:
taskBarEdge = TaskBarEdge.Bottom;
height = abd.rc.bottom - abd.rc.top;
break;
case (int)ABEdge.ABE_TOP:
taskBarEdge = TaskBarEdge.Top;
height = abd.rc.bottom;
break;
case (int)ABEdge.ABE_LEFT:
taskBarEdge = TaskBarEdge.Left;
height = abd.rc.right - abd.rc.left;
break;
case (int)ABEdge.ABE_RIGHT:
taskBarEdge = TaskBarEdge.Right;
height = abd.rc.right - abd.rc.left;
break;

}
#endregion

#region TaskBar AutoHide Property
abd = new APPBARDATA();
uint uState = SHAppBarMessage((int)ABMsg.ABM_GETSTATE, ref abd);
switch (uState)
{
case (int)ABState.ABS_ALWAYSONTOP:
autoHide = false;
break;
case (int)ABState.ABS_AUTOHIDE:
autoHide = true;
break;
case (int)ABState.ABS_AUTOHIDEANDONTOP:
autoHide = true;
break;
case (int)ABState.ABS_MANUAL:
autoHide = false;
break;
}
#endregion
}
#endregion

}
}
 
Back
Top