2012年4月11日 星期三

OnInitDialog 請將初始化設定在這裡

This message is sent to the dialog box during the Create, CreateIndirect, or DoModal calls, which occur immediately before the dialog box is displayed.
from MSDN

其實不用從上面的說明,從function的名稱也可以猜到dialog初始化時會先執行function所定義的項目.
在vc2003之前,你可以從Class wizard->message->WM_INITDIALOG.
在vc2003之後,請在Class wizard->Override->OnInitDialog

其實也挺合理的,這本來就是一個virtual function,在我還不知道class wizard可以添加之前,也都是直接手動定義的,這邊也分享一下原始碼,如果還是找不到添加的位置就手動key吧!!正所謂DIY會更有感覺 XD.

(In head file *.h)
class Dlg : public CDialog
{
.....
protected:
virtual BOOL OnInitDialog();
.....
}

(In source code *.cpp)
BOOL Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
      //TODO:在此添加額外的初始化設定


return TRUE;
}

沒有留言:

張貼留言