Q: Hide the application's taskbar icon
Answer:
First, let's get some terminology straight. The system tray is the little box
in the corner of the task bar where programs can display small icons. Some examples include
the SysAgent icon, and the Outlook icon when you get new mail. The taskbar is the toolbar that
stretches across the screen. This is where program icons are located. To hide a program's taskbar
icon, you call the ShowWindow function and pass the Application->Handle
window handle.
ShowWindow(Application->Handle, SW_HIDE);
To make the taskbar icon re-appear, simply change SW_HIDE to SW_SHOW.
ShowWindow(Application->Handle, SW_SHOW);
Note: You can hide the main form by setting its Visible property to false.
Note: Hiding the form's taskbar icon with ShowWindow is not permanent. Certain actions will cause the
taskbar icon to reappear. You can remove a program's taskbar icon and prevent it from ever appearing again by making
the hidden application window a tool window. Tool windows never have a taskbar icon. Making the application window a tool
window has the side effect of removing the program from the list of programs that appear when the user presses ALT-TAB.
You can make the application window a tool window by calling the API GetWindowLong and SetWindowLong
functions.
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
DWORD dwExStyle = GetWindowLong(Application->Handle, GWL_EXSTYLE);
dwExStyle |= WS_EX_TOOLWINDOW;
SetWindowLong(Application->Handle, GWL_EXSTYLE, dwExStyle);
try
{
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
return 0;
}
|