Specifies whether the application has set the input focus to one of the controls in the dialog box. If OnInitDialog returns nonzero, Windows sets the input focus to the first control in the dialog box. The application can return 0 only if it has explicitly set the input focus to one of the controls in the dialog box.
This member function is called in response to the WM_INITDIALOG message. This message is sent to the dialog box during the Create, CreateIndirect, or DoModal calls, which occur immediately before the dialog box is displayed.
Override this member function if you need to perform special processing when the dialog box is initialized. In the overridden version, first call the base class OnInitDialog but disregard its return value. You will normally return TRUE from your overridden member function.
Windows calls the OnInitDialog function via the standard global dialog-box procedure common to all Microsoft Foundation Class Library dialog boxes, rather than through your message map, so you do not need a message-map entry for this member function.
CDialog Overview | Class Members | Hierarchy Chart
See Also CDialog::Create, CDialog::CreateIndirect,WM_INITDIALOG
The WM_INITDIALOG message is sent to the dialog box procedure immediately before a dialog box is displayed. Dialog box procedures typically use this message to initialize controls and carry out any other initialization tasks that affect the appearance of the dialog box.
hwndFocus = (HWND) wParam; // handle of control to receive focus
lInitParam = lParam; // initialization parameter
Value of wParam. Identifies the control to receive the default keyboard focus. The system assigns the default keyboard focus only if the dialog box procedure returns TRUE.
Value of lParam. Specifies additional initialization data. This data is passed to the system as the lParamInit parameter in a call to the CreateDialogIndirectParam, CreateDialogParam, DialogBoxIndirectParam, or DialogBoxParam function used to create the dialog box. For property sheets, this parameter is a pointer to thePROPSHEETPAGE structure used to create the page. This parameter is zero if any other dialog box creation function is used.
The dialog box procedure should return TRUE to direct the system to set the keyboard focus to the control given by hwndFocus. Otherwise, it should return FALSE to prevent the system from setting the default keyboard focus.
The dialog box procedure should return the value directly. The DWL_MSGRESULT value set by the SetWindowLong function is ignored.
The control to receive the default keyboard focus is always the first control in the dialog box that is visible, not disabled, and that has the WS_TABSTOP style. When the dialog box procedure returns TRUE, the system checks the control to ensure that the procedure has not disabled it. If it has been disabled, the system sets the keyboard focus to the next control that is visible, not disabled, and has the WS_TABSTOP.
An application can return FALSE only if it has set the keyboard focus to one of the controls of the dialog box.
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in winuser.h.
Dialog Boxes Overview, Dialog Box Messages, CreateDialogIndirectParam, CreateDialogParam, DialogBoxIndirectParam, DialogBoxParam,PROPSHEETPAGE, SetFocus