INFO: DIALOGEX Resource Template Differences from DIALOG Template

ID: Q141201


The information in this article applies to:


SUMMARY

When you create or modify a dialog box 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 box. */ 
nchar = nCopyAnsiToWideChar (p, TEXT("Dialog"));
p += nchar;

   /* Font information because of DS_SETFONT. */ 
   *p++ = MAKEWORD( 18, DEFAULT_CHARSET );  // Point size and charset.

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;
}
 


REFERENCES

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

Additional query words: 4.00 kbinf


Keywords          : kbcode kbNTOS351 kbWinOS95 kbDSupport 
Version           : WINDOWS:95
Platform          : WINDOWS 
Issue type        : kbinfo 

Last Reviewed: July 21, 1999