简体   繁体   中英

In MFC, How can I have a button to create several dialog instances successively without closing them?

I've already implemented a dialog with a button on it.
When the user clicks the button, a new dialog is shown. But the problem is the user can't click the button unless I close the new dialog.

How can I let the user click the button without closing the new dialog instances?

Here is the code for the button clicking part:

void CMyprojDlg::OnClicked()
{
    dialognewone mydia;
    mydia.DoModal();
}

You should create a modeless dialog dynamically:

void CMyprojDlg::OnClicked()

{
      // Note that: you should free memory by yourself when you close the dialog
      dialognewone *mydia = new dialognewone(); 
      mydia->Create(IDD_DIALOG1);   // create a modeless dialog
      mydia->ShowWindow(SW_SHOWNORMAL);  // show a modeless dialog
}

According to the keyword by Michael Walz' Comment .
I've changed my code into

void CMyprojDlg::OnClicked() 
{
    DialogClassName *dia = new DialogClassName;
    dia->Create(IDNumberOfTemplate,this);
    dia->ShowWindow(SW_SHOW);
}

And It works.

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