Windows sends the WM_INITDIALOG message to the dialog box during the Create, CreateIndirect, or DoModal calls, which occur immediately before the dialog box is displayed.
Override this method if you want to perform special processing when the dialog box is initialized. In the overridden version, first call the base class OnInitDialog but ignore its return value. You will typically return TRUE from your overridden method.
Windows calls the OnInitDialog function by using the standard global dialog-box procedure common to all Microsoft Foundation Class Library dialog boxes. It does not call this function through your message map, and therefore you do not need a message map entry for this method.
Note:
You cannot override this method when you use a CFileDialog object in a program that is compiled under Windows Vista. For more information about changes to CFileDialog under Windows Vista see CFileDialog Class.
在创建对话框(创建对话框的方法有:Create(),CreateIndirect(),DoModal())时,Windows发送WM_INITDIALOG消息到该被创建的对话框,这就立即激发该对话框的OnInitDialog()函数,即,在显示该对话框前使用OnInitDialog()函数初始化该对话框的数据及内容,以及可以使用该函数在显示对话框前布置控件的显示大小及位置。
重写此方法的目的是如果你要执行特殊的处理时(比如就象上面说的要初始化数据或者控件等)。在重写的函数中,首先调用基类的OnInitDialog()函数,但需要忽视它的返回值。添加好你的功能后,直接返回TRUE。
Windows调用通过使用标准的全局对话框程序共同所有的Microsoft基础类库对话框的OnInitDialog()函数。它不调用通过你的消息映射代码功能,因此您不需要为此方法在代码中添加MFC消息映射项。
注意:
当您是在Windows Vista下编译的程序一个CFileDialog对象时,您不能重写此方法。如需在Windows Vista下修改的CFileDialog CFileDialog类信息,请参阅最新的MSDN中关于Vista的CFileDialog类。