Re: How to DoModal a CDialog initially invisible
"Dansk" <dansk@laouilest.com> wrote in message
news:uHyeUyooHHA.4552@TK2MSFTNGP04.phx.gbl...
Hi all,
Under specific circunstances, I need to start my dialog-based app
invisible.
Make a hidden window the main window of your app, not the dialog:
CYourApp::InitInstance()
{
...
CMainWnd *pMainWnd = new CMainWnd;
if ( !pMainWnd->Init() )
return FALSE;
m_pMainWnd = pMainWnd;
return TRUE;
}
where
//// [mainwnd.h]
class CMainWnd : public CFrameWnd
{
public:
CMainWnd();
BOOL Init();
protected:
virtual ~CMainWnd();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMainWnd)
protected:
//}}AFX_VIRTUAL
// Generated message map functions
protected:
//{{AFX_MSG(CMainWnd)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
}
//// [mainwnd.cpp]
CMainWnd::CMainWnd()
{
}
CMainWnd::~CMainWnd()
{
}
BOOL CMainWnd::Init()
{
CRect rcWnd (0, 0, 1, 1); // can be anything because window is hidden
if (!CreateEx (0, AfxRegisterWndClass(0), NULL, WS_POPUP, rcWnd, NULL,
0))
return FALSE;
return TRUE;
}
BEGIN_MESSAGE_MAP(CMainWnd, CFrameWnd)
//{{AFX_MSG_MAP(CMainWnd)
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// CMainWnd message handlers
int CMainWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}
But, how does the user make your dialog visible? In my programs,
CMainWnd::OnCreate() creates a tray icon. When the user double-clicks the
icon, CMainWnd gets a message, then shows the modal dialog. You could adapt
this to have CMainWnd show your dialog under applicable circumstances.
-- David