Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear,
I'm creating a class derived from CDialog, suppose that class name it is 'CBase'.
I want it acting as CDialog of MFC and any class derived from base create one dialog box. What can I do for it?
I tried out as fallows

C++
CBase : public Cdialog
{
    CBase(CWnd* pParent = NULL);   // standard constructor

    //{{AFX_DATA(CTestDlgBase)
    enum { IDD = _UNKNOWN_RESOURCE_ID_ };

    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV protected:

    DECLARE_MESSAGE_MAP()

}
Cderive : public CBase
{
Cderive(CWnd* pParent = NULL);   
   //{{AFX_DATA(CTestDlgBase)
   enum { IDD = _UNKNOWN_RESOURCE_ID_ };

   protected:
   virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV protected:

   DECLARE_MESSAGE_MAP()

}


but I got error as fallows
error C2065: '_UNKNOWN_RESOURCE_ID_' : undeclared identifier
error C2057: expected constant expression

also when I create object of class CBase & calling DoModal the dialog isn't shown.
What can I do for it?
Posted
Updated 5-Sep-10 22:33pm
v3
Comments
Sandeep Mewara 6-Sep-10 2:35am    
Use PRE tags to format your code part - it makes the question readable.

you must delete the code of "enum { IDD = _UNKNOWN_RESOURCE_ID_ };"
and change the constructor like "CBase(UINT nIDD ,CWnd* pParent = NULL); // standard constructor"
the dialog id put in by youself !
 
Share this answer
 
As an enhancement to Glen's response, the intermediate class CBase has no knowledge of the dialog id used. It's not until you create a dialog instance you do know. Hence, the id must be an argument/variable in CBase.
Depending on how you implement your Cderive class, it can use the enum construct or it too has to use an argument/variable for the id.
 
Share this answer
 
if _UNKNOWN_RESOURCE_ID_ is the dialog resource then .
just #include resource.h in your file.
 
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