setDialog method

int setDialog({
  1. required int style,
  2. int dwExtendedStyle = 0,
  3. required int cdit,
  4. int x = 0,
  5. int y = 0,
  6. required int cx,
  7. required int cy,
  8. int windowSystemClass = 0,
  9. String windowClass = '',
  10. String title = '',
  11. String fontName = '',
  12. int fontSize = 0,
})

Sets the memory at the pointer location to the dialog supplied.

Returns the number of WORDs written.

Implementation

int setDialog(
    {required int style,
    int dwExtendedStyle = 0,
    required int cdit,
    int x = 0,
    int y = 0,
    required int cx,
    required int cy,
    int windowSystemClass = 0,
    String windowClass = '',
    String title = '',
    String fontName = '',
    int fontSize = 0}) {
  /// Size in 16-bit WORDs of the DLGTEMPLATE struct
  const dlgTemplateSize = 9;

  final ptr = cast<Uint16>();

  var idx = 0; // 16-bit index offset

  /// Specifies the properties of the DLGTEMPLATE structure.
  ptr.cast<DLGTEMPLATE>().ref
    ..style = style
    ..dwExtendedStyle = dwExtendedStyle
    ..cdit = cdit
    ..x = x
    ..y = y
    ..cx = cx
    ..cy = cy;

  idx += dlgTemplateSize;

  // Immediately following the DLGTEMPLATE structure is a menu array that
  // identifies a menu resource for the dialog box. If the first element of
  // this array is 0x0000, the dialog box has no menu and the array has no
  // other elements. Since Dart does not currently support embedding a
  // resource file in a Windows executable, the other settings are moot.
  ptr[idx++] = 0x0000;

  // Following the menu array is a class array that identifies the window
  // class of the dialog box. If the first element of the array is 0x0000, the
  // system uses the predefined dialog box class for the dialog box and the
  // array has no other elements. If the first element is 0xFFFF, the array
  // has one additional element that specifies the ordinal value of a
  // predefined system window class. If the first element has any other value,
  // the system treats the array as a null-terminated Unicode string that
  // specifies the name of a registered window class.
  if (windowClass.isNotEmpty) {
    idx += ((ptr + idx).cast<Utf16>().setString(windowClass) / 2).ceil();
  } else {
    if (windowSystemClass != 0) {
      ptr[idx++] = 0xFFFF;
      ptr[idx++] = windowSystemClass;
    } else {
      ptr[idx++] = 0x0000;
    }
  }

  /// Following the class array is a title array that specifies a
  /// null-terminated Unicode string that contains the title of the dialog
  /// box. If the first element of this array is 0x0000, the dialog box has no
  /// title and the array has no other elements.
  if (title.isEmpty) {
    ptr[idx++] = 0x0000;
  } else {
    idx += ((ptr + idx).cast<Utf16>().setString(title) / 2).ceil();
  }

  /// Following the title array is a 16-bit point size value and the typeface
  /// array, in that order, if the style member specifies the DS_SETFONT
  /// style. These are set for the dialog box. The typeface array is a
  /// null-terminated Unicode string.
  if ((style & DS_SETFONT == DS_SETFONT) && (fontName.isNotEmpty)) {
    ptr[idx++] = fontSize;
    idx += ((ptr + idx).cast<Utf16>().setString(fontName) / 2).ceil();
  }

  // Each DLGITEMTEMPLATE structure in the template must be aligned on a DWORD
  // boundary. Move idx forward so that it aligns to the next DWORD boundary.
  if ((ptr.address + idx) % 2 != 0) {
    ptr[idx++] = 0x0000;
  }
  return idx;
}