show method

void show({
  1. bool forced = false,
})

Bring window to the front with an optional forced flag.

Implementation

void show({bool forced = false}) {
  AttachThreadInput(
    GetCurrentThreadId(),
    GetWindowThreadProcessId(hWnd, nullptr),
    TRUE,
  );

  final Pointer<WINDOWPLACEMENT> place = calloc<WINDOWPLACEMENT>();
  GetWindowPlacement(hWnd, place);

  switch (place.ref.showCmd) {
    case SW_SHOWMAXIMIZED:
      ShowWindow(hWnd, SW_SHOWMAXIMIZED);
      break;
    case SW_SHOWMINIMIZED:
      ShowWindow(hWnd, SW_RESTORE);
      break;
    default:
      ShowWindow(hWnd, SW_NORMAL);
      break;
  }
  free(place);
  if (forced) {
    ShowWindow(hWnd, SW_RESTORE);
    SetForegroundWindow(hWnd);
    BringWindowToTop(hWnd);
    SetFocus(hWnd);
    SetActiveWindow(hWnd);
    UpdateWindow(hWnd);
  }
  SetForegroundWindow(hWnd);
  if (GetForegroundWindow() != hWnd) {
    SwitchToThisWindow(hWnd, TRUE);
    SetForegroundWindow(hWnd);
  }

  AttachThreadInput(
    GetCurrentThreadId(),
    GetWindowThreadProcessId(hWnd, nullptr),
    FALSE,
  );
}