
Can I start a dialog app initially hidden?
Quote:
>I need to write a dialog app that starts out initially hidden. Is there any
>other way besides creating a normal hidden window and calling DoModal from
>there? Windows seems to ignore the fact that I don't have a WS_VISIBLE flag
>set.
Gil,
I don't know of any way other than to have a hidden owner/parent
window. Here's a solution I've posted a few times before:
BOOL CInvDlgApp::InitInstance()
{
// Normal MFC generated code...
// Doctored version of BekiM's stealth code
// (m_wndOwner is a member CWnd I've 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;
Quote:
}
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;
Quote:
}
Dave
----
Address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow up email copies.