File: f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\winocc.cpp的子窗口初始化问题
m_dlg1::m_dlg1(CWnd* pParent /*=NULL*/) : CDialog(m_dlg1::IDD, pParent) { CEdit* pOneBox = (CEdit*)this->GetParent()->GetDlgItem(IDC_EDIT1); CString str; pOneBox->GetWindowText(str); SetDlgItemText(IDC_STATIC2,str); } m_dlg1是子窗口的类,上面是子窗口的初始化函数,我希望在窗口初始化的时候改变子窗口里一个 static text控件的数据,但是这样是不行的,在子窗口的构建函数中编辑框还未初始化,必须在重载OnInitDialog()函数在那个函数中添加功能
正确做法:
先添加函数
添加函数,记得类型要是BOOL,不能用bool。
然后再子窗口cpp文件添加代码
BOOL m_dlg1::OnInitDialog() { CDialog::OnInitDialog(); CEdit* pOneBox = (CEdit*)this->GetParent()->GetDlgItem(IDC_EDIT1); CString str; pOneBox->GetWindowText(str); SetDlgItemText(IDC_STATIC2,str); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
ok搞定