简体   繁体   English

如何使用 std::async 显示 Cdialog

[英]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.我有一个名为 A 的派生类是从CDialog继承的,我创建了一个名为 a 的对象,并希望利用成员函数 domodal 来显示对话框。 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..如果我是你,我不会与 Async 和 DoModal 搏斗,因为 DoModal() 的目的是等待对话框的响应,让应用程序知道如何前进。

Below, I've added a simpler option.下面,我添加了一个更简单的选项。 Just create member variable pointer to a Dialog class, and then use Show Window.只需创建指向 Dialog 类的成员变量指针,然后使用 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);
}

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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