对话框的初始化问题
CSockDlg::CSockDlg(CWnd* pParent /*=NULL*/) // 数据成员初始化: CDialog(CSockDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSockDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
/////////////////////////////////////////////////////////////////////////////
// CSockDlg message handlers
BOOL CSockDlg::OnInitDialog() // 显示状态初始化
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
今天认真看了 VC 向导自动产生的一个 MFC工程,突然发现其对对话框的初始化使用了两个函数
如上,分别是对数据成员和显示状态初始化,不知道微软工程师们怎么考虑这种软件架构模式,为什么要把初始化还分得这么的清晰呢?另外想知道这两个初始化函数的调用顺序?