CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: GetTextExtent

  1. #1
    Join Date
    May 1999
    Posts
    3

    GetTextExtent

    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???


  2. #2
    Join Date
    Apr 1999
    Location
    Germany
    Posts
    418

    Re: GetTextExtent

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured