Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: JoeH on March 02, 2026, 03:07:10 pm

Title: Display resolution issue
Post by: JoeH on March 02, 2026, 03:07:10 pm
   I am experiencing a difficulty with retrieving the dpi display value.  I want my program to draw to the display at actual size.  As an example, I want to draw a circle with a 3 inch diameter to the screen and when the display is measured with a ruler, the circle measures 3 inches in diameter.  I want to accomplish this without the user having to input any scaling information and regardless of the display resolution the user has implemented on his computer.

   Here are the details of my installation from the CodeBlocks Help/About display:

Name               : Code::Blocks
Version                     : 25.03-r13644
SDK Version            : 2.25.0
Scintilla Version                 : 3.7.5
Author               : The Code::Blocks Team
E-mail               : info@codeblocks.org
Website                    : https://www.codeblocks.org
OS                       : Windows ll (build 26100), 64-bit edition
Scaling factor            : 1.000000
Detected scaling factor      : 1.000000
Display PPI            : 96x96
Display count            : 1
Display 0 (\\.\DISPLAY1)      : XY=[0,0]; Size=[1920,1080]; Primary

wxWidgets Library (wxMSW port)
Version 3.2.7 (Unicode: wchar_t, debug level: 1),
compiled at Mar 25 2025 17:16:27

Runtime version of toolkit used is 10.0.26100.

I am using a HP laptop that has a display that is 15 inches wide and 8.5 inches high.  My calculator tells me that the PPI for 1920x1080 is 127 (close enough) in each direction.  As you can see above, the reported Display PPI is 96x96.  These are the values I get within my program as well.

   If I manually enter the 127 ppi into my program I get the display results I desire (actual size).  Is there a mechanism to get the actual ppi from a system call?

   Thanks for your help.

Joe
Title: Re: Display resolution issue
Post by: Miguel Gimenez on March 02, 2026, 06:28:55 pm
Windows 11 on laptops with a native resolution of 1920x1080 usually sets a 125 % scaling factor, so the PPI in logical pixels (DIP) may be 127/125 ~ 100. This scaling factor should appear in the About dialog, though.

One way to check your manifest (referring to your post on wxForums) is using Resource Hacker. This is part of the manifest from C::B

Code
<asmv3:application xmlns="urn:schemas-microsoft-com:asm.v1">
    <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
      <dpiAware>True</dpiAware>
    </asmv3:windowsSettings>
</asmv3:application>

You can try using FromDIP() and ToDIP() from wxWindow.

EDIT: Strangely, your Windows version appears as "Windows II" (Windows 2 in roman numerals), not "Windows 11"; Did you edit the installation details?.
Title: Re: Display resolution issue
Post by: ollydbg on March 03, 2026, 01:59:10 am
Maybe, the OP used some image shot and OCR software?  :)
Title: Re: Display resolution issue
Post by: JoeH on March 04, 2026, 12:35:45 am
That is exactly what happened.  I tried to post a screen shot of the Help/About data, but I guess the image was too large.  I then passed it through an OCR program and missed correcting those two I's to ones.

I am currently chasing Miguel's leads on From and ToDPI but have not stumbled on anything promising yet.

I have given up on doing anything relative to the manifest because it is beyond my level of understanding.

Joe
Title: Re: Display resolution issue
Post by: Miguel Gimenez on March 04, 2026, 09:26:28 am
On MSW PPI is always reported as (96x96)*scale factor. The screen size in inches may be available via EDID (Extended Display Identification Data), but wxWidgets does not support it; use EnumDisplayDevices() and the registry to get the information.

For laptops you can use GetIntegratedDisplaySize() from the Windows API, included in sysinfoapi.h.
Title: Re: Display resolution issue
Post by: JoeH on March 07, 2026, 04:19:55 am
I gave the recommended "Get" function a try.  Even though I included the sysinfoapi.h file in the main header file, the code will not compile successfully.  I get a error stating "GetIntegratedDisplaySize was not declared in this scope".

Joe
Title: Re: Display resolution issue
Post by: ollydbg on March 07, 2026, 07:56:37 am
AI helps:

Code
#include <windows.h>
#include <iostream>

typedef HRESULT (WINAPI *GetIntegratedDisplaySize_t)(double*);

int main()
{
    HMODULE hKernelBase = LoadLibraryW(L"kernelbase.dll");
    if (!hKernelBase)
    {
        std::wcout << L"Failed to load kernelbase.dll\n";
        return 1;
    }

    auto GetIntegratedDisplaySize =
        (GetIntegratedDisplaySize_t)GetProcAddress(
            hKernelBase,
            "GetIntegratedDisplaySize"
        );

    if (!GetIntegratedDisplaySize)
    {
        std::wcout << L"API not available\n";
        return 1;
    }

    double size = 0.0;
    HRESULT hr = GetIntegratedDisplaySize(&size);

    if (SUCCEEDED(hr))
    {
        std::wcout << L"Integrated display size: "
                   << size
                   << L" inches\n";
    }

    FreeLibrary(hKernelBase);
}

I can compile and run the program under msys2/mingw64/gcc.
Title: Re: Display resolution issue
Post by: Miguel Gimenez on March 07, 2026, 10:47:15 am
The quickest solution is adding libonecore.a to the linker.