Expand/Collapse System Notification Area programmatically.

9 04 2008


Windows system task bar have System notification area. There is an arrow button nearby that by which we can Expand or collapse the System notification Area. Did you notice that while minimizing yahoo messenger, it displays a message that “Yahoo messenger will be still running in the system tray”. While displaying such as message, it will be nice to animate the Notification area by expanding and collapsing it.


See the code snippet. I guess, its self explanatory.

// Find the Shell Tray Window.
HWND hTrayWnd = ::FindWindowEx( 0,
                                0,
                                _T("Shell_TrayWnd"),
                                _T(""));
// Find the Tray notification window,
// which is a child of ShellTrayWidnow.
HWND hTrayNotifyWnd = ::FindWindowEx( hTrayWnd,
                                      0,
                                      _T("TrayNotifyWnd"),
                                      _T(""));
// Find the Button which is a child of ShellTrayWidnow.
HWND hButton = ::FindWindowEx( hTrayNotifyWnd,
                               0,
                              _T("Button"),
                              _T(""));

// Now get the DialogControlID of the button.
UINT DlgId = ::GetDlgCtrlID( hButton );

// Send a WM_COMMAND message, so the button reacts.
::SendMessage( hTrayNotifyWnd, WM_COMMAND, DlgId, 0 );

// Wait a bit to have an animation effect.
Sleep( 1000 );

// Send WM_COMMAND message once again.
::SendMessage( hTrayNotifyWnd, WM_COMMAND, DlgId, 0 );


Targeted Audiance – Intermediate

Advertisements