Click to See Complete Forum and Search --> : Changing the dialog template resource file of a class based on a generic class with a different temp


Abu Musa
May 11th, 1999, 04:23 AM
Hi,

I want to write some generic classes for dialog screens with a standard dialog template which can be changed to a template (with the same controls but also some additional ones) in a class based on the generic class.

e.g.
Generic class CGeneric (Template: ID_DIALOG_EDIT)
CGeneric based class CDerived (Template: ID_DIALOG_BROWSE)

Thanks

eric33
May 11th, 1999, 06:11 AM
Does your template a simple resource in your resource file ?

If yes it is very sample to change the resource use by a CDialog class.
Look at the constructor of your CDialog class. It normally calls the CDialog based class constructor passing IDD as parameter. IDD is the resource id and is defines in the your class header.

So just change your CDialog constructor by this :


CMyDialog::CMyDialog( UINT id, CWnd* pParent )
: CDialog(id,pParent)




So you just have to declare your instances by passing the identifier.


CMyDialog dlg1(ID_DIALOG_EDIT);
CMyDialog dlg2(ID_DIALOG_BROWSE);




But be carefull. The two dialog templates must have the same controls identifiers if you use the DDX (members variables linked to resources).

I hope this could help.

Abu Musa
May 11th, 1999, 11:41 AM
Hi,

Thanks for the reply which has pointed me in the right direction, but I have a class CMyDerived derived from CMyDialog which has just a simple constructor and destructor:

CDlgDerived::CDlgDerived()
{

}

CDlgDerived::~CDlgDerived()
{

}
I how would I change the template from that specified in the header file CMyDialog

enum { IDD = IDD_DLG_EDIT };

Thanks

eric33
May 12th, 1999, 04:36 AM
So if i understand CDlgDerived is derived from CMyDialog and not CDialog.

Note that CMyDialog in my example is just a dialog class derived for CDialog. You don't have to derived your class from CMyDialog but just from CDialog.

Hovewer if CDlgDerived is derived from CMyDialog and CMyDialog derived from CDialog then here is the solution.

The first step change the constructor of CMyDialog as this :


CMyDialog::CMyDialog( UINT id, CWnd* pParent ) : CDialog(id,pParent)




Note that you can change the actual constructor or you can add this new one. In the second method you keep the original constructor which is maybe used elsewhere in your code.


Then the second step is to change the constructor of your derived class.


CDlgDerived::CDlgDerived( UINT id, CWnd* pParent ) : CMyDialog(id,pParent)




OR


CDlgDerived::CDlgDerived( CWnd* pParent ) : CMyDialog(CDlgDerived::IDD,pParent)




Hope this help.

Abu Musa
May 12th, 1999, 10:20 AM
Thanks a lot, this works well. I've tried to use the same principle for CFormView derived classes but is proving difficult. Can you give me any example for this?
I am calling the derived class using RUNTIME_CLASS and IMPLEMENT_DYNCREATE:

CMultiDocTemplate* temp = new CMultiDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CClassesDoc),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CViewDetails));

Base class constructor:
CClassesView::CClassesView()
: CFormView(CClassesView::IDD)
{
//{{AFX_DATA_INIT(CClassesView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT

}


Derived class constructor:
IMPLEMENT_DYNCREATE(CViewDetails, CClassesView)

CViewDetails::CViewDetails()
{

}

eric33
May 14th, 1999, 04:17 AM
I do not know exactly what is the problem.

But do not forget

DECLARE_DYNCREATE(CViewDetails)



in the class CViewDetails declaration


Then do not forget too :

IMPLEMENT_DYNCREATE(CClassesView)



AND

DECLARE_DYNCREATE(CViewDetails)




Try this.

Therefore what is the exact problem with the declaration of the document template ?