Checkbox / How do I get the width/height of it?
-
I have a button with
BS_CHECKBOX
style and text. I want to center the checkbox with my dialog so I need to get the "real" width of the control (Checkbox + gap + text = full width). I know how to get the width of the text part but how do I get the width and height of the checkbox itself? I looked atGetSystemMetrics
andSystemParametersInfo
but didn't find any. Any ideas where to look at? The width of the gap between is also needed. I need a plain WinAPI solution that works on all versions of Windows (not XP only). Thanks in advance, Sebastian ------------------------------------------- My website: http://www.hartwork.org -- modified at 1:03 Sunday 5th March, 2006 -
I have a button with
BS_CHECKBOX
style and text. I want to center the checkbox with my dialog so I need to get the "real" width of the control (Checkbox + gap + text = full width). I know how to get the width of the text part but how do I get the width and height of the checkbox itself? I looked atGetSystemMetrics
andSystemParametersInfo
but didn't find any. Any ideas where to look at? The width of the gap between is also needed. I need a plain WinAPI solution that works on all versions of Windows (not XP only). Thanks in advance, Sebastian ------------------------------------------- My website: http://www.hartwork.org -- modified at 1:03 Sunday 5th March, 2006More searching taught me that
SM_CXMENUCHECK
andSM_CXMENUSIZE
seem to be what I was looking for. So my new problem is how do I tellGetTextExtentPoint32
to work with the new font and not the default one. Here's my code:const TCHAR * const szNeverAgain = TEXT( "Do not ask again" );
SendMessage( hNeverAgain, WM_SETFONT, ( WPARAM )GetStockObject( DEFAULT_GUI_FONT ), ( LPARAM )TRUE );
const HDC hdc = GetDC( hNeverAgain );
SIZE size;
GetTextExtentPoint32( hdc, szNeverAgain, _tcslen( szNeverAgain ), &size );
ReleaseDC( hNeverAgain, hdc );size.cx
is always the width for the old font. I need the new one - any ideas? ------------------------------------------- My website: http://www.hartwork.org -
More searching taught me that
SM_CXMENUCHECK
andSM_CXMENUSIZE
seem to be what I was looking for. So my new problem is how do I tellGetTextExtentPoint32
to work with the new font and not the default one. Here's my code:const TCHAR * const szNeverAgain = TEXT( "Do not ask again" );
SendMessage( hNeverAgain, WM_SETFONT, ( WPARAM )GetStockObject( DEFAULT_GUI_FONT ), ( LPARAM )TRUE );
const HDC hdc = GetDC( hNeverAgain );
SIZE size;
GetTextExtentPoint32( hdc, szNeverAgain, _tcslen( szNeverAgain ), &size );
ReleaseDC( hNeverAgain, hdc );size.cx
is always the width for the old font. I need the new one - any ideas? ------------------------------------------- My website: http://www.hartwork.orgSelect a font into the DC before calling
GetTextExtentPoint32
. e.g.const TCHAR * const szNeverAgain = TEXT( "Do not ask again" ); SendMessage( hNeverAgain, WM_SETFONT, ( WPARAM )GetStockObject( DEFAULT_GUI_FONT ), ( LPARAM )TRUE ); HDC hdc = GetDC( hNeverAgain ); HFONT hOldFont = (HFONT)SelectObject(hdc, hYourFont); SIZE size; GetTextExtentPoint32( hdc, szNeverAgain, _tcslen( szNeverAgain ), &size ); SelectObject(hdc, hOldFont); ReleaseDC( hNeverAgain, hdc );
Steve
-
Select a font into the DC before calling
GetTextExtentPoint32
. e.g.const TCHAR * const szNeverAgain = TEXT( "Do not ask again" ); SendMessage( hNeverAgain, WM_SETFONT, ( WPARAM )GetStockObject( DEFAULT_GUI_FONT ), ( LPARAM )TRUE ); HDC hdc = GetDC( hNeverAgain ); HFONT hOldFont = (HFONT)SelectObject(hdc, hYourFont); SIZE size; GetTextExtentPoint32( hdc, szNeverAgain, _tcslen( szNeverAgain ), &size ); SelectObject(hdc, hOldFont); ReleaseDC( hNeverAgain, hdc );
Steve
This is it! It works! I'm so happy - Thank you very much! Best regards, Sebastian ------------------------------------------- My website: http://www.hartwork.org
-
Select a font into the DC before calling
GetTextExtentPoint32
. e.g.const TCHAR * const szNeverAgain = TEXT( "Do not ask again" ); SendMessage( hNeverAgain, WM_SETFONT, ( WPARAM )GetStockObject( DEFAULT_GUI_FONT ), ( LPARAM )TRUE ); HDC hdc = GetDC( hNeverAgain ); HFONT hOldFont = (HFONT)SelectObject(hdc, hYourFont); SIZE size; GetTextExtentPoint32( hdc, szNeverAgain, _tcslen( szNeverAgain ), &size ); SelectObject(hdc, hOldFont); ReleaseDC( hNeverAgain, hdc );
Steve
Btw in case you are the author of SpeedLoad - good work! :-D ------------------------------------------- My website: http://www.hartwork.org
-
Btw in case you are the author of SpeedLoad - good work! :-D ------------------------------------------- My website: http://www.hartwork.org
Yeah I'm to blame for SpeedLoad. Thanks for your kind words. Steve
-
I have a button with
BS_CHECKBOX
style and text. I want to center the checkbox with my dialog so I need to get the "real" width of the control (Checkbox + gap + text = full width). I know how to get the width of the text part but how do I get the width and height of the checkbox itself? I looked atGetSystemMetrics
andSystemParametersInfo
but didn't find any. Any ideas where to look at? The width of the gap between is also needed. I need a plain WinAPI solution that works on all versions of Windows (not XP only). Thanks in advance, Sebastian ------------------------------------------- My website: http://www.hartwork.org -- modified at 1:03 Sunday 5th March, 2006 -
No. The problem is the width can be much more than the text in it actually needs. If I want to center the checkbox I need the width of what the user sees, not the width of the window rect. Best regards, Sebastian ------------------------------------------- My website: http://www.hartwork.org