Click to See Complete Forum and Search --> : GetTextExtent


Jan-Klaas
May 27th, 1999, 03:10 AM
I would like to display a progress bar in my status bar next to a string of text like
"Processing..." <here the progress bar>
For this reason I tried to calculate the width of the string using

m_wndStatusBar.GetDC()->GetTextExtent(str);




However, the font selected in the device context of the status bar doesn't seem to be the font of the displayed string. GetTextExtent returns a too large value.

Who can help???

Martin Speiser
May 27th, 1999, 04:51 AM
Hi Jan-Klaas,

if you call GetDC(), and then GetTextExtent() the length is calculated on the standard font. You need to select the font in the DC by yourself. To get the font you can use


NONCLIENTMETRICS ncm;
memset( &ncm, 0, sizeof( ncm );
ncm.cbSize = sizeof( ncm );
SystemParametersInfo( SPI_GETNONCLIENTMETRICS, sizeof( ncm ), &ncm, FALSE );
CFont font;
font.CreateFontIndirect( &ncm.lfStatusFont );




After getting the font select it in the DC, and call GetTextExtent afterwards.

HTH


Martin