简体   繁体   中英

How to show Cdialog with std::async

I have a derive class named A was inheritance from CDialog , I created the object to A named a and want to utilize the member function domodal to show dialog. Nonetheless, this dialog cannot show and parent window was block.

A a(this);

auto DlgResult = std::async(std::launch::async, &A::DoModal,&a);

DlgResult.wait();

if (DlgResult.get() == IDOK)
{
    std::wstring ss = a.get_text_fromdlg();
}

Can someone help me, thanks!

If I were you, I wouldn't wrestle w/ the Async and DoModal since the purpose of DoModal() is to wait for the response from the dialog to let the app know how to move forward..

Below, I've added a simpler option. Just create member variable pointer to a Dialog class, and then use Show Window. Also, in this instance, you may consider making the dialog topmost so you don't lose focus of it.

MFCClass1* m_pDlg = new MFCClass1();

void CMFCApplication1Dlg::OnBnClickedButton1()
{
    m_pDlg->Create(IDD_DIALOG1);
    m_pDlg->ShowWindow(SW_SHOWNORMAL);
    SetWindowPos(&m_pDlg->wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}

在此处输入图片说明

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