mfc >> Problem compiling class derived from CDialog

by Rick Lee » Wed, 03 Dec 2003 15:02:37 GMT

This should be simple, so please help me find my dumb mistake.

I have a custom base class derived from CDialog, and I need to derive
several more classes from it. I followed KB article 99601, which seems
to describe my situation exactly.

1. Both my base class and my derived class were made using Class Wizard.
2. Both used CDialog as their base class.
3. In my derived class, all references to CDialog were changed to my
base class.
4. The .clw file was deleted and regenerated.

When the project was recompiled, one error was generated:
error C2660: 'CProjectsSetupDlg::CProjectsSetupDlg' : function does not
take 2 parameters

(Note that CProjectsSetupDlg is my base class and CProjectsAddDlg is my
derived class.)

Thanks for looking at this,
Rick Lee

/*
*
* THIS IS THE .CPP FILE
*
*/

/////////////////////////////////////////////////////////////////////////////
// CProjectsAddDlg dialog


CProjectsAddDlg::CProjectsAddDlg(CWnd* pParent /*=NULL*/)
: CProjectsSetupDlg(CProjectsAddDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CProjectsAddDlg)
m_AddProjectDesc = _T("");
m_AddProject_ID = _T("");
m_AddProjectName = _T("");
//}}AFX_DATA_INIT
}


void CProjectsAddDlg::DoDataExchange(CDataExchange* pDX)
{
CProjectsSetupDlg::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CProjectsAddDlg)
DDX_Text(pDX, IDC_PROJ_SETUP_DESCRIPTION, m_AddProjectDesc);
DDV_MaxChars(pDX, m_AddProjectDesc, PROJECT_DESC_LENGTH);
DDX_Text(pDX, IDC_PROJ_SETUP_ID, m_AddProject_ID);
DDV_MaxChars(pDX, m_AddProject_ID, PROJECT_ID_LENGTH);
DDX_Text(pDX, IDC_PROJ_SETUP_NAME, m_AddProjectName);
DDV_MaxChars(pDX, m_AddProjectName, PROJECT_NAME_LENGTH);
//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CProjectsAddDlg, CProjectsSetupDlg)
//{{AFX_MSG_MAP(CProjectsAddDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CProjectsAdd message handlers

void CProjectsAddDlg::OnOK()
{
CString oldItemText;

// TODO: Add extra validation here
this->UpdateData(TRUE);
m_AddProject_ID.TrimLeft();
m_AddProject_ID.TrimRight();
m_AddProjectName.TrimLeft();
m_AddProjectName.TrimRight();
m_AddProjectDesc.TrimLeft();
m_AddProjectDesc.TrimRight();

// Project ID must not be empty.
if (m_AddProject_ID == "") {
AfxMessageBox("Please enter a value for Project ID");
return;
}

// Project ID must be unique.
int nItems = localProjectList.GetSize();
for (int i=0; i<nItems; i++) {
oldItemText = localProjectList[i].GetIndexedMember(1);
if (oldItemText.CompareNoCase(m_AddProject_ID) == 0) {
AfxMessageBox("Please enter a unique value for the Project ID.");
return;
}
}

// Add the project to the static local list.
localProjectList.Add(CSingleProject(m_AddProject_ID, m_AddProjectName,
m_AddProjectDesc));

// Out we go...
CProjectsSetupDlg::OnOK();
}

void CProjectsAddDlg::OnCancel()
{
// TODO: Add extra cleanup here

CProjectsSetupDlg::OnCancel();
}

/*
*
* THIS IS THE .H FILE
*
*/

/////////////////////////////////////////////////////////////////////////////
// CProjectsAdd dialog

class CProjectsAddDlg : public CProjectsSetupDlg
{
// Construction
public:
CProjectsAddDlg(CWnd* pParent = NULL); // standard constructor

// Dialog Data
//{{AFX_DATA(CProjectsAddDlg)
enum { IDD = IDD_PROJECTS_ADD };
CString m_AddProjectDesc;
CString m_AddProject_ID;
CString m_AddProjectName;
//}}AFX_DATA


// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CProjectsAddDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:

// Generated message map functions
//{{AFX_MSG(CProjectsAddDlg)
virtual void OnOK();
virtual void OnCancel();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};


mfc >> Problem compiling class derived from CDialog

by Jeff Partch [MVP] » Wed, 03 Dec 2003 22:46:45 GMT





////////////////////////////////////////////////////////////////////////////
/

My guess is that the CProjectsSetupDlg doesn't have a ctor that takes 2
parameters. I think the wizard usually generates a dialog class ctor that
takes a CWnd* pParent, and they pass that to the CDialog(UINT nIDTemplate,
CWnd* pParentWnd) ctor along with the class scoped enum IDD. Can you show
your CProjectsSetupDlg ctor(s)?
--
Jeff Partch [VC++ MVP]





mfc >> Problem compiling class derived from CDialog

by Rick Lee » Thu, 04 Dec 2003 04:30:58 GMT

Jeff,

I think you're right. Here's the constructor:
CProjectsSetupDlg::CProjectsSetupDlg(CWnd* pParent /*=NULL*/)
: CDialog(CProjectsSetupDlg::IDD, pParent)
How do I fix it?

