What is the correct way to subclass MFC management?

We host dialog boxes using the resource editor. So to speak, I have a RichEditCtrl called IDC_RICH. And I want to associate it with an instance of a custom class CMyRichEditCtrl : CRichEditCtrlwithout losing the ability to set properties in it in the resource editor.

Which is the right way? You can, of course, get some functionality by creating a DDX-related variable and changing the type to CMyRichEditCtrl. But in some cases, I see people calling code like:

m_Rich.SubclassDlgItem(IDC_RICH, this));

Who cares?

EDIT: One of the problems I see is that when I override the Create (Ex) methods, they are not called. Does it look like the control has already been created by the time my object is bound to the resource identifier, pehaps?

+4
source share
3 answers

The windows that you enter into the dialog with the resource editor are created using CreateWindow (Ex) with the first argument set to the class name specified in the .rc file. The DDX_ mechanism then associates this instance window with a member of the dialog class in DoDataExchange ().

MFC - Win32, MFC Win32. , MFC - . MFC , , " " (.. MFC), . Create() - , , , MFC . ( , , ).

+4

DDX_Control() SubclassWindow() . SubclassDlgItem - SubclassWindow (GetDlgITem()). ( ) , SubclassWindow, , , DDX_Control ( 1995 ?) MFC-, , .

, DDX_Control() , , SubclassDlgItem().

+7

1 > , , DDX_Control:

class CMyDlg : public CDialogEx
{

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

public:
    CRichEditCtrl m_Rich;
};

void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_RICHEDIT1, m_Rich);
}

2 > , :

CRichEditCtrl m_Rich; m_Rich.Create(...); m_Rich.SubclassDlgItem(IDC_RICH, this));

0
source

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


All Articles