close method

bool? close()

Closes this Window.

  • Calls Win32 CloseWindow.
  • Returns true (closed) and calls CloseWindow if processClose returns null (delegates to default behavior).
  • Returns false (minimize) if processClose returns true (confirm close).
  • Returns null (do nothing) if processClose returns false (abort close).

Implementation

bool? close() {
  final hwnd = this.hwnd;

  var shouldClose = processClose();
  notifyClose();

  if (shouldClose == null) {
    var r = CloseWindow(hwnd);
    // retry:
    if (r == 0) {
      WindowMessageLoop.consumeQueue();
      r = CloseWindow(hwnd);
    }

    if (r == 0) {
      final errorCode = GetLastError();
      _logWindow.warning(
          "Error closing `Window`> errorCode: $errorCode ; hwnd: $hwnd -> $this");
      return false;
    }
    return true;
  } else if (shouldClose) {
    if (!isMinimized) {
      minimize();
    }
    return false;
  } else {
    return null;
  }
}