Discussion:
CListCtrl unnecessarily clips texts in Windows 7
(too old to reply)
Kjetil Viggen
2010-01-18 13:22:01 UTC
Permalink
Hi All

My application uses the MFC control CListCtrl (in List mode) to display a
list of items. The control automatically orders items in columns, where the
column width is determined by the longest text.

This works well on Windows XP and Vista, but fails on Windows 7. A long text
may be correctly displayed, while a short text in the same column may get
clipped. Usually the last couple of letters will be missing, and replaced by
"...". The problem seems to occur on all Windows 7 PCs, and can also be
easily reproduced in a simple MFC test application.

Examples:
"GENERAL FURNITURE", "DRAWERS" and "THOUSANDS OF CHAIRS" are not clipped.
"SHELVES" becomes "SHELV...".
"LAVA LAMPS" becomes "LAVA LAM..."
"LAV" becomes "L..."

I have only seen the problem for texts containing capital letters. Texts
containing L, V and A seem especially error prone.

The problem only occurs for specific fonts. Texts get clipped if I use
Arial, Calibri or Times New Roman, while when using Arial Black, Georgia or
MS Sans Serif all texts are correctly displayed. So changing font could be a
workaround, but as all the rest of the UI uses Arial I would rather not do
this.

Does anyone have a clue what is going on here, and even better - how to fix
it?

Regards,
Kjetil
Leslie Milburn
2010-01-18 16:27:52 UTC
Permalink
Post by Kjetil Viggen
Hi All
My application uses the MFC control CListCtrl (in List mode) to display a
list of items. The control automatically orders items in columns, where the
column width is determined by the longest text.
This works well on Windows XP and Vista, but fails on Windows 7. A long text
may be correctly displayed, while a short text in the same column may get
clipped. Usually the last couple of letters will be missing, and replaced by
"...". The problem seems to occur on all Windows 7 PCs, and can also be
easily reproduced in a simple MFC test application.
"GENERAL FURNITURE", "DRAWERS" and "THOUSANDS OF CHAIRS" are not clipped.
"SHELVES" becomes "SHELV...".
"LAVA LAMPS" becomes "LAVA LAM..."
"LAV" becomes "L..."
I have only seen the problem for texts containing capital letters. Texts
containing L, V and A seem especially error prone.
The problem only occurs for specific fonts. Texts get clipped if I use
Arial, Calibri or Times New Roman, while when using Arial Black, Georgia or
MS Sans Serif all texts are correctly displayed. So changing font could be a
workaround, but as all the rest of the UI uses Arial I would rather not do
this.
Does anyone have a clue what is going on here, and even better - how to fix
it?
Regards,
Kjetil
This occurs when the column is not wide enough. Naturally different fonts
and using caps changes what can fit into the column. The solution is to make
the column wider. If I remember correctly, there is a function call to get
windows to autosize the columns itself but this would need to be done after
the list has been populated.

hth
Leslie.
Kjetil Viggen
2010-01-19 08:41:01 UTC
Permalink
Hi Leslie

Appreciate your reply, however it does not solve my problem.

I am well aware that texts get clipped in CListCtrl when a column is not
wide enough to accomodate the text. This is not the problem here.

I can resize my CListCtrl so that all my text entries are shown in a single
column.
The text "THOUSANDS OF CHAIRS" is then unclipped, i.e. the CListCtrl has
autosized the column to make room for this 19 characters long text.
The same column should display the text "LAV". This is however clipped, and
displayed as "L...". As the column has enough space to fit "THOUSANDS OF
CHAIRS", it should definitely also be able to display "LAV" without clipping.

Exactly the same code gives no clipping on XP and Vista, and this seems to
be a clear indication that there is a Windows 7 specific bug in some text
length calculation used by CListCtrl.

Kjetil
Kjetil Viggen
2010-01-19 09:43:01 UTC
Permalink
NB:

The problem only occurs in List view mode (LVS_LIST). When using Report view
mode (LVS_REPORT) the texts are correctly clipped according to column width.

Kjetil
Kjetil Viggen
2010-01-25 10:36:01 UTC
Permalink
Just to wrap this up:

I ended up unhappily doing a hack - changing the font in the CListCtrl from
Arial to MS Sans Serif. With this font no clipping occurs.

Seems like CListCtrl uses different algorithms for calculating the needed
field width for a text and for checking if a text is to wide to fit a given
field:
Step 1: Calculate needed field width for a given text.
Step 2: Clip the text if it is too long to fit a given field width.
The problem is most likely related to font kerning, as it was only observed
for capital letters, and specifically for letter commands like LV and AV.

Kjetil

Loading...