Yes, you can use GetThemePartSize
function .
some code:
HTHEME hTheme = ::OpenThemeData(hwnd, L"button");
SIZE szCheckBox;
HRESULT hr = GetThemePartSize(hTheme, NULL, BP_CHECKBOX, CBS_UNCHECKEDNORMAL, NULL, TS_TRUE, &szCheckBox);
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
is there any way to determine the exact size of the black-bordered square of the checkbox (CButton
with BS_AUTOCHECKBOX
style) in MFC? I'm talking only about the rectangle with the black border that contains an optional checkmark. Also, I'd like to determine the width of the gap between this square and the checkbox's text.
I tried everything mentioned here, but none of the answers gave me the exact result (Windows draws the 13x13px square on 100%, 16x16px on 125% dpi, 20x20px on 150%, ALSO 20x20px on 175% dpi (???), etc.). It seems that the real size doesn't seem to grow proportionally to the DPI, therefore I cannot come up with any formula. I'd also like to avoid a custom-drawn checkbox.
Yes, you can use GetThemePartSize
function .
some code:
HTHEME hTheme = ::OpenThemeData(hwnd, L"button");
SIZE szCheckBox;
HRESULT hr = GetThemePartSize(hTheme, NULL, BP_CHECKBOX, CBS_UNCHECKEDNORMAL, NULL, TS_TRUE, &szCheckBox);
On which OS ?
On Windows 10 1909, I get 13*13 for the default check box size (with the usual methods : GetThemePartSize when themed or size of OBM_CHECKBOXES when not themed) and 22-23 at 175%, which is = 13*175% = 22.75
A screencopy of a (themed) CheckBox at 175% :