Hiding/Showing the Windows TaskBar

I was writing an application which had a requirement saying that the Windows taskbar needs to be hidden. While looking out for source code, I came across SystemParametersInfo() API in MSDN, which retrieves the size of the work area on the primary display monitor. The work area is the portion of the screen not obscured by the system taskbar or by application desktop toolbars.

Now, my only requirement was to retrieve the handle to the TaskBar window. I used CWnd's FindWindow() function to do this. FindWindow() takes two parameters, the window's class name (a WNDCLASS structure) and the windw name (the windows title). You may retrieve these properties of the window using the SPY++'s FindWindow utility that comes with Visual Studio.

Using these two functions I came up with the following code which you can use to either show or hide the taskbar and utilize the full desktop.

void gShowHideTaskBar(BOOL bHide /*=FALSE*/)
{
 CRect rectWorkArea = CRect(0,0,0,0);
 CRect rectTaskBar = CRect(0,0,0,0);

 CWnd* pWnd = CWnd::FindWindow("Shell_TrayWnd", "");

 if( bHide )
 {
  // Code to Hide the System Task Bar
  SystemParametersInfo(SPI_GETWORKAREA,
                       0,
                       LPVOID)&rectWorkArea,
                       0);

  if( pWnd )
  {
   pWnd->GetWindowRect(rectTaskBar);
   rectWorkArea.bottom += rectTaskBar.Height();
   SystemParametersInfo(SPI_SETWORKAREA,
                        0,
                        LPVOID)&rectWorkArea,
                        0);

   pWnd->ShowWindow(SW_HIDE);
  }
 }
 else
 {
  // Code to Show the System Task Bar
  SystemParametersInfo(SPI_GETWORKAREA,
                       0,
                       (LPVOID)&rectWorkArea,
                       0);
  if( pWnd )
  {
   pWnd->GetWindowRect(rectTaskBar);
   rectWorkArea.bottom -= rectTaskBar.Height();
   SystemParametersInfo(SPI_SETWORKAREA,
                        0,
                        (LPVOID)&rectWorkArea,
                        0);

   pWnd->ShowWindow(SW_SHOW);
  }
 }
}

Downloads

Download source - 2 Kb
Download demo project (including release build) - 28 Kb


Comments

  • Problem in Win2k

    Posted by Legacy on 08/06/2003 12:00am

    Originally posted by: Azhar

    After Program terminination the full size for windows decreases and all windows when maximized have a distance b/w their bottom line and task bar.
    

    Reply
  • How to move the entire Desktop(whole display)??

    Posted by Legacy on 07/02/2003 12:00am

    Originally posted by: sonu

    How are we able to move the entire display window.
    
    The display window here means the entire desktop screen which includes the taskbars and all other related windows.

    When executed the display window should be shifted from its reference to the new allocated position.

    Reply
  • how can i add item to?

    Posted by Legacy on 11/26/2002 12:00am

    Originally posted by: lfr

    how can i add item to the tray bar?
    
    Any one please provide source code

    Reply
  • Why don't other windows shrink to new workarea size?

    Posted by Legacy on 10/07/2002 12:00am

    Originally posted by: Aisenberg Mor

    If I build an application that uses the:
    SystemParametersInfo(SPI_SETWORKAREA, 0, &Temp, 0);

    (Kind of task bar utility)

    Windows who where maximized before are now under the taskbar how can I make them shrink to proper size?

    -Mor-

    Reply
  • After program termiation

    Posted by Legacy on 09/11/2002 12:00am

    Originally posted by: Nikhil Alulkar

    Dear users,
    Please add the to Show The taskbar at the time of program termination so that taskbar setting will be restored.

    --Nikhil Alulkar.

    Reply
  • What about the Start menu???

    Posted by Legacy on 07/18/2001 12:00am

    Originally posted by: Martin Cannon

    It seems to me that this code is completely useless because even if you hide the taskbar, you can still use the start keyboard key (or Ctrl+Esc) to display the start menu!?!
    If anyone knows how to restrict the start button (while still starting the explorer.exe shell on startup) please let me know, I've been trying for ages!!!

    Reply
  • An easier way

    Posted by Legacy on 05/03/2001 12:00am

    Originally posted by: Hadi Dayvary

    I think this way is better:
    
    

    void ShowHideTaskBar(BOOL bHide)
    {
    // find taskbar window
    CWnd* pWnd = CWnd::FindWindow("Shell_TrayWnd","");
    if(!pWnd )
    return;
    if( bHide )
    pWnd->ShowWindow(SW_HIDE);
    else
    pWnd->ShowWindow(SW_SHOW);
    }

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • Live Event Date: September 17, 2014 @ 12:00 p.m. ET / 9:00 a.m. PT Another day, another end-of-support deadline. You've heard enough about the hazards of not migrating to Windows Server 2008 or 2012. What you may not know is that there's plenty in it for you and your business, like increased automation and performance, time-saving technical features, and a lower total cost of ownership. Check out this upcoming eSeminar and join Rich Holmes, Pomeroy's practice director of virtualization, as he discusses the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds