CreateDialogIndirectParam function (Windows)

Switch View :
ScriptFree
CreateDialogIndirectParam function

Applies to: desktop apps only

Creates a modeless dialog box from a dialog box template in memory. Before displaying the dialog box, the function passes an application-defined value to the dialog box procedure as the lParam parameter of the WM_INITDIALOG message. An application can use this value to initialize dialog box controls.

Syntax

HWND WINAPI CreateDialogIndirectParam(
  __in_opt  HINSTANCE hInstance,
  __in      LPCDLGTEMPLATE lpTemplate,
  __in_opt  HWND hWndParent,
  __in_opt  DLGPROC lpDialogFunc,
  __in      LPARAM lParamInit
);

Parameters

hInstance [in, optional]

Type: HINSTANCE

A handle to the module that will create the dialog box.

lpTemplate [in]

Type: LPCDLGTEMPLATE

The template CreateDialogIndirectParam uses to create the dialog box. A dialog box template consists of a header that describes the dialog box, followed by one or more additional blocks of data that describe each of the controls in the dialog box. The template can use either the standard format or the extended format.

In a standard template, the header is a DLGTEMPLATE structure followed by additional variable-length arrays. The data for each control consists of a DLGITEMTEMPLATE structure followed by additional variable-length arrays.

In an extended dialog box template, the header uses the DLGTEMPLATEEX format and the control definitions use the DLGITEMTEMPLATEEX format.

After CreateDialogIndirectParam returns, you can free the template, which is only used to get the dialog box started.

hWndParent [in, optional]

Type: HWND

A handle to the window that owns the dialog box.

lpDialogFunc [in, optional]

Type: DLGPROC

A pointer to the dialog box procedure. For more information about the dialog box procedure, see DialogProc.

lParamInit [in]

Type: LPARAM

The value to pass to the dialog box in the lParam parameter of the WM_INITDIALOG message.

Return value

Type: HWND

If the function succeeds, the return value is the window handle to the dialog box.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

The CreateDialogIndirectParam function uses the CreateWindowEx function to create the dialog box. CreateDialogIndirectParam then sends a WM_INITDIALOG message to the dialog box procedure. If the template specifies the DS_SETFONT or DS_SHELLFONT style, the function also sends a WM_SETFONT message to the dialog box procedure. The function displays the dialog box if the template specifies the WS_VISIBLE style. Finally, CreateDialogIndirectParam returns the window handle to the dialog box.

After CreateDialogIndirectParam returns, you can use the ShowWindow function to display the dialog box (if it is not already visible). To destroy the dialog box, use the DestroyWindow function. To support keyboard navigation and other dialog box functionality, the message loop for the dialog box must call the IsDialogMessage function.

In a standard dialog box template, the DLGTEMPLATE structure and each of the DLGITEMTEMPLATE structures must be aligned on DWORD boundaries. The creation data array that follows a DLGITEMTEMPLATE structure must also be aligned on a DWORD boundary. All of the other variable-length arrays in the template must be aligned on WORD boundaries.

In an extended dialog box template, the DLGTEMPLATEEX header and each of the DLGITEMTEMPLATEEX control definitions must be aligned on DWORD boundaries. The creation data array, if any, that follows a DLGITEMTEMPLATEEX structure must also be aligned on a DWORD boundary. All of the other variable-length arrays in the template must be aligned on WORD boundaries.

All character strings in the dialog box template, such as titles for the dialog box and buttons, must be Unicode strings.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

Unicode and ANSI names

CreateDialogIndirectParamW (Unicode) and CreateDialogIndirectParamA (ANSI)

See also

Reference
CreateDialog
CreateDialogIndirect
CreateDialogParam
CreateWindowEx
DestroyWindow
DialogProc
DLGITEMTEMPLATE
DLGITEMTEMPLATEEX
DLGTEMPLATE
DLGTEMPLATEEX
ShowWindow
WM_INITDIALOG
WM_SETFONT
Conceptual
Dialog Boxes
Other Resources
MultiByteToWideChar

 

 

Send comments about this topic to Microsoft

Build date: 2/10/2012

Community Content

Pinkybum
Wrong function
Sorry the actual function is: DialogBoxIndirectParamA - same issues apply.

Pinkybum
Crashing ATL dll
I have a ATL COM dll that has been working for the past 12 years on Windows 2000 and XP. However, On Windows 7 the Modal dialog causes the application to crash. I believe the errant code is contained within the above function as the AtlAxDialogBoxA function calls this eventually.

Henrik Haftmann
More remarks
All CreateWindowEx() calls are with lpParam==0. Therefore, it is not possible to create a dialog-style window as a true MDI child (see documentation on CreateWindowEx()). Parsing the DLGTEMPLATE/DLGTEMPLATEEX structure by self-made code will solve this problem seamlessly but it's much efford. It's internal workflow is roughly:
CREATESTRUCT cs;
HFONT f = fill_cs_with_dlgtemplate(&lpTemplate, &cs);  // loads menu, may call WideCharToMultiByte(), and MapDialogRect()
HWND w = CreateWindowEx(cs.dwExStyle, cs.lpszClass, cs.lpszName, cs.style, cs.x, cs.y, cs.cx, cs.cy, hWndParent, cs.hMenu, hInstance, 0);
if (f) SendMessage(w, WM_SETFONT, (WPARAM)f, 0);
while (fill_cs_with_dlgitemtemplate(&lpTemplate, &cs))  // cs.hMenu is now the control ID
  CreateWindowEx(cs.dwExStyle, cs.lpszClass, cs.lpszName, cs.style, cs.x, cs.y, cs.cx, cs.cy, w, cs.hMenu, hInstance, 0); return w;
The workhorse functions are named fill_cs_with_dlgtemplate() and fill_cs_with_dlgitemtemplate() here. These are quite complex. The former function detects whether it's DLGTEMPLATE or DLGTEMPLATEEX and can record this in one of the unused fields of cs, and the latter function can then use this info to branch in either decoding DLGITEMTEMPLATE or DLGITEMTEMPLATEEX.