简体   繁体   中英

MFC: Creating modeless dialog box without displaying

I'm trying to create a simple modeless dialog box which I'm creating from my CWinApp derived InitInstance() function.

BOOL CMyApp::InitInstance()
{
    ...
    m_pMyDialog = new CMyDialog();
    m_pMyDialog->Create(CMyDialog::IDD);
    ...
    retrun TRUE;
}

I've created the dialog template in the resource editor and the WS_VISIBLE bit is unset. My intention is to avoid showing the dialog until I explicitly call ShowWindow(SW_SHOW) but for some reason the call to Create displays the dialog.

I've tried to change the return value of OnInitDialog() to FALSE but that doesn't work.

I've even tried to call ModifyStyle() in case something else is setting the WS_VISIBLE bit.

int CMyDialog::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
   if (CDialog::OnCreate(lpCreateStruct) == -1)
      return -1;

   ModifyStyle(WS_VISIBLE, 0);   

   return 0;

 }

That doesn't work either. In all cases, after I call Create the dialog is displayed which isn't how I've read it should work.

The problem was with AnimateWindow() which was causing the dialog to display prematurely.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM