How can I inherit the MFC dialog box?

I created a dialog box (cMyDialog). I plan to duplicate cMyDialog and call it cMyDialog2. How can I inherit in MFC? I want cMyDialog2 to inherit all IDDs from cMyDialog1, so I don't need to copy and paste the code from cMyDialog1 to cMyDialog2. The purpose of cMyDialog2 is to inherit all the functions from cMyDialog1 and add some additional functions to it.


Thank you very much for your response. I'm not quite sure about IMPLEMENT_DYNAMIC. Below is a short snippet of my code. Can you look at it and help me if I misunderstood the macro?

// cMyDialog1.cpp : implementation file

cMyDialog1::cMyDialog1(void * pMsgData, CWnd* pParent /*=NULL*/): CDialog(cMyDialog1::IDD, pParent)

{ //codes....
}

BOOL cMyDialog1::OnInitDialog() 

{
    CDialog::OnInitDialog();
...
}


//cMyDialog2.cpp

cMyDialog2::cMyDialog2(void * pMsgData, CWnd* pParent /*=NULL*/)
    : CMyDialog1(cMyDialog2::IDD, pParent)

{ //codes....
   IMPLEMENT_DYNAMIC(cMyDialog2, cMyDialog1)
}

I can inherit from CMyDialog using DECLARE_DYNAMICand methods IMPLEMENT_DYNAMIC. Thanks so much for your help, Adam.

. CMyDialog1, , " ", . , CMyDialog1 CMyDialog , , ? ?

+3
2

, , CDialog. , DECLARE_DYNAMIC , MFC. . :

.h:

class cMyDialog2
  : public cMyDialog
{
  DECLARE_DYNAMIC(cMyDialog2)

pulic:
  cMyDialog2();
  virtual ~cMyDialog2();

protected:
  DECLARE_MESSAGE_MAP()
};

.cpp:

#include "cMyDialog2.h"

IMPLEMENT_DYNAMIC(cMyDialog2, cMyDialog)

BEGIN_MESSAGE_MAP(cMyDialog2, cMyDialog)
END_MESSAGE_MAP()

cMyDialog2::cMyDialog2()
{
}

...etc.
+6

. DoDataExchange() . (cMyDialog2) , (), , :

void cMyDialog2::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    cMyDialog::DoDataExchange(pDX);
}

, , / .

0

Source: https://habr.com/ru/post/1703393/


All Articles