Click here to Skip to main content
15,878,809 members
Articles / Desktop Programming / MFC

Manipulating The Windows Taskbar

Rate me:
Please Sign up or sign in to vote.
4.54/5 (26 votes)
11 Apr 2007CPOL3 min read 173.1K   2.5K   59   42
Some useful messages for manipulating the Windows Taskbar
Sample screenshot

Introduction

Most often when visiting VC++ forums, we see questions like how to show the ShutDown dialog, Logoff dialog, how to lock the windows taskbar and others. Hence it quite fascinated me to try out a few things with the windows taskbar. The article is a result of this fascination. :)

Well this article is for those who don't know how to do this. This article simply lists the message numbers which when sent to the taskbar makes it do something (so don't expect too much). ;)

How I Did This

Well I started off by posting a few messages to the taskbar. I started off from Zero. It was a long and tedious process. The process was like:

  1. Post a message
  2. Then wait
  3. If nothing happens, post another
  4. If something happens, jot it down. Hehe

I know this is quite trivial, but anyway, this is how I did it. :)

The Message Numbers

Heh, now let me show you the real content of this article...

Note: I am using WM_COMMAND and the message number goes into the WPARAM parameter.

Serial. Msg Number Description Of The Message
1. 305 Displays the Start menu
2. 401 Displays Run Dialog
3. 402 Displays Logoff Dialog
4. 403 Command to cascade all toplevel windows
5. 404 Command to Tile Horizontally all top level windows
6. 405 Command to Tile Vertically all top level windows
7. 407 Shows the desktop. Do look at message number 419.
8. 408 Shows the Date and Time Dialog
9. 413 Shows taskbar properties
10. 415 Minimize all windows
11. 416

Maximize all windows. To see the effect of this command first do Minimize and then Maximize all.

12. 419 Well I am a bit confused about this message. This also shows the desktop. Maybe somebody can notice the difference.
13. 420 Shows task manager
14. 421 Opens Customize Taskbar Dialog
15. 424 Locks the taskbar
16. 503 Opens Help and Support Center Dialog
17. 505 Opens Control panel
18. 506 Shows the Shutdown computer dialog
19. 510 Displays the Printers and Faxes dialog
20. 41093 Displays Find Files Dialog
21. 41094 Displays Find Computers Dialog

Always on top attribute (Added on 4/12/2007)

Recently a guy asked me how to remove always on top attribute from the taskbar. So I thought of adding the piece of code that does this...

Msg Id is 0x02b1 WPARAM 0x7 -- Taskbar always on top
Msg Id is 0x02b1 WPARAM 0x8 -- Taskbar normal.

C++
// Set task taskbar always on top
::SendMessage(hShellWnd, 0x2b1, 7, 0);
::SendMessage(hShellWnd, 0x581/*WM_USER+385*/, 1, 0);
::SendMessage(hShellWnd, 0x550/*WM_USER+336*/, 0, 10001);

// Set taskbar always on top off
::SendMessage(hShellWnd, 0x2b1, 8, 0);
::SendMessage(hShellWnd, 0x581/*WM_USER+385*/, 1, 0);
::SendMessage(hShellWnd, 0x550/*WM_USER+336*/, 0, 10001);
::SendMessage(hShellWnd, 0x579/*WM_USER+377*/, 0, 0);

The Code that Sends the Message...

I know most of you know how to do this, but for beginners this could be tough. So hence here it is...

C++
UINT nEventIds[] =
{
 305,        //DisplayStartupMenu
 401,        //DisplayRunDialog
 402,        //DisplayLogoffDialog
 403,        //ArrangeCascade
 404,        //ArrangeTileHrz
 405,        //ArrangeTileVrt
 407,        //ShowDesktop
 408,        //ShowDateTimeDialog
 413,        //ShowTaskbarPrps
 415,        //MinAll
 416,        //MaxAll
 419,        //ShowDesktop2
 420,        //ShowTaskMngr
 421,        //TaskBrCustomizeNtfy
 424,        //LockTaskbar
 503,        //HelpAndSuppCenter
 505,        //ControlPanel
 506,        //TurnOffCompDialog
 510,        //PrintersAndFaxesDialog
 41093,      //FindFilesDialog
 41094       //FindComputers
}; 

// Does initialization, adds strings to combo based on 
// based on the above array.

void CHackTrayDlg::Init(void)
{ 
  m_cCmbEventList.AddString(_T("Start menu"));
  m_cCmbEventList.AddString(_T("Run dialog"));
  m_cCmbEventList.AddString(_T("Log off dialog"));
  m_cCmbEventList.AddString(_T("Cascade windows"));
  m_cCmbEventList.AddString(_T("Tile windows horizontally"));
  m_cCmbEventList.AddString(_T("Tile windows vertically"));
  m_cCmbEventList.AddString(_T("Show desktop"));
  m_cCmbEventList.AddString(_T("Date time dialog"));
  m_cCmbEventList.AddString(_T("Task bar properties"));
  m_cCmbEventList.AddString(_T("Minimize all"));
  m_cCmbEventList.AddString(_T("Maximize all"));
  m_cCmbEventList.AddString(_T("Show desktop 2"));
  m_cCmbEventList.AddString(_T("Show task manager"));
  m_cCmbEventList.AddString(_T("Task bar customize notifications")); 
  m_cCmbEventList.AddString(_T("Lock taskbar"));
  m_cCmbEventList.AddString(_T("Help and support center"));
  m_cCmbEventList.AddString(_T("Control panel"));
  m_cCmbEventList.AddString(_T("Turn off computer dialog"));
  m_cCmbEventList.AddString(_T("Printers and faxes dialog"));
  m_cCmbEventList.AddString(_T("Find files dialog"));
  m_cCmbEventList.AddString(_T("Find computers")); 
}

//Code for posting messages to the taskbar
void CHackTrayDlg::OnCbnSelendokCombo1()
{ 
  int selIndex = m_cCmbEventList.GetCurSel();
  if(selIndex != CB_ERR)
  {
    static HWND hShellWnd = ::FindWindow(_T("Shell_TrayWnd"), NULL);
        
    if(hShellWnd != NULL)
       ::PostMessage(hShellWnd, WM_COMMAND, MAKELONG(nEventIds[selIndex], 0), NULL); 
    else
       hShellWnd = ::FindWindow(_T("Shell_TrayWnd"), NULL); 
  }
}

Watch Out

You might have noticed the huge gap between the last few messages. I didn't find any in between this. I think there might be some but maybe I didn't notice it. For example, the Lock statusbar message number. Initially I didn't notice the difference but when I tried to resize the taskbar LOL then I realised something had happened. Heh I was quick to retest the whole thing to find out which message number caused the event.

How Can You Help Me

Well if you know of any other messages, please tell me. I will post them here along with the others.

Disclaimer

I don't know how reliable this information is. Well all of them work in WinXP and 2000. Please test the above information before using it. The author does not take any responsibility for any kind of damage caused due to this article. Please use this at your own risk.

History

  • Modified on 4/12/2007 (Added code for removing always on top attribute from taskbar)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Microsoft
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
AnswerShow the desktop Pin
rusnuker21-Feb-23 12:45
rusnuker21-Feb-23 12:45 
Jokeresource hacker Pin
FatassCartmaN26-Jul-10 11:22
FatassCartmaN26-Jul-10 11:22 
General5000 shows the "Switch User" dialog under 7/Vista/XP Pin
Jochen Baier3-Feb-10 5:24
Jochen Baier3-Feb-10 5:24 
General517 locks desktop under Vista and 7 [modified] Pin
Jochen Baier3-Feb-10 5:07
Jochen Baier3-Feb-10 5:07 
Questionalways on top on/off Pin
lengfy4-Feb-09 21:33
lengfy4-Feb-09 21:33 
AnswerRe: always on top on/off Pin
virusak39-Mar-09 7:17
virusak39-Mar-09 7:17 
GeneralA little more information Pin
whelkpeddle16-Nov-08 22:16
whelkpeddle16-Nov-08 22:16 
GeneralPathetic : copy-paste of usenet post from... 1999 Pin
kilt24-Jul-08 19:57
kilt24-Jul-08 19:57 
GeneralRe: Pathetic : copy-paste of usenet post from... 1999 Pin
Nibu babu thomas24-Jul-08 20:01
Nibu babu thomas24-Jul-08 20:01 
GeneralRe: Pathetic : copy-paste of usenet post from... 1999 Pin
Flave7-Nov-09 10:37
Flave7-Nov-09 10:37 
GeneralRe: Pathetic : copy-paste of usenet post from... 1999 Pin
Nibu babu thomas8-Nov-09 19:18
Nibu babu thomas8-Nov-09 19:18 
GeneralListen if Startmenu opened Pin
Danielku1523-May-08 7:15
Danielku1523-May-08 7:15 
QuestionHow to catch the event when some new program starts? Pin
ebody19-May-08 1:45
ebody19-May-08 1:45 
GeneralVISTA... Pin
TalSt7-Apr-08 20:15
TalSt7-Apr-08 20:15 
GeneralRe: VISTA... Pin
Nibu babu thomas7-Apr-08 20:20
Nibu babu thomas7-Apr-08 20:20 
GeneralRe: VISTA... Pin
TalSt7-Apr-08 21:07
TalSt7-Apr-08 21:07 
GeneralRe: VISTA... Pin
Nibu babu thomas7-Apr-08 21:24
Nibu babu thomas7-Apr-08 21:24 
GeneralIts Really Great Pin
Hiran Das18-Aug-06 4:41
Hiran Das18-Aug-06 4:41 
GeneralWell done! Pin
AndrewVos15-Aug-06 23:22
AndrewVos15-Aug-06 23:22 
GeneralRe: Well done! Pin
Nibu babu thomas15-Aug-06 23:49
Nibu babu thomas15-Aug-06 23:49 
AndrewVos wrote:
Thanks so much for your contribution!


Did I help you in some way. Big Grin | :-D


Nibu thomas
A Developer

Programming tips[^]  My site[^]

GeneralRe: Well done! Pin
AndrewVos16-Aug-06 1:21
AndrewVos16-Aug-06 1:21 
GeneralRe: Well done! Pin
Nibu babu thomas16-Aug-06 17:22
Nibu babu thomas16-Aug-06 17:22 
GeneralRe: Well done! Pin
AndrewVos16-Aug-06 22:53
AndrewVos16-Aug-06 22:53 
GeneralRe: Well done! Pin
Nibu babu thomas17-Aug-06 17:28
Nibu babu thomas17-Aug-06 17:28 
GeneralCode in C# Pin
Drew Noakes9-Aug-06 2:47
Drew Noakes9-Aug-06 2:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.