Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

header ctrl item sizing

1 view
Skip to first unread message

Simon Scott

unread,
Sep 25, 2007, 6:14:00 AM9/25/07
to
Hi,
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?
--
Regards
Simon

Christian ASTOR

unread,
Sep 25, 2007, 8:18:19 AM9/25/07
to
Simon Scott wrote:

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

Simon Scott

unread,
Sep 25, 2007, 8:24:01 AM9/25/07
to
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.
--
Regards
Simon

Christian ASTOR

unread,
Sep 25, 2007, 8:57:30 AM9/25/07
to
Simon Scott wrote:

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

Jeffrey Tan[MSFT]

unread,
Sep 25, 2007, 11:14:49 PM9/25/07
to
Hi Simon,

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.

Simon Scott

unread,
Sep 28, 2007, 4:35:00 PM9/28/07
to
Thanks for the comments. I have no problem calculating the length of the
string. What I'm trying to find out is 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 "...".
--
Regards
Simon

Jeffrey Tan[MSFT]

unread,
Oct 1, 2007, 3:34:11 AM10/1/07
to
Hi Simon,

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.

Christian ASTOR

unread,
Oct 1, 2007, 8:22:23 AM10/1/07
to
Simon Scott wrote:

> 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

Jeffrey Tan[MSFT]

unread,
Oct 2, 2007, 10:01:42 PM10/2/07
to
Hi Simon,

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.

Simon Scott

unread,
Oct 3, 2007, 11:26:04 AM10/3/07
to
Thanks for looking into the issue for me. I suspected this would be the
answer, just wanted to be sure I wasn't missing something in the
documentation.
--
Regards
Simon

Jeffrey Tan[MSFT]

unread,
Oct 3, 2007, 11:33:08 PM10/3/07
to
Hi Simon,

Thank you for the confirmation.

If you need further help, please feel free to post, thanks.

0 new messages