diff --git a/src/launcher/window.cpp b/src/launcher/window.cpp index cfd666f..d0c26fa 100644 --- a/src/launcher/window.cpp +++ b/src/launcher/window.cpp @@ -34,6 +34,8 @@ void window::create(const std::string& title, const int width, const int height, this->handle_ = CreateWindowExA(NULL, this->wc_.lpszClassName, title.data(), flags, x, y, width, height, nullptr, nullptr, this->wc_.hInstance, this); + + SendMessageA(this->handle_, WM_DPICHANGED, 0, 0); } window::~window() @@ -131,6 +133,24 @@ void window::set_callback(const std::functionlast_dpi_) + { + RECT rect; + GetWindowRect(*this, &rect); + + const auto scale = dpi * 1.0 / this->last_dpi_; + this->last_dpi_ = dpi; + + const auto width = rect.right - rect.left; + const auto height = rect.bottom - rect.top; + + MoveWindow(*this, rect.left, rect.top, int(width * scale), int(height * scale), TRUE); + } + } + if (message == WM_DESTROY) { remove_window(this); diff --git a/src/launcher/window.hpp b/src/launcher/window.hpp index a9f9779..9d9f2a6 100644 --- a/src/launcher/window.hpp +++ b/src/launcher/window.hpp @@ -27,6 +27,8 @@ protected: virtual LRESULT processor(UINT message, WPARAM w_param, LPARAM l_param); private: + uint32_t last_dpi_ = 96; + WNDCLASSEX wc_{}; HWND handle_ = nullptr; std::string classname_; diff --git a/src/main.cpp b/src/main.cpp index 8eacebb..daeee2b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -81,6 +81,7 @@ FARPROC load_binary(const launcher::mode mode) int main() { FARPROC entry_point; + SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); { auto premature_shutdown = true;