Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Title bar width

Status
Not open for further replies.

TonyGroves

Programmer
Aug 13, 2003
2,389
IE
Anybody know how to get the width in pixels of the text region in a window's title bar?

I have an application where the window titles are dynamic and could be very long, and so I want to adjust the titles if necessary to fit in the available space.
 
Well, i know that i can get the window-width, and i should be able to take that value and subtract the "standart" buttons and thus get the usable width but that's the best i've got, there might very well be another way but i don't know it.

Totte
Keep making it perfect and it will end up broken.
 
Thanks for that, Totte.

If I had to do it the hard way, then to get the title bar text width, I'd have to take into account:
- Window width
- Border width
- What buttons are displayed
- The size of the buttons
- Whether the window is focused or not
- Whether there is an icon displayed
- The margins between buttons and text
- And probably more besides

Then, to decide if a particular string will fit into the available width, I'd have to take into account:
- The font used in the title bar
- Whether the window is focused or not

So, as you can understand, I'm hoping there's an API function that would save me having to find out where and how this information is stored, and processing it. After searching through the docs, it looks like there's not, so I'll probably just have to roll up my sleeves and get down to business.
 
Somewhere I saw a banner component. Instead of the title displaying on the top of the form, the banner would scroll some info across the top. This might be a more efficient way do displaying info instead of trying to resize the form.



James P. Cottingham
-----------------------------------------
[sup]To determine how long it will take to write and debug a program, take your best estimate, multiply that by two, add one, and convert to the next higher units.[/sup]
 
Hi,
Look under help for GetSystemMetrics()
There is a load of info you can get from this function (too much to list here).
GetSystemMetrics(SM_CYCAPTION) may be of use here but be sure to check if XP themes is on as this seems to throw it out slightly.
Hope this helps.....

"Time Is Precious, Waste It Wisely
 
something to consider would be using a font that
has a fixed char size. I think courier new has
this property. since you now beforehand by previous
tests, what length of char of this font will fit
into a certain length you can size your string
accordingly.


TC
 
Thanks for those contributions.

What I did (6 months ago now!) was use GetSystemMetrics() and other functions to estimate the space available for the caption, and adjusted the caption text until its TextWidth() value indicated it would fit.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top