
| Last Modification: December 11, 1999 |
How do I prevent my application showing a button on the taskbar?
One method is to give your window the WS_EX_TOOLWINDOW style. However, this
has the side effect of making your application's caption bar much smaller
than a normal caption bar, and may not be ideal.
The best method is to make the application's top level
window have a parent window that is invisible.
One variation on this is how to stop a dialog application from showing up on the taskbar. This is a little more involved:
Create a normal MFC dialog application. In InitInstance(), create an
invisible top level window before the application dialog constructor. Pass
the invisible window as the parent of the dialog and call DoModal.
In the dialog's OnInitDialog() handler, modify the style of the dialog
window to remove the WS_EX_APPWINDOW style.
Here's the relevant bits of code:
BOOL CInvDlgApp::InitInstance()
{
// Normal MFC generated code...
// Altered version of BekiM's stealth code
// (m_wndOwner is a CWnd member variable added to
// the application class)
if ( m_wndOwner.m_hWnd == NULL )
{
LPCTSTR pstrOwnerClass = AfxRegisterWndClass(0);
if ( !m_wndOwner.CreateEx(0, pstrOwnerClass, _T(""),
WS_POPUP, CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL, 0) )
return FALSE;
}
CInvDlgDlg dlg( &m_wndOwner );
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Destroy the invisible window
if (m_wndOwner.m_hWnd != NULL)
m_wndOwner.DestroyWindow();
return FALSE;
}
BOOL CInvDlgDlg::OnInitDialog()
{
// Normal MFC generated template code....
// TODO: Add extra initialization here
/* Remove the WS_EX_APPWINDOW style */
ModifyStyleEx( WS_EX_APPWINDOW, 0 );
return TRUE;
}
The dialog is displayed as normal, you can Alt+Tab to it, but there's no button on the taskbar for it.
References and Samples: