| Language: | C |
| Category: | System |
| Date: | 2008-06-17 |
| Author: | Michael Flenov |
| Attachment: | Download |
I want to tell you how to get access to the Windows Start button and the Windows tray bar. The tray bar is a special window in the system with a Shell_TrayWnd class name. What does it mean? It means that you can find this windows using FindWindow API function. Here is the example:
HWND hTrayBar;
hTrayBar= FindWindow("Shell_TrayWnd",NULL);
After that the hTrayBar variable will contain a handle to the system tray window. The Start button is a button on the system tray window. To find it we can use FindWindowEx API function:
HWND hButton; hButton= FindWindowEx(hTrayBar, 0,"Button", NULL);
You can show or hide Start button like any other window control in your application. For example:
HWND hTrayBar, hButton;
hTrayBar= FindWindow("Shell_TrayWnd",NULL);
hButton= FindWindowEx(hTrayBar, 0,"Button", NULL);
// hide the Start button
ShowWindow(hButton, SW_HIDE);
// wait for 50 msec
Sleep(50);
// show the start button
ShowWindow(hButton, SW_SHOW);
Sleep(50);
To show or hide a control we use ShowWindow function. A first parameter is a handle of control you want to show or hide. A second parameter is a SW_SHOW to show control or SW_HIDE to hide control. More information can be found on MSDN WEB site
Next example shows us how to force the Start button to get up and down:
hTaskBar= FindWindow("Shell_TrayWnd",NULL);
hButton= GetWindow(hTaskBar, GW_CHILD);
MainMenu=LoadMenu(hInstance, (LPCTSTR)IDC_STARTENABLE);
SetParent(hButton, 0);
int i;
int toppos=GetSystemMetrics(SM_CYSCREEN)-23;
// Set top-left window position
SetWindowPos(hButton, HWND_TOPMOST, 4, toppos, 50, 20, SWP_SHOWWINDOW);
UpdateWindow(hButton);
// the button gets up
for (i=0; i<50; i++)
{
toppos=toppos-4;
SetWindowPos(hButton, HWND_TOPMOST, 4, toppos, 50, 20, SWP_SHOWWINDOW);
Sleep(15);// wait for 15 milsec
}
// the button gets down
for (i=50; i>0; i--)
{
toppos=toppos+4;
SetWindowPos(hButton, HWND_TOPMOST, 4, toppos, 50, 20, SWP_SHOWWINDOW);
Sleep(15);// wait for 15 milsec
}
SetParent(hButton, hTaskBar);
Source codes can be found in attachment to the article.
Best regards Michael Flenov