简体   繁体   中英

CDHtmlDialog - make it modal?

I am popping up a CDHtmlDialog box when user clicks inside a another dialog box. Here is the pseudo code

CMyClass{
    CDHtmlDialog * m_htmlDialog;
}

CMyClass::OnInitDialog(){
     m_htmlDialog = new CDHtmlDialog(IDD_DIALOG_EMAIL, IDR_HTML_SUBMIT_EMAIL);
}

CMyClass::OnBnClickSendEmail{

     m_htmlDialog->Create(IDD_DIALOG_EMAIL);
     //m_htmlDialog->DoModal();
     m_htmlDialog->ShowWindow(SW_SHOWNORMAL);
}

The code runs fine when the DoModal is commented. But the problem is that the Html Dialog is not modal and I can click on the background forms and dialogs. I want the Html dialog to be modal and when I uncomment the DoModal() line the code crashes.

This is how I display a modal dialog, when it begins as a null pointer:

auto *pDlgEditor = new CSomeDlg(this);
if (pDlgEditor != nullptr)
{
    pDlgEditor->DoModal();

    delete pDlgEditor;
}

Notice that I am passing this which is the owner for the window.

The actual class itself specifies the dialogue resource:

CSomeDlg::CChristianLifeMinistryEditorDlg(CWnd* pParent /*=NULL*/)
    : CDialogEx(IDD_DIALOG_EXAMPLE, pParent))

I realise that my code doesn't show a CDHtmlDialog ... According to the documentation there are 3 constructors:

 CDHtmlDialog(); CDHtmlDialog( LPCTSTR lpszTemplateName, LPCTSTR szHtmlResID, CWnd *pParentWnd = NULL); CDHtmlDialog( UINT nIDTemplate, UINT nHtmlResID = 0, CWnd *pParentWnd = NULL); 

The third parameter is the parent which defaults to NULL . Try passing this as the third parameter.

Now, if you are inside a popup modaless window when you do the above the parent will be the modaless window. But if you pass the modaless windows' parent then that will become the owner instead. We don't have full information so the above is just generic advice.


Note that the documentation states that if you leave the pParentWnd as the default ( NULL ):

If it is NULL , the dialog object's parent window is set to the main application window.

So, it might not necessarily use the parent you expect, which is why it is good to specify it yourself.

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