Can I return a custom value from a dialog box's DoModal function?

前端 未结 3 1640
灰色年华
灰色年华 2020-12-21 15:47

What I wish to do is, after creating a dialog box with DoModal() and pressing OK in the box to exit it, to have a custom value returned. For example, a couple o

3条回答
  •  星月不相逢
    2020-12-21 16:10

    I don't think it is possible (or reasonable). DoModal returns an INT_PTR, which is usually used to know what the user did to exit the dialog (press OK, Cancel, there was an error...). The way to do it is have public members or functions which the dialog set and the caller of the dialog can access to know the values. Like so:

    CMyDialog dlg;
    
    if(dlg.DoModal()==IDOK)
    {
        CString str1 = dlg.m_String1;
        CString str2 = dlg.GetString2();
    }
    

    It's the way you would use CFileDialog, for example.

提交回复
热议问题