Home > Mobile >  How to create a window with CreateWindowEx but ignoring the scale settings on Windows
How to create a window with CreateWindowEx but ignoring the scale settings on Windows

Time:03-13

When I create a window with CreateWindowEx it will follow the resolution but also use the scale settings from the display settings. So, in 1920 x 1080 if I try to create the window, the size is actually 1200 something when scale is at 150%. Is there a way to get around this limitation? If I just set the size manually to 1920 x 1080 I get a cropped window. Thanks.

    auto activeWindow = GetActiveWindow();
    HMONITOR monitor = MonitorFromWindow(activeWindow, MONITOR_DEFAULTTONEAREST);
    //
    // Get the logical width and height of the monitor
    MONITORINFOEX monitorInfoEx;
    monitorInfoEx.cbSize = sizeof(monitorInfoEx);
    GetMonitorInfo(monitor, &monitorInfoEx);
    auto cxLogical = monitorInfoEx.rcMonitor.right - monitorInfoEx.rcMonitor.left;
    auto cyLogical = monitorInfoEx.rcMonitor.bottom - monitorInfoEx.rcMonitor.top;

vScreenSize = { cxLogical, cyLogical };

            WNDCLASS wc;
        wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
        wc.hInstance = GetModuleHandle(nullptr);
        wc.lpfnWndProc = olc_WindowEvent;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.lpszMenuName = nullptr;
        wc.hbrBackground = nullptr;
        wc.lpszClassName = olcT("Wusik SQ480 Engine");
        RegisterClass(&wc);
        DWORD dwExStyle = 0;
        DWORD dwStyle = WS_VISIBLE | WS_POPUP;
        olc::vi2d vTopLeft = vWindowPos;

        // Keep client size as requested
        RECT rWndRect = { 0, 0, vWindowSize.x, vWindowSize.y };
        AdjustWindowRectEx(&rWndRect, dwStyle, FALSE, dwExStyle);
        int width = rWndRect.right - rWndRect.left;
        int height = rWndRect.bottom - rWndRect.top;

        olc_hWnd = CreateWindowEx(dwExStyle, olcT("Wusik SQ480 Engine"), olcT(""), dwStyle,
            vTopLeft.x, vTopLeft.y, width, height, NULL, NULL, GetModuleHandle(nullptr), this);

CodePudding user response:

Thanks to Remy Lebeau it was as simple as adding the following call to the main initialization of the app. Now I always get a window with the physical resolution and not a logic scaled resolution.

SetProcessDPIAware();
  • Related