HWND CreateDialog(hInstance,lpTemplateName,hWndParent,lpDialogFunc)
This function creates a modeless dialog box that has the size, style, and controls defined by the dialog-box template given by the lpTemplateName parameter. The hWndParent parameter identifies the application window that owns the dialog box. The dialog function pointed to by the lpDialogFunc parameter processes any messages received by the dialog box.
The CreateDialog function sends a WM_INITDIALOG message to the dialog function before displaying the dialog box. This message allows the dialog function to initialize the dialog-box controls.
CreateDialog returns immediately after creating the dialog box. It does not wait for the dialog box to begin processing input.
Parameter | Type/Description | |
hInstance | HANDLE Identifies an instance of the module whose executable file contains the dialog-box template. | |
lpTemplateName | LPSTR Points to a character string that names the dialog-box template. The string must be a null-terminated character string. | |
hWndParent | HWND Identifies the window that owns the dialog box. | |
lpDialogFunc | FARPROC Is the procedure-instance address for the dialog function. See the following “Comments” section for details. |
The return value is the window handle of the dialog box. It is NULL if the function cannot create the dialog box.
Use the WS_VISIBLE style for the dialog-box template if the dialog box should appear in the parent window upon creation.
Use the DestroyWindow function to destroy a dialog box created by the CreateDialog function.
A dialog box can contain up to 255 controls.
The callback function must use the Pascal calling convention and must be declared FAR.
BOOL FAR PASCAL DialogFunc(hDlg,wMsg,wParam,lParam)
HWNDhDlg;
WORDwMsg;
WORDwParam;
DWORDlParam;
DialogFunc is a placeholder for the application-supplied function name. The actual name must be exported by including it in an EXPORTS statement in the application's module-definition file.
Parameter | Definition | |
hDlg | Identifies the dialog box that receives the message. | |
wMsg | Specifies the message number. | |
wParam | Specifies 16 bits of additional message-dependent information. | |
lParam | Specifies 32 bits of additional message-dependent information. |
Return Value
Except in response to the WM_INITDIALOG message, the dialog function should return nonzero if the function processes the message, and zero if it does not. In response to a WM_INITDIALOG message, the dialog function should return zero if it calls the SetFocus function to set the focus to one of the controls in the dialog box. Otherwise, it should return nonzero, in which case Windows will set the focus to the first control in the dialog box that can be given the focus.
Comments
The dialog function is used only if the dialog class is used for the dialog box. This is the default class and is used if no explicit class is given in the dialog-box template. Although the dialog function is similar to a window function, it must not call the DefWindowProc function to process unwanted messages. Unwanted messages are processed internally by the dialog-class window function.
The dialog-function address, passed as the lpDialogFunc parameter, must be created by using the MakeProcInstance function.