From 0a4c74ea2a5ca4ff34ed77e3f23f80871883d6de Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Mon, 7 Jun 2021 01:36:47 +0200 Subject: [PATCH] add limiter for max resolution --- src/dd.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/dd.c b/src/dd.c index c4219ca..7394fe5 100644 --- a/src/dd.c +++ b/src/dd.c @@ -131,8 +131,34 @@ HRESULT dd_EnumDisplayModes(DWORD dwFlags, LPDDSURFACEDESC lpDDSurfaceDesc, LPVO { 1920, 1080 }, }; + DWORD max_w = 0; + DWORD max_h = 0; + DEVMODE m; + + memset(&m, 0, sizeof(DEVMODE)); + m.dmSize = sizeof(DEVMODE); + + if (EnumDisplaySettings(NULL, ENUM_REGISTRY_SETTINGS, &m)) + { + max_w = m.dmPelsWidth; + max_h = m.dmPelsHeight; + } + for (i = 0; i < sizeof(resolutions) / sizeof(resolutions[0]); i++) { + if ((max_w && resolutions[i].cx > max_w) || (max_h && resolutions[i].cy > max_h)) + { + memset(&m, 0, sizeof(DEVMODE)); + + m.dmSize = sizeof(DEVMODE); + m.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; + m.dmPelsWidth = resolutions[i].cx; + m.dmPelsHeight = resolutions[i].cy; + + if (ChangeDisplaySettings(&m, CDS_TEST) != DISP_CHANGE_SUCCESSFUL) + continue; + } + memset(&s, 0, sizeof(DDSURFACEDESC)); s.dwSize = sizeof(DDSURFACEDESC);