DIALOGEX Resource Template Differences from DIALOG Template

Last reviewed: December 14, 1995
Article ID: Q141201
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK) for:

        - Microsoft Windows NT version 3.51
        - Microsoft Windows 95
    

SUMMARY

When you create or modify a dialog template in memory, it is necessary to know the form of the DLGTEMPLATE and DLGITEMTEMPLATE structures. While these structures are well documented for DIALOG resources, they take a different form for DIALOGEX resources, and are not well documented in the SDK.

MORE INFORMATION

The extended DLGTEMPLATE structure, call it DLGTEMPLATEEX, has this form:

typedef struct tagDLGTEMPLATEEX{

    WORD wDlgVer;           // use 1
    WORD wSignature;        // use 0xFFFF
    DWORD dwHelpID;         // Dialog's context help ID
    DWORD dwExStyle;        // Extended style
    DWORD dwStyle;          // Style
    WORD cDlgItems;         // Number of controls in dialog
    short x;                // Initial position, horizontal
    short y;                // Initial position, vertical
    short cx;               // Width
    short cy;               // Height
} DLGTEMPLATEEX;

This is followed by menu name, class name, title, and font info if style includes DS_SETFONT, which have the same form as documented in the SDK for DLGTEMPLATE.

The extended DLGITEMTEMPLATE structure, call it DLGITEMTEMPLATEEX, has this form:

typedef struct tagDLGITEMTEMPLATEEX{

    DWORD dwHelpID;         // Context help ID for control
    DWORD dwExStyle;        // Control extended styles
    DWORD dwStyle;          // Style
    short x;                // Initial position, horizontal
    short y;                // Initial position, vertical
    short cx;               // Width
    short cy;               // Height
    DWORD dwID;             // Window ID
} DLGITEMTEMPLATEEX;

This is followed by class name, title, and creation data for the control, which have the same form as documented in the SDK for DLGITEMTEMPLATE.

Code Sample

The following code creates a DIALOGEX resource in memory with a button and a custom control to which it passes creation data:

/* allocate some memory */
pdlgtemplate = p = (PWORD) LocalAlloc (LPTR, 1000);

/* start to fill in the dlgtemplate information, addressing by WORDs */
lStyle = DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU| DS_SETFONT;
*p++ = 1;          // DlgVer
*p++ = 0xFFFF;     // Signature
*p++ = 0;          // LOWORD HelpID
*p++ = 0;          // HIWORD HelpID
*p++ = 0;          // LOWORD (lExtendedStyle)
*p++ = 0;          // HIWORD (lExtendedStyle)
*p++ = LOWORD (lStyle); *p++ = HIWORD (lStyle);
*p++ = 2;          // NumberOfItems
*p++ = 210;        // x
*p++ = 10;         // y
*p++ = 100;        // cx
*p++ = 100;        // cy
*p++ = 0;          // Menu
*p++ = 0;          // Class

/* copy the title of the dialog */
nchar = nCopyAnsiToWideChar (p, TEXT("Dialog")); p += nchar;

/* Font information because of DS_SETFONT */
*p++ = 18;     // point size
nchar = nCopyAnsiToWideChar (p, TEXT("Times New Roman")); // Face name p += nchar;

/* make sure the first item starts on a DWORD boundary */
p = lpwAlign (p);

/* now start with the first item */
lStyle = BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | WS_TABSTOP;
*p++ = 0;          // LOWORD (lHelpID)
*p++ = 0;          // HIWORD (lHelpID)
*p++ = 0;          // LOWORD (lExtendedStyle)
*p++ = 0;          // HIWORD (lExtendedStyle)
*p++ = LOWORD (lStyle); *p++ = HIWORD (lStyle);
*p++ = 10;         // x
*p++ = 60;         // y
*p++ = 80;         // cx
*p++ = 20;         // cy
*p++ = IDOK;       // LOWORD (Control ID)
*p++ = 0;      // HOWORD (Control ID)

/* fill in class i.d., this time by name */
char = nCopyAnsiToWideChar (p, TEXT("BUTTON"));
p += nchar;

/* copy the text of the first item */
nchar = nCopyAnsiToWideChar (p, TEXT("OK")); p += nchar;

*p++ = 0; // advance pointer over nExtraStuff WORD

/* make sure the second item starts on a DWORD boundary */
p = lpwAlign (p);

lStyle = WS_VISIBLE | WS_CHILD;

*p++ = 0;             // LOWORD (lHelpID)
*p++ = 0;             // HIWORD (lHelpID)
*p++ = 0;             // LOWORD (lExtendedStyle)
*p++ = 0;             // HIWORD (lExtendedStyle)
*p++ = LOWORD (lStyle); *p++ = HIWORD (lStyle);
*p++ = 20;            // x
*p++ = 5;             // y
*p++ = 65;            // cx
*p++ = 45;            // cy
*p++ = 57;            // LOWORD (Control ID)
*p++ = 0;               // HOWORD (Control ID)

// The class name of the custom control
nchar = nCopyAnsiToWideChar (p, TEXT("ACustomControl")); p += nchar;

/* copy the text of the second item, null terminate the string. */
nchar = nCopyAnsiToWideChar (p, TEXT("")); p += nchar;

*p++ = 8; // number of bytes of extra data

*p++ = 0xA1;   //extra data
*p++ = 0xA2; *p++ = 0xA3; *p++ = 0xA4;

DialogBoxIndirect (ghInst, (LPDLGTEMPLATE) pdlgtemplate, hwnd, (DLGPROC) About); LocalFree (LocalHandle (pdlgtemplate));

///////////////////////////////////////////////////////////////////////////
//
//
Helper routines taken from the WIN32SDK DYNDLG sample
///////////////////////////////////////////////////////////////////////////
//
//
LPWORD lpwAlign ( LPWORD lpIn) {
  ULONG ul;

  ul = (ULONG) lpIn;
  ul +=3;
  ul >>=2;
  ul <<=2;
  return (LPWORD) ul;
}

int nCopyAnsiToWideChar (LPWORD lpWCStr, LPSTR lpAnsiIn)
{
  int nChar = 0;

  do {
    *lpWCStr++ = (WORD) *lpAnsiIn;
    nChar++;
  } while (*lpAnsiIn++);

  return nChar;
}

REFERENCE

For further information on using Dialog templates, please see the SDK documentation for the DLGTEMPLATE and DLGITEMTEMPLATE structures.


Additional reference words: 4.00 kbinf
KBCategory: kbprg kbcode
KBSubcategory:


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 14, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.