Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I measure the width of the caption bar available for text?

Tags:

winapi

I'm trying to adjust the caption of my main window to show as much of a file name as is possible to fit in the caption area. So, I'm looking to calculate the width of the area marked up here in the red rectangle:

enter image description here

Now, I would ideally like to have code that can use whatever system metrics are available and thereby avoid being caught out by all the various platform/theme/dpi variations that can exist.

How can this be done, if indeed it is even possible?

like image 258
David Heffernan Avatar asked Nov 10 '22 01:11

David Heffernan


1 Answers

As andlabs said in the comments, the WM_GETTITLEBARINFOEX message can be used to obtain the required information.

This message can be sent to the window and the TITLEBARINFOEX struct is populated with the state and location of the titlebar and each of its buttons. From there it is a simple task to determine how much space is available for the caption.

like image 180
David Heffernan Avatar answered Nov 15 '22 13:11

David Heffernan