$KDynamic Dialogs

The information contained in this help file is extracted from a document titled, "Win32 Binary resource formats."  This information was edited and released by Microsoft Developer Support.  Unfortunately, the format may change slightly in the future.  Microsoft is NOT committing to stay with this format by releasing this document.  Questions or followups for any of the information presented here should be posted to the Compuserve MSWIN32 forum, section 4. 

Strings in Unicode			DWORD Alignment
Dialog Box Resources

#$K1.2 Strings in UNICODE

All strings in a resource file are now stored in UNICODE format.  In this format, all characters are represented by a 16-bit (WORD) value. The first 256 characters are identical to the 256 characters in the Windows ANSI character set (although the characters are represented by 16 bits each rather than 8bits).  This means that they are terminated with a UNICODE_NULL symbol rather than a single NULL.  The resource compiler translates all normal ASCII strings into UNICODE by calling the MultiByteToWideChar function provided by the Windows API. All escaped characters are stored directly, and are assumed to be valid UNICODE characters for the resource.  If these strings are read in later by an application as ASCII (for instance, by calling the LoadString api), they will be converted back from UNICODE to ASCII transparently by the loader.
The only exception to the rule is strings in RCDATA statements. These psuedo-strings are not real strings, but merely a convenient notation for a collection of bytes.  Users may overlay a structure over the data from an RCDATA statement, and expect certain data to be at certain offsets.  If a psuedo-string gets automatically changed into a UNICODE string, it would inadvertently change the offsets of things in the structure and break those applications.  Hence, these psuedo-strings must be left as ASCII bytes.  To specify a UNICODE string inside an RCDATA statement, the user should use the explicit Lquoted string.

#$K1.3 DWORD Alignment

To make resource binary files easier to read under Windows 32, all objects within the file are to be DWORD aligned.  This includes headers, as well as data entries.  This does not usually entail changes in the order of the fields of resource data structures, but does entail the need for some padding between fields.

#$K4.4 Dialog Box Resources

A	dialog box is contained in a single resource and has a header and a portion repeated for each control in the dialog box.  The header is as follows:
		[Resource header (type = 5)]
struct DialogBoxHeader {
	DWORD  lStyle;
	DWORD  lExtendedStyle;     // new for NT
	WORD	NumberOfItems;
	WORD	x;
	WORD	y;
	WORD	cx;
	WORD	cy;
	[Name or Ordinal] MenuName;
	[Name or Ordinal] ClassName;
	WCHAR  szCaption[];
	WORD	wPointSize;         // Only here if FONT set for dialog
	WCHAR  szFontName[];       // This too
	};
The item DWORD lStyle is a standard window style composed of flags found in WINDOWS.H.    The default style for a dialog box is:
		WS_POPUP | WS_BORDER | WS_SYSMENU
The lExtendedStyle DWORD is used to specify the extended window style flags.  If an extended style is specified on the DIALOG statement, or with the other optional modifier statements, this DWORD is set to that value.
The items marked `Name or Ordinal' are the same format used throughout the resource file (most notably in each resource header) to store a name or an ordinal ID.  As before, if the first word is an 0xffff, the next two bytes contain an ordinal ID.  Otherwise, the first 1 or more WORDS contain a double-null-terminated string.  An empty string is represented by a single WORD zero in the first location.
The WORD wPointSize and WCHAR szFontName entries are present if the FONT statement was included for the dialog box.  This can be detected by checking the entry lStyle.  if lStyle & DS_SETFONT (DS_SETFONT = 0x40), then these entries will be present.
The data for each control starts on a DWORD boundary (which may require some padding from the previous control), and its format is as follows:
struct ControlData {
	DWORD  lStyle;
	DWORD  lExtendedStyle;
	WORD	x;
	WORD	y;
	WORD	cx;
	WORD	cy;
	WORD	wId;
	[Name or Ordinal] ClassId;
	[Name or Ordinal] Text;
	WORD   nExtraStuff;
	};
As before, the item DWORD lStyle is a standard window style composed of the flags found in WINDOWS.H.  The type of control is determined by the class.  The class is either given by a zero-terminated string, or in the case of many common Windows classes, is given a one word code to save space and speed processing - in this case, the ordinal number will be a WORD in length, but only the lower byte will be used.  Because UNICODE allows 0x8000 as a legal character, the ordinal classes are prefaced with a of 0xFFFF, similar to the ordinal Type and Name fields.  The one byte classes are listed here:
		#define	BUTTON	0x80
		#define	EDIT		0x81
		#define	STATIC	0x82
		#define	LISTBOX	0x83
		#define	SCROLLBAR	0x84
		#define	COMBOBOX	0x85
The lExtendedStyle DWORD is used to specify the extended style flags to be used for this control.  The extended style flags are placed at the end of the CONTROL (or other control statements) statement following the coordinates
The extra information at the end of the control data structure is currently not used, but is intended for extra information that may be needed for menu items in the future.  Usually it is zero length.
The various statements used in a dialog script are all mapped to these classes along with certain modifying styles.  The values for these styles can be found in WINDOWS.H.  All dialog controls have the default styles of WS_CHILD and WS_VISIBLE.  A list of the default styles used to make the script statements follows:
		Statement		Default Class  Default Styles
		CONTROL		None	WS_CHILD|WS_VISIBLE
		LTEXT		STATIC	ES_LEFT
		RTEXT		STATIC	ES_RIGHT
		CTEXT		STATIC	ES_CENTER
		LISTBOX		LISTBOX	WS_BORDER | LBS_NOTIFY
		CHECKBOX		BUTTON	BS_CHECKBOX | WS_TABSTOP
		PUSHBUTTON		BUTTON	BS_PUSHBUTTON | WS_TABSTOP
		GROUPBOX		BUTTON	BS_GROUPBOX
		DEFPUSHBUTTON	BUTTON	BS_DEFPUSHBUTTON | WS_TABSTOP
		RADIOBUTTON	BUTTON	BS_RADIOBUTTON
		AUTOCHECKBOX	BUTTON	BS_AUTOCHECKBOX
		AUTO3STATE		BUTTON	BS_AUTO3STATE
		AUTORADIOBUTTON BUTTON	BS_AUTORADIOBUTTON
		PUSHBOX		BUTTON	BS_PUSHBOX
		STATE3		BUTTON	BS_3STATE
		EDITTEXT		EDIT	ES_LEFT|WS_BORDER|WS_TABSTOP
		COMBOBOX		COMBOBOX	None
		ICON		STATIC	SS_ICON
		SCROLLBAR		SCROLLBAR	None
The control text is stored in the `Name or Ordinal' format described in detail above.