From 4041ff10f50d4b6dc5c14b18f180b2738cbbadd0 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Wed, 30 Sep 2020 15:12:21 +0300 Subject: Windows: Initial/minimum window size vs. UI scale factor --- src/win32.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/win32.c') diff --git a/src/win32.c b/src/win32.c index 36043b53..5eb2a0d5 100644 --- a/src/win32.c +++ b/src/win32.c @@ -25,11 +25,28 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define WIN32_LEAN_AND_MEAN #include +#include void setDPIAware_Win32(void) { SetProcessDPIAware(); } +float desktopDPI_Win32(void) { + /* Query Direct2D for the desktop DPI (not aware of which monitor, though). */ + float ratio = 1.0f; + ID2D1Factory *d2dFactory = NULL; + HRESULT hr = D2D1CreateFactory( + D2D1_FACTORY_TYPE_SINGLE_THREADED, &IID_ID2D1Factory, NULL, (void **) &d2dFactory); + if (SUCCEEDED(hr)) { + FLOAT dpiX = 96; + FLOAT dpiY = 96; + ID2D1Factory_GetDesktopDpi(d2dFactory, &dpiX, &dpiY); + ratio = (float) (dpiX / 96.0); + ID2D1Factory_Release(d2dFactory); + } + return ratio; +} + void useExecutableIconResource_SDLWindow(SDL_Window *win) { HINSTANCE handle = GetModuleHandle(NULL); HICON icon = LoadIcon(handle, "IDI_ICON1"); -- cgit v1.2.3