The problem has been discussed here, but people settled for an inaccurate solution. I'm using a CButton class with a BS_AUTOCHECKBOX flag. Is there a precise way to determine the size of the square with a black border (which holds the checkmark) on Windows/MFC? And also the gap between this square and text?
I realized, the gap can be calculated like this (scale_factor depends on the client's current screen DPI - 100%dpi, scale_factor==1; 150%dpi, scale_factor==1.5, etc.)
std::ceil(3 * scale_factor)
I need my solution to return the true size based on the client's screen resolution/DPI settings. Windows creates this square 13x13px on 100% DPI, 16x16px on 125% DPI, but 20x20px on both 150% and 175% DPI! Therefore, it's impossible to just multiply 13 with the scale_factor.
This code
int x = GetSystemMetrics(SM_CXMENUCHECK);
int y = GetSystemMetrics(SM_CYMENUCHECK);
returns 15px on 100% DPI, 19px on 125% DPI, and if I subtract
int xInner = GetSystemMetrics( SM_CXEDGE );
int yInner = GetSystemMetrics( SM_CYEDGE );
which returns 2px (on every DPI setting (???) ), I get my 13px on 100% dpi, but 17px on 125% DPI (it should be 16) and the error only gets bigger with higher DPIs. The problem is that the SM_CXMENUCHECK doesn't represent the standard CButton checkbox.
I'd like to avoid custom drawing. Is there any way to do this with pixel-precision (if not, what's the best possible solution you came up with)? Many thanks in advance.
EDIT: Just to clarify, I need a function (or some algorithm) that will return 13px on 100% scaling, 16px on 125%, 20px on 150% AND 175% (and for any other possible scalings as well). That means I need a true size of the checkbox (which is drawn by Windows based on the resolution that is currently set on the client's screen).
