Search code examples
windowsvisual-c++mfcdiamond-problem

MFC - encountering deadly diamond of death


A newbie here in windows programming.

I want to make a dialogbox that uses both CPropertyPage and CDHtmlDialog?

class CPropertyPage : public CDialog  
class CDHtmlDialog  : public CDialog

Since I can't change the inheritance for each of the above case to "virtual public", is it still possible to make a dialog that has some fields from CPropertyPage and some forms from CDHtmlDialog?


Solution

  • You can create the HTML dialog as child dialog of property page. The only problem is that child dialog closes if user pressed cancel. You have to override CDHtmlDialog::OnCancel. Example:

    class CMyDHtmlDialog : public CDHtmlDialog
    {
        void OnCancel()
        {
            //GetParent()->GetParent()->PostMessage(WM_COMMAND, IDCANCEL);
        }
    };
    
    class CMyPropertyPage : public CPropertyPage
    {
        CMyDHtmlDialog child;
        BOOL OnInitDialog()
        {
            BOOL res = CPropertyPage::OnInitDialog();
            child.Create(IDD_HTML, this);
            CRect rc;
            GetClientRect(&rc);
            child.SetWindowPos(NULL, 0, 0, rc.Width(), rc.Height(), SWP_SHOWWINDOW);
            return res;
        }
    };