setDialogItem method
Sets the memory at the pointer location to the dialog item supplied.
Returns the number of WORDs written.
Implementation
int setDialogItem({
required int style,
int dwExtendedStyle = 0,
required int x,
required int y,
required int cx,
required int cy,
required int id,
int windowSystemClass = 0,
String windowClass = '',
String text = '',
List<int> creationDataBytes = const [],
}) {
/// Size in 16-bit WORDs of the DLGITEMTEMPLATE struct
const dlgItemTemplateSize = 9;
final ptr = cast<Uint16>();
var idx = 0; // 16-bit index offset
/// Specifies the properties of the DLGITEMTEMPLATE structure.
ptr.cast<DLGITEMTEMPLATE>().ref
..style = style
..dwExtendedStyle = dwExtendedStyle
..x = x
..y = y
..cx = cx
..cy = cy
..id = id;
idx += dlgItemTemplateSize;
/// Immediately following each DLGITEMTEMPLATE structure is a class array
/// that specifies the window class of the control. If the first element of
/// this array is any value other than 0xFFFF, the system treats the array
/// as a null-terminated Unicode string that specifies the name of a
/// registered window class. If the first element is 0xFFFF, the array has
/// one additional element that specifies the ordinal value of a predefined
/// system class.
///
/// The ordinal can be one of the following atom values: 0x0080: Button
/// 0x0081: Edit 0x0082: Static 0x0083: List box 0x0084: Scroll bar
/// 0x0085: Combo box
if (windowClass.isNotEmpty) {
idx +=
(ptr.elementAt(idx).cast<Utf16>().setString(windowClass) / 2).ceil();
} else {
ptr[idx++] = 0xFFFF;
ptr[idx++] = windowSystemClass;
}
// Following the class array is a title array that contains the initial text
// or resource identifier of the control.
idx += (ptr.elementAt(idx).cast<Utf16>().setString(text) / 2).ceil();
// The creation data array begins at the next WORD boundary after the title
// array. This creation data can be of any size and format. If the first
// word of the creation data array is nonzero, it indicates the size, in
// bytes, of the creation data (including the size word).
if (creationDataBytes.isNotEmpty) {
ptr[idx++] = creationDataBytes.length + 1;
ptr
..elementAt(idx)
..cast<Uint8>()
..asTypedList(creationDataBytes.length).setAll(0, creationDataBytes);
idx += (creationDataBytes.length / 2).ceil();
} else {
ptr[idx++] = 0x0000;
}
// Move idx forward so that it aligns to the next DWORD boundary
if ((ptr.address + idx) % 2 != 0) {
ptr[idx++] = 0x0000;
}
return idx;
}