Q: How to start your dialog application in hidden mode?
A: If you put the function 'ShowWindow(SW_HIDE)' in your 'OnInitDialog()', it won't have any effect, because 'OnInitDialog()' always finishes with calling 'ShowWindow(SW_SHOW)'. But there is a workaround for that. Create a 'BOOL' member variable into your dialog class and set it to 'FALSE' in the constructor.
Now override the 'WM_WINDOWPOSCHANGING' message handler. Your code should look something like this to hide the dialog:Code:class CYourDialog : public CDialog { ... private: BOOL m_visible; }; CYourDialog::CYourDialog(CWnd* pParent /*=NULL*/) : CDialog(CYourDialog::IDD, pParent) { //... m_visible = FALSE; }
To make the dialog again visible, use the following code:Code:void CYourDialog::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) { if(!m_visible) { lpwndpos->flags &= ~SWP_SHOWWINDOW; } CDialog::OnWindowPosChanging(lpwndpos); }
Code://... m_visible = TRUE; ShowWindow(SW_SHOW); //...




Reply With Quote