bindWindow method

void bindWindow(
  1. Window? window
)

Makes every call address window, or with null goes back to the window the platform currently considers the app's own.

By default the window is looked up with nativeapi's WindowManager.getCurrent(), retried by every call until it answers. On Windows that is the active window, so an app that keeps its window hidden during startup may have none to address before it is shown. Binding the window explicitly removes that dependency:

// hwnd: the HWND of the app's top-level window, from the runner.
windowManager.bindWindow(
  nativeapi.Window.createWithNativeWindow(Pointer<Void>.fromAddress(hwnd)),
);

Listeners and setPreventClose move to the new window: native events stop arriving from the previous one. A show requested while no window could be found is carried out on window.

Implementation

void bindWindow(nativeapi.Window? window) {
  _unwireNativeEvents();
  _window = null;
  if (window != null) {
    _adopt(window);
  } else if (_wantsNativeEvents) {
    // Resolves the current window, if there is one yet, and wires it.
    _wireNativeEvents();
  }
}