Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subclass CDialog

Status
Not open for further replies.

ahoodin

Programmer
Jul 25, 2001
48
US
I would like to subclass CDialog, to add functionality.
I can pretty easily subclass stuff in non-MFC applications.
How do I code that. I would like to substitute my new class for existing dialogs that use CDialog class.

Help me please!
Asher
 
The easiest way would be to go through the wizard. Design your dialog, right click it, class wizard, and create the class. It will automatically be added to the project.

Matt
 
What about the existing dialogs that already have been subclassed from CDialog. I want to use multiple inheritance, and how would I go about that?

1 I use CDialog as my base class.

2 in the header: class Csubtest : public CMyDialogClass
where it used to be: class Csubtest : public CDialog

Shouldnt that be enough? What other things am I overlooking?

ahoodin
 
Nope... looks right to me.

If you created a dialog or any control that had a specific ability (lets say drag and drop enabled).

So the big picture.

class MyDragDropDlg: public CDialog

and then if you wanted another dialog to have the properties of the DragAndDropDlg you could just create that dialog as I mentioned above and change the inheritance from public CDialog to public MyDragDropDlg

Matt
 
I get an error on CDialog::DoModal() on
the first line

ASSERT(m_lpszTemplateName != NULL || m_hDialogTemplate != NULL ||
m_lpDialogTemplate != NULL);

all these member vars are 0
ahoodin
 
are you calling DoModal with a pointer or an object? You may need to call "CreateWindow"

Matt
 
Here I am calling it like this:

Csubtest mytest;
mytest.DoModal();

CExistingDlg::CExistingDlg(CWnd* pParent /*=NULL*/)
: CMyDialog(CTestresizeDlg::IDD, pParent)
//was CDialog
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}



when I left it as CDialog, it errored out saying somthing about not taking 2 parameters.

ahoodin

PS: I have to be able to replace all the dialogs whether I call them with DoModal or not!
 
I believe what you need to do is this

Code:
CExistingDlg::CExistingDlg(CWnd* pParent /*=NULL*/)
: CMyDialog(pParent)
Code:
//was CDialog
{
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

if CMyDialog had a constructor that took 2 parameters then I am not sure why you are seeing the error that you are.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top