Also, the CProjectsAddDlg class does not seem to be in the class browse file, as
the References, Base Class, etc. commands don't work for it only.

Thanks,
Rick



My guess is that the CProjectsSetupDlg doesn't have a ctor that takes 2
parameters. I think the wizard usually generates a dialog class ctor that
takes a CWnd* pParent, and they pass that to the CDialog(UINT nIDTemplate,
CWnd* pParentWnd) ctor along with the class scoped enum IDD. Can you show
your CProjectsSetupDlg ctor(s)?



Similar Threads

1. Deriving from a class derived from a CDialog

Hello,

Hopefully the title wasn't too confusing. I have a problem with the class wizard.
For classes which are derived from CDialog via 2 hops he looses the ability to
generate event handlers. If I add the event handlers by hand things work but the
automatic 'wizard' things in the resource editor no longer work.

1) What I wanted to achive and did

The project (a dialog based app) uses a tabulator control to display various
pages to the user where he can change values, send commands to an external
device and see the results. But certain operations have to be performed always
when a tab is selected or deselcted (configuration/initialization and reseting
of the external device). In the original approach the Tabs where directly derived
from CDialog and the CMyTabCtrl (derived from CTabCtrl) new which methods to call
for starting/stopping a tab.
I tried to make this more C++ like by introducing an additional class CTab dervied
from CDialog which defines two virtual methods TabSelected, TabDeselected and all Tabs are
now derived from that new class. Additionally as CTab is tightly related to
the tab control I made it a public inner class of the CMyTab Ctrl class.

Essential C++ code:

class CMyTabCtrl :: public CTabCtrl
{
public:
   class CTab : public CDialog
   {

   public:
     explicit CTab(LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL)
       : CDialog(lpszTemplateName, pParentWnd)
     {};

       explicit CTab(UINT nIDTemplate, CWnd* pParentWnd = NULL)
         : CDialog(nIDTemplate, pParentWnd)
     {};

     CTab() : CDialog()
     {};

     virtual void TabSelected()
     {}
     virtual void TabDeselected()
     {}
   };

   // other methods to add and setup the needed tabs
}

// Tabs are now implemented via
class CSomeTab :: public CMyTabCtrl::CTab


2) What happened

Somehow the class wizard lost any ability to generate event handlers for all the
classes derived from CMyTabCtrl::CTab.

I suspect it has something to do with all the DECLARE_DYNAMIC and DECLARE_MESSAGE_MAP
macros but I do not have enough insight to point to the problem.

I tried to use DECLARE_DYNAMIC and IMPLEMENT_DYNAMIC but it seems that those macros
choke on inner classes.
Because

   IMPLEMENT_DYNAMIC(CMyTabCtrl::CTab, CDialog);  // and the needed DECLARE_DYNAMIC in the header file

leads to error messages from the compiler regarding the '::'.

Best regards,

Oliver

2. enbed a CDialog class into a CWnd-derived window

3. An simple class derived from CDialog

Hi,

I would like to create a class that derived from CDialog. This class
should only paint RED the background of it dialog. Thereafter I will
derivate all my following dialog from this one. So the code to pain
the dialog will not be redundant.

By the way, what should I put in the CPP and .H of the derivates class
for the relation works well (Message map, inheritage,
BEGIN_MESSAGE_MAP, DoDataExchange,  etc..)?

DialogBaseRedBackground.h

classe CDialogBaseRedBackground : public CDialog
{
};

DialogBaseRedBackground.cpp

{
};

MyDialog.h

classe CDialogRedBackground : public CDialogBaseRedBackground
{
};

MyDialog.cpp

{
};

Thank
Best regards,

4. Creating a CDialog derived class for a Dialog??

5. Linking Dialogs to Existing CDialog Derived Classes

Hi,

I'm trying to create an MFC application from 'scratch'.
I created an empty Windows application, linked to MFC shared libraries,
and derived classes from CWinApp and CDialog. I created the dialog in
Studio, and it compiled, ran and showed that dialog fine.
Problem is, Studio doesn't recognize that the dialog is connected to my
class, so I can't do all the neat thing like double clicking on a button
to set the event handler without seeing the MFC Class Wizard screen.
I can't use the MFC Class Wizard, because the class already exists!
(Plus, it doesn't seem to work anyways, unless you started using the MFC
Application Wizard, another question, but for later).

How do I link the dialog to the class?


Thanks for your help,

Michael

6. CDialog from CWinThread derived class hangs on ShowWindow(SH_HIDE) on shutdown

7. Attach() 'ing a CEdit derived class on a CDialog

I have a dialog with a custom CEdit derived control on it.  Let's call in 
CMyEdit.  Using Class Wizard, I have mapped the control's ID to CMyEdit. 
When doing this, MFC actually creates the control before CMyEdit knows about 
it.  i.e OnCreate() will never get called.  I think MFC is using Attach() to 
do this.  That's fine.  I just need a way to know when it's attached so I 
can set the window's text.  There isn't an OnAttach().. like I want.  What 
can I do?

Thanks! 


8. CDialog derived class