oncreate,oninitialupdate,oninitdialog |
时间上,oncreate,oninitial两者先后顺序不同,构造函数生成本类的对象,但没有产生窗口,OnCreate后窗口产生, 然后才是视图的OnInitialUpDate,一般在这里对视图的显示做初始化。简单点,就是ONCREATE只是产生VIEW的基本结构和变量而在OnInitialUpDate()中,主要初始化视图中控件等。对各个变量进行初始化操作。例子。我们要在视图中添加一个button和combobox控件则OnCreate函数中写法如下:int CFormView::OnCreate(LPCREATESTRUCT lpCreateStruct) {if (CView::OnCreate(lpCreateStruct) == -1) return -1;// TODO: Add your specialized creation code hereCRect rect(20,20,100,50);m_ctrlButton.Create("Button1",WS_CHILD|WS_VISIBLE,rect,this,NULL);
//创建按扭控件CFont *pFont=CFont::FromHandle((HFONT)::GetStockObject(ANSI_VAR_FONT));CRect rect1(150,20,350,100);m_combobox.Create(WS_CHILD|WS_VISIBLE|CBS_SIMPLE|CBS_NOINTEGRALHEIGHT|WS_VSCROLL,rect1,this,NULL);
return 0;}OnInitialUpDate中写法void CFormView::OnInitialUpdate() {CView::OnInitialUpdate();// TODO: Add your specialized code here and/or call the base class//初始化组合框控件m_combobox.AddString("Mondy");m_combobox.AddString("Tuesday");m_combobox.AddString("Wednesday");m_combobox.AddString("Thursday");m_combobox.AddString("Saturday");m_combobox.AddString("Sunday");
}
另外CVIEW::OnInitialUpdate()和CDLG::OnInitDialog()出现时间都差不多,前者指的是在view马上显示之前由框架去调用的,后者是before the dialog box display ;所以OnInitDialog()也在Create()和CreateIndirect()或domodal()之后. | |
|
|