I suggest you initialize the member variables in the oninitdialog () function, and try not to initialize them in the constructor.
For example, create a dialog box application and generate a "ccalculatordlg" class, which inherits from the "cdialog" class.
This issue is explained based on the "ccalculatordlg" class:
The ccalculatordlg class defines two member variables: Double m_data and cedit * m_pedit.
1. Both variables can be initialized in the ccalculatordlg () constructor or oninitdialog () function as follows:
M_data = 0;
M_pedit = NULL;
2. You can perform the following initialization in the oninitdialog () function:
M_data = 0;
M_pedit = (cedit *) This-> getdlgitem (idc_edit); // idc_edit is the cedit Control ID in the dialog box.
3. perform the following initialization in the ccalculatordlg () constructor:
M_pedit = (cedit *) This-> getdlgitem (idc_edit); // idc_edit is the cedit Control ID in the dialog box.
An error is reported when the "Debug solution" is generated, but no error is reported when the "Release solution" is generated.
Error reported when "Debug solution" is generated:
Debug assertion failed!
Program :...
File:... \ winocc. cpp
Line: 92
Open winocc. cpp and jump to line 1
Cwnd * cwnd: getdlgitem (int nid) const <br/>{< br/> assert (: iswindow (m_hwnd )); // The value is 92nd rows. </P> <p> If (m_pctrlcont = NULL) <br/> return cwnd: fromhandle (: getdlgitem (m_hwnd, NID )); <br/> else <br/> return m_pctrlcont-> getdlgitem (NID); <br/>}
This statement asserted whether m_hwnd is a form handle. It only executes this statement when "Debug solution" is generated, and skips this macro when "Release solution" is generated.
As to why it reports an error, I understand it as follows: In the generate ccalculatordlg dialog box and call ccalculatordlg () m_hwnd in the base class cwnd of the constructor is too late for initialization (I .e. m_hwnd = NULL). Therefore, an error will occur when you execute the 92nd row assertions, therefore, it is best to put the initialization of this class in oninitdialog.