Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 431435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:58:29+00:00 2026-05-12T19:58:29+00:00

In a Win32 GUI application I need to determine the width of area occupied

  • 0

In a Win32 GUI application I need to determine the width of area occupied by a string on a toolbar button so that I adjust the button width accordingly. The toolbar is plain old ToolbarWindow32 windows class. I use the following code:

 HDC dc = GetDC( toolbarWindowHandle );
 SIZE size;
 GetTextExtentPoint32( dc, stringToMeasure, tcslen(stringToMeasure), &size );

For some fixed string (say “Hello”) size.cx is filled with say 72 but when I make a screenshot of the toolbar with the very same string displayed on a button I see that the string occupies say 56 pixels.

The difference clearly depends on system fonts settings. I use “large fonts” and the value obtained by code is bigger than what is occupied on screen. On machines with “small fonts” the value obtained is smaller.

I thought if I use GetTextExtentPoint32() on a window device context it will return exactly the right size. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:58:29+00:00Added an answer on May 12, 2026 at 7:58 pm

    The font used by the toolbar won’t be selected into the DC so you’ll need to work out what font it is using, create a copy, select it into the DC, get the size and then select the font out (else you could end up with a resource leak). You will currently be getting the size of the system font I expect, or whatever the default DC font is.

    You could try finding the font handle used by sending a WM_GETFONT message to the toolbar window but this isn’t guaranteed to return the actual font used when the text is displayed. It all depends on how the toolbar works internally.

    However I’m pretty sure that the Win32 toolbar uses the menu font for rendering button text, which can be discovered using a combination of SystemParametersInfo and the NONCLIENTMETRICS structure.

    If I was at work I’d post some code.

    Don’t you just love Win32?

    BTW, I use the toolbar button text feature and have never had to size the button by hand in this way.

    http://msdn.microsoft.com/en-us/library/ms724947(VS.85).aspx
    http://msdn.microsoft.com/en-us/library/ms724506(VS.85).asp

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Win32 GUI application that has several edit controls (plain old EDIT
I have a win32 GUI (MFC) application which I need to port to a
I have a C++ Win32 application that was written as a Windows GUI project,
I have a Win32 GUI application that uses GDI havily. It needs to draw
I just noticed the memory usage of a simple win32 C based GUI application
I am working on an application/GUI created with Win32/ATL . So there is UI
I tried to build vtkMFC project available in vtk-5.8.0\VTK\Examples\GUI\Win32\vtkMFC. When I built that I
I've developed a Python application that runs both in the GUI mode and the
We have some code that works and it's a Win32 app with a GUI,
We have a command line application that could benefit from a GUI. We want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.