stanigator
stanigator

Reputation: 10944

MFC: OnInitialUpdate function of a CFormView-derived class

My CFormView-derived class is structured as follows:

class FormViewClass : public CFormView
{
        ...
        FormViewClass();
        void Initialize();
        virtual void OnInitialUpdate();
        ...
};

Ideally, I would like to call the Initialize() function in the body of the constructor as follows:

FormViewClass::FormViewClass()
{
        ...
        // originally I want to call Initialize function here
        Initialize();
        ...
}

However, since I want this function to be responsible for all the initialization of this class when being created, and it contains MFC objects initializations such as combobox, edit control, checkbox control, radio button control, etc., should I be instead calling the Initialize() function here as I thought:

void FormViewClass::OnInitialUpdate()
{
    // Should I call Initialize function instead here?
    Initialize();
}

Currently I have non-MFC memory and object initialization in the constructor (hence calling Iniitalize() helper function in the constructor) and MFC object iniitalization in the OnIniitalUpdate() handler function. It would be great to hear your thoughts about it so that I can refactor the code properly. Thanks in advance.

Upvotes: 3

Views: 3649

Answers (1)

RichieHindle
RichieHindle

Reputation: 281505

I think you're right to do it the way you're doing it.

In general, I would try to initialise things as early as possible (but no earlier 8-) so doing non-GUI stuff in the constructor, and GUI stuff in OnInitialUpdate makes sense.

(If OnInitDialog existed for CFormView, that would probably be a better place than OnInitialUpdate, but I don't think it does.)

Upvotes: 6

Related Questions