int DialogBoxIndirect(hinst, hglbDlgTemp, hwndOwner, dlgprc) | |||||
HINSTANCE hinst; | /* handle of application instance | */ | |||
HGLOBAL hglbDlgTemp; | /* handle of memory with dialog box template | */ | |||
HWND hwndOwner; | /* handle of owner window | */ | |||
DLGPROC dlgprc; | /* instance address of dialog box procedure | */ |
The DialogBoxIndirect function creates a modal dialog box from a dialog box template in memory.
hinst
Identifies the instance of the module that will create the dialog box.
hglbDlgTemp
Identifies the global memory object that contains a dialog box template used to create the dialog box. This template is in the form of a DialogBoxHeader structure. For more information about this structure, see Chapter 7, “Resource Formats Within Executable Files,” in the Microsoft Windows Programmer's Reference, Volume 4.
hwndOwner
Identifies the window that owns the dialog box.
dlgprc
Specifies the procedure-instance address of the dialog box procedure. The address must be created by using the MakeProcInstance function. For more information about the dialog box procedure, see the description of the DialogProc callback function.
The return value is the value of the nResult parameter specified in the EndDialog function that is used to terminate the dialog box. The system processes values returned by the dialog box procedure and does not return them to the application. The return value is –1 if the function cannot create the dialog box.
The CreateWindowEx function is called to create the dialog box. The dialog box procedure then receives a WM_SETFONT message (if DS_SETFONT style was specified) and a WM_INITDIALOG message, and then the dialog box is displayed.
The DialogBoxIndirect function does not return control until the dialog box procedure terminates the modal dialog box by calling the EndDialog function.
A dialog box can contain up to 255 controls.
The following example uses the DialogBoxIndirect function to create a dialog box from a dialog box template in memory:
#define TEMPLATE_SIZE 100
HGLOBAL hglbDlgTemp;
DLGPROC dlgprc;
int result;
HWND hwndParent;
/* Allocate a global memory object for the dialog box template. */
hglbDlgTemp = GlobalAlloc(GHND, TEMPLATE_SIZE);
.
. /* Build a DLGTEMPLATE structure in the memory object. */
.
dlgprc = (DLGPROC) MakeProcInstance(DialogProc, hinst);
result = DialogBoxIndirect(hinst, hglbDlgTemp, hwndParent, dlgprc);
DialogBox, DialogBoxIndirectParam, DialogBoxParam, DialogProc, EndDialog, MakeProcInstance