> I'm looking for a way to set the size of a header item so that it "just
> fits" the text of the item - any ideas?
It can't "just fit" the text because the text is drawn with a margin
(and it's different if themed or not)
> Sure, but there must be a way to determine the size of margin? After all, the
> listview control offers LVSCW_AUTOSIZE_USEHEADER, which does it somehow.
Text length is GetTextExtentPoint32() but the total width depends on
many flags (HDF_IMAGE, HDF_CHECKBOX, HDF_SORT*, HDF_SPLITBUTTON, ...)
Bitmap or text margins are GetSystemMetrics(SM_CXEDGE)*3 as mentioned in
the doc.
Besides Christian's reply, there is also a good article talks about
calculating the width of strings; it should be informative to you:
"Width of text in italic font"
http://www.codeproject.com/gdi/italicText.asp
Once you can determine the string width, you can send a message to the
header control to adjust the control side. Also, you should take care of
the control border width which addes with the string width to get the total
control width.
Hope this helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Thank you for the feedback.
Oh, I see your key concern now. Ok, I will try to discuss this with some
GUI team developers to see what the official calculation algorithm is.
Additionally, have you tried to add the string length with the 2 border
edge width(2*GetSystemMetrics(SM_CXEDGE))? Does this width just fit your
string without showing "..."?
Anyway, I will get back to you as soon as I got anything useful. Thanks.
> what is the extra width I need to add
> to arrive at the required size of header item so that the text is displayed
> without "...".
As I said + test if GetThemeBackgroundExtent() & HP_HEADERITEM is larger
if themed
Sorry for letting you wait.
I have discussed this issue with several GUI experts internally, they all
confirmed that the listview uses private knowledge of the header control
when autosizing via LVSCW_AUTOSIZE_USEHEADER. And this is an undocumented
implementation detail. There are many traits which can alter the width in
addition to the text: themes, icons, sort arrows, etc. You will have to
implement your own algorithm that does something similar.
Since you already have the text size, just add some padding until the
string fits without the ellipsis. Try using multiples of
GetSystemMetrics(SM_CXEDGE) and take care of the theme scenario as
Christian suggested.
Thanks for your understanding.
Thank you for the confirmation.
If you need further help, please feel free to post, thanks.