Wednesday, February 18, 2009

[VC++] Accessing taskbar from your program & do operations

Are you interested in accessing windows taskbar and its child programs in your program? It's an easy thing; you may know that "Shell_TrayWnd" is the class name of the windows taskbar. You can use FindWindow() for obtaining handle to taskbar and you can get its child windows by using EnumChildWindows() or by explicitly get the window handle specifying the class name in FindWindowEx(). I shall demonstrate how to show/hide taskbar and its child windows programmatically.

Show/Hide Windows Taskbar

// Get the task bar window
HWND hSysTrayWnd = ::FindWindow( "Shell_TrayWnd", 0 );
// Toggle the show or hidden status
if( ::IsWindowVisible( hSysTrayWnd ))
{
::ShowWindow( hSysTrayWnd, SW_HIDE );
}
else
{
::ShowWindow( hSysTrayWnd, SW_SHOW );
}
Show/Hide System tray child window
// Get the shell tray window
HWND hSysTrayWnd = ::FindWindow ("Shell_TrayWnd", 0 );
if( hSysTrayWnd )
{
// Get the tray notification window
HWND hTrayNotifyWnd = ::FindWindowEx( hSysTrayWnd, 0, "TrayNotifyWnd", 0 );
if( hTrayNotifyWnd )
{
// Hide the tray notification window if shown or show if hidden
if( ::IsWindowVisible( hTrayNotifyWnd ))
{
::ShowWindow( hTrayNotifyWnd, SW_HIDE );
}
else
{
::ShowWindow( hTrayNotifyWnd, SW_SHOW );
}
}
}
Show/Hide System Clock
// Get the shell tray window
HWND hSysTrayWnd = ::FindWindow( "Shell_TrayWnd", 0 );
if( hSysTrayWnd )
{
// Get the tray notification window
HWND hTrayNotifyWnd = ::FindWindowEx( hSysTrayWnd, 0, "TrayNotifyWnd", 0 );
if( hTrayNotifyWnd )
{
// Get the tray clock window
HWND hTrayClockWnd = ::FindWindowEx( hTrayNotifyWnd, 0, "TrayClockWClass", 0);
if( hTrayClockWnd )
{
// Hide the tray clock if shown or show if hidden
if( ::IsWindowVisible( hTrayClockWnd ))
{
::ShowWindow( hTrayClockWnd, SW_HIDE );
}
else
{
::ShowWindow( hTrayClockWnd, SW_SHOW );
}
}
}
}
Show/Hide Start button
// Get the shell tray window
HWND hSysTrayWnd = ::FindWindow( "Shell_TrayWnd", 0 );
if( hSysTrayWnd )
{
// Get the start button
HWND hStartBtn = ::FindWindowEx( hSysTrayWnd, 0, "Button", "start" );
if( hStartBtn )
{
// Hide the start button if shown or show if hidden
if( ::IsWindowVisible( hStartBtn ))
{
::ShowWindow( hStartBtn, SW_HIDE );
}
else
{
::ShowWindow( hStartBtn, SW_SHOW );
}
}
}

No comments: