Skip to content

Instantly share code, notes, and snippets.

@slightfoot
Created September 25, 2024 18:19
Show Gist options
  • Save slightfoot/9a274ae6477ac09f55674b3be6704b02 to your computer and use it in GitHub Desktop.
Save slightfoot/9a274ae6477ac09f55674b3be6704b02 to your computer and use it in GitHub Desktop.
Flutter Windows Desktop - Client Area Adjustment :: by Simon Lightfoot - 25th September 2024 :: https://www.youtube.com/watch?v=QiLPSsD9kRc
bool Win32Window::Create(const std::wstring& title,
const Point& origin,
const Size& size) {
Destroy();
const wchar_t* window_class =
WindowClassRegistrar::GetInstance()->GetWindowClass();
const POINT target_point = {static_cast<LONG>(origin.x),
static_cast<LONG>(origin.y)};
HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST);
UINT dpi = FlutterDesktopGetDpiForMonitor(monitor);
double scale_factor = dpi / 96.0;
RECT windowRect = {
0,
0,
static_cast<LONG>(size.width),
static_cast<LONG>(size.height),
};
AdjustWindowRectEx(&windowRect, WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW);
HWND window = CreateWindowEx(
WS_EX_APPWINDOW,
window_class,
title.c_str(),
WS_OVERLAPPEDWINDOW,
Scale(origin.x, scale_factor),
Scale(origin.y, scale_factor),
Scale((windowRect.right - windowRect.left), scale_factor),
Scale((windowRect.bottom - windowRect.top), scale_factor),
nullptr,
nullptr,
GetModuleHandle(nullptr),
this
);
if (!window) {
return false;
}
UpdateTheme(window);
return OnCreate();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment