Click here to Skip to main content
15,893,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to create 5-6 dialog boxes in MFC, but there are some common controls on each dialog box, so i am thinking to create one parent dialog box which will contain these common controls and others will inherit from this parent dialog box.

e.g.
class CParentDlg:public CDialog {
          //common controls
  }
  class CChildDlg:public CParentDlg{
    //child related specific controls
  }

so when i do DoModal on child dialog box, then it should also show the controls of parent.

so can we do like this? if yes how?

[i have done things in above manner, but it is not showing the parent dialog box's controls on child dialog box]
Posted
Updated 24-May-11 21:20pm
v4
Comments
Sergey Alexandrovich Kryukov 25-May-11 2:04am    
Bad terminology! Those are not child and parent but Base and Derived.
You're doing it right, so what's the problem? Go ahead and do it.
--SA
sunnyram 25-May-11 2:42am    
I did it but it is not showing the controls of base dialog box on the derived dialog box on DoModal.
CPallini 25-May-11 3:40am    
You should post the relevant code, then.
sunnyram 25-May-11 3:58am    
class CBaseDlg : public CDialog
{
CBaseDlg(CWnd* pParent = NULL); // standard constructor
CBaseDlg(UINT nIDTemplate, CWnd* pParent = NULL); // constructor
}

class CChildDlg : public CBaseDlg
{
CChildDlg(CWnd* pParent = NULL): CBaseDlg(IDD, pParent){} // constructor
}

//and then calling the domodal
CChildDlg ChildDlgObj;
ChildDlgObj.DoModal();

//so it should show the parent dialog box controls on child dialog box. but for me it is not showing it.

1 solution

You cannot do it this way; dialog resources are not part of the class object and are not inherited. The dialog resource is compiled into the executable file and loaded when you invoke DoModal(). As far as I know the only way to achieve what you want to do is to use a common dialog resource and then add dynamic controls in the OnInitDialog() function. You could also take a look at the Common Dialogs[^] and create a customizable version of your own.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900