Click here to Skip to main content
Click here to Skip to main content

Manipulating The Windows Taskbar

By , 11 Apr 2007
 
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.

// 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...

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)

About the Author

Nibu babu thomas
Software Developer Microsoft
India India
Member
Nibu has been programming for 6 years now. He loves programming. Not a geek but trying to be one.
 
Nibu loves playing guitar and piano in his spare time.
Nibu loves his family a lot and loves to spent time with them. He is married to a wonderful woman. Smile | :)
 
Nibu is passionate about leading a good christian life. He dedicates all his success to Jesus. In fact this is what he says "I am whatever I am by the grace of Jesus" Smile | :) .
 
He loves CodeProject.
 
He has got a programming tips and tricks site. You could help him improve with your suggestions.
 
Please visit bits and bytes. Your feedback is very important.
 
I brag here -> Random thoughts.
 
What I post on CodeProject or other forums has nothing to do with Microsoft or any of the companies that I work/worked for. These are my own ideas/thoughts unless otherwise explicitly mentioned.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Jokeresource hackermemberFatassCartmaN26 Jul '10 - 11:22 
some of these message numbers can be found with resource hacker Laugh | :laugh:
General5000 shows the "Switch User" dialog under 7/Vista/XPmemberJochen Baier3 Feb '10 - 5:24 
PostMessage(hShellWnd, WM_COMMAND, MAKELONG(5000, 0), NULL) shows the dialog to switch the user.
General517 locks desktop under Vista and 7 [modified]memberJochen Baier3 Feb '10 - 5:07 
PostMessage(hShellWnd, WM_COMMAND, MAKELONG(517, 0), NULL) will lock the desktop. Works with Vista and Seven.
 
modified on Wednesday, February 3, 2010 11:44 AM

Questionalways on top on/offmemberlengfy4 Feb '09 - 21:33 
System.Int32 iHandle;
iHandle = MyWin32.FindWindow("Shell_TrayWnd", string.Empty);
MyWin32.SendMessage(iHandle, 0x2b1, 7, 0);
MyWin32.SendMessage(iHandle, 0x581, 1, 0);
MyWin32.SendMessage(iHandle, 0x550, 0, 10001);
 
I have add these C# code want to set always on top on,but it can't work,it seems the MyWin32.SendMessage(iHandle, 0x581, 1, 0) failed, but i don't know why? can u help me?my os is winxp.
AnswerRe: always on top on/offmembervirusak39 Mar '09 - 7:17 
man, if u find this out, please tell me too..Unsure | :~ I searched the whole www for this Dead | X| . Maybe u will find it. If i will, i'll announce you. TNX!Thumbs Up | :thumbsup:
GeneralA little more informationmemberwhelkpeddle16 Nov '08 - 22:16 
Just a minor point (because I've gone through a fair bit of pain with this)...
 
Message 0x2B1 is WM_WTSSESSION_CHANGE.
It will not (at least in Vista/2008 Server) be sent to your application unless you execute the API function WTSRegisterSessionNotification.
 
The WParam values for this message are as follows:
WTS_CONSOLE_CONNECT = 1,
WTS_CONSOLE_DISCONNECT = 2,
WTS_REMOTE_CONNECT = 3,
WTS_REMOTE_DISCONNECT = 4,
WTS_SESSION_LOGON = 5,
WTS_SESSION_LOGOFF = 6,
WTS_SESSION_LOCK = 7,
WTS_SESSION_UNLOCK = 8,
WTS_SESSION_REMOTE_CONTROL = 9
 
Hope this adds a little more information.
GeneralPathetic : copy-paste of usenet post from... 1999memberkilt24 Jul '08 - 19:57 
All this has been posted in... 1999 in win32 api newsgroup (comp.os.ms-windows.programmer.win32) !
What a shame !
GeneralRe: Pathetic : copy-paste of usenet post from... 1999memberNibu babu thomas24 Jul '08 - 20:01 
kilt wrote:
All this has been posted in... 1999 in win32 api newsgroup (comp.os.ms-windows.programmer.win32) !
What a shame !

 
Shame on you Mr Bot! Look here[^], seems like you are into the habit of bad mouthing hard work done by others. Lazy fellow!
GeneralRe: Pathetic : copy-paste of usenet post from... 1999memberFlave7 Nov '09 - 10:37 
doesn't change the fact that you completely plagiarized your article
GeneralRe: Pathetic : copy-paste of usenet post from... 1999memberNibu babu thomas8 Nov '09 - 19:18 
It's a pity that people are saying that this work is plagiary. Frown | :( Wrote this article when I was working for CodeProject, Dundas (India).
 

Nibu babu thomas
Microsoft MVP for VC++

 
Code must be written to be read, not by the compiler, but by another human being.
 
Programming Blog: http://nibuthomas.wordpress.com

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 12 Apr 2007
Article Copyright 2006 by Nibu babu thomas
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid