MFC:一个CFormView派生类的OnInitialUpdate函数 [英] MFC: OnInitialUpdate function of a CFormView-derived class

查看:557
本文介绍了MFC:一个CFormView派生类的OnInitialUpdate函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的CFormView派生类的结构如下:

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

理想情况下,我想在构造函数的主体中调用Initialize

  FormViewClass :: FormViewClass()
{
...
//原本I想调用Initialize函数这里
Initialize();
...
}

但是,由于我想要此函数负责在创建这个类的所有初始化,它包含MFC对象初始化,如组合框,编辑控制,复选框控制,单选按钮控制等,我应该改为调用Initialize()函数在这里,我想:

  void FormViewClass :: OnInitialUpdate()
{
//我应该调用Initialize函数吗?
Initialize();
}

目前我在构造函数中有非MFC内存和对象初始化在构造函数中的Iniitalize()辅助函数)和OnIniitalUpdate()处理函数中的MFC对象初始化。听到你的想法是很好,所以我可以重构代码正确。提前感谢。

解决方案

我认为你是做对的。

一般来说,我会尝试尽早初始化(但是没有更早的8-),所以在构造函数中做非GUI东西,而在 c> c> $

> CFormView ,这可能比 OnInitialUpdate 更好,但我不认为它是。)


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.

解决方案

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.)

这篇关于MFC:一个CFormView派生类的OnInitialUpdate函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