HOWTO: Find the Edge of a Task Bar

Last reviewed: January 29, 1998
Article ID: Q179908
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK)

SUMMARY

When you use the SHAppBarMessage() function to retrieve information about a task bar, you do not receive a message that indicates where the AppBar position is relative to the edges of the screen. You use ABE_LEFT, ABE_RIGHT, ABE_TOP, and ABE_BOTTOM to create the task bar, but you do not get a message call that returns the edge position after the task bar is created. This article shows how to find the edge of a task bar.

MORE INFORMATION

The following function called GetEdge() uses the message ABM_GETTASKBARPOS to get the bounding rectangle coordinates to determine where the task bar appears.

Sample Code

   void CMainFrame::OnGetTaskbarPos()  // Message handler.
      {
         // Get a pointer to the Windows task manager.
      CWnd *pwnd = FindWindow("Shell_TrayWnd", NULL);

      if (pwnd != NULL)
      {
         APPBARDATA abd;

         abd.cbSize = sizeof(APPBARDATA);
         abd.hWnd = phwnd->m_hWnd;

         SHAppBarMessage(ABM_GETTASKBARPOS, &abd);

         UINT uEdge = GetEdge(abd.rc);

         switch(uEdge)
         {
         case ABE_LEFT:
            break;
         case ABE_RIGHT:
            break;
         case ABE_TOP:
            break;
         case ABE_BOTTOM:
            break;
         default:
            AfxMessageBox("abd.uEdge not found");
                     return;
            }
         }
      }

      UINT CMainFrame::GetEdge(CRect rc)
      {
      UINT uEdge = -1;

      if (rc.top == rc.left && rc.bottom > rc.right)
      {
          uEdge = ABE_LEFT;
      }
      else if (rc.top == rc.left && rc.bottom < rc.right)
      {
          uEdge = ABE_TOP;
      }
      else if (rc.top > rc.left )
      {
          uEdge = ABE_BOTTOM;
      }
      else
      {
          uEdge = ABE_RIGHT;
      }

         return uEdge;
      }
Keywords          : UsrShell kbcode
Version           : WINNT
Platform          : winnt
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 29, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.