我有两节课。
DialogBase类是从CDialog继承的
DialogDerived类是从DialogBase继承的。
BOOL DialodDervied::OnInitDialog()
{
CDialogBase::OnInitDialog();
//Add Dynamic Control to Main Dialog from here
}
我想在通过派生类调用对话框(CDialogBase)时动态添加一个复选框。可能吗?如果是,怎么办?
最佳答案
声明成员变量CButton m_ctrl_chk
,重写DialodDervied :: OnCreate()并添加类似的代码
int DialodDervied::OnCreate(LPCREATESTRUCT lpCreateStruct)
{ if (CDialogEx::OnCreate(lpCreateStruct) == -1)
return -1;
m_ctrl_chk.Create(_T("Checkmate"), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX,
CRect(5, 5, 100, 20), this, 1234); // the 1234 value is the ID of the control
return 0;
}
使用类似的类(
CEdit
,CStatic
,CButton
,...)以相同的方式创建其他类型的控件。