Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2008

Tip: Looking for answers? Try searching our database.

TaskBar height and location?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Terry Wahl - 16 Jan 2008 16:57 GMT
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
Mattias Sjögren - 16 Jan 2008 20:24 GMT
>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

If you don't mind calling native APIs with PInvoke, you can use
SHAppBarMessage(ABM_GETTASKBARPOS).

http://msdn2.microsoft.com/en-us/library/bb762108(VS.85).aspx

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Terry Wahl - 18 Jan 2008 18:59 GMT
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

   }
}

> >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:
[quoted text clipped - 8 lines]
>
> Mattias

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.