Discussion:
Owner draw fixed and custom draw in a list view
(too old to reply)
Woody
2011-07-07 23:29:08 UTC
Permalink
Working on the same XListCtrl, I now want to change the spacing of
lines in report view from the default.

In VS6 I used the following VBI: the control is created with the style
owner draw fixed, and after OnMeasureItem has been called, and I give
it the desired line spacing, I cleared the owner-draw bit using
ModifyStyle.

The effect of this was that the custom drawing of the control worked,
and the line spacing in report view was the value I had passed in
repsonse to the WM_MEASUREITEM.

In VS2005, the same technique produces a different result. The line
spacing remains the default. If I leave the owner-draw fixed bit
alone, I am expected to provide a DrawItem function, and since I have
not, CListCtrl::DrawItem asserts.

Since the custom draw paradigm doesn't allow for changing in spacing,
how can I combine changing the (constant) spacing of the listview
control's items with the custom drawing?
Joseph M. Newcomer
2011-07-08 00:38:23 UTC
Permalink
See below...
Post by Woody
Working on the same XListCtrl, I now want to change the spacing of
lines in report view from the default.
In VS6 I used the following VBI: the control is created with the style
owner draw fixed, and after OnMeasureItem has been called, and I give
it the desired line spacing, I cleared the owner-draw bit using
ModifyStyle.
****
You did not mention what you mean by "spacing". I presume you are meaning vertical
spacing.
****
Post by Woody
The effect of this was that the custom drawing of the control worked,
and the line spacing in report view was the value I had passed in
repsonse to the WM_MEASUREITEM.
****
This surprises me because WM_MEASUREITEM is not a documented message from a CListCtrl
Post by Woody
In VS2005, the same technique produces a different result. The line
spacing remains the default. If I leave the owner-draw fixed bit
alone, I am expected to provide a DrawItem function, and since I have
not, CListCtrl::DrawItem asserts.
****
Yes, it is supposed to assert, because you didn't override it. I have read the
documentation of the list control and have found no way to set the item height for a
CListCtrl.

And yes, you have to do real owner-draw. It's more complex than you think, because there
are problems with horizontal scrolling.

You can find examples of this in my CListCtrlEx control which you can find in my Locale
Explorer, PowerPoint Indexer or PolyDraw Explorer downloads from my MVP Tips site. But I
have no idea how to change the height.
****
Post by Woody
Since the custom draw paradigm doesn't allow for changing in spacing,
how can I combine changing the (constant) spacing of the listview
control's items with the custom drawing?
****
I have not found any technique that would allow this. Are you sure about how you did
this? CListBox has it, but not CListCtrl.
joe
****
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
Woody
2011-07-08 07:16:39 UTC
Permalink
Yes, I meant vertical spacing (the height of each line).

I definitely get a WM_MEASUREITEM message from the control, with a
control type of 102 (which should be ODT_something, but I can't find
any such constant with that value). The item height in the
MEASUREITEMSTRUCT is 14.

I agree that this message doesn't seem to be documented, except
inasmuch as a list control is a CWnd.

Regardless, this method did work in VS6, and doesn't work in VS2005.
Maybe I can get around the limitation by doing something to cause the
list control to need a larger vertical spacing, such as an icon.
Malachy Moses
2011-07-13 15:32:56 UTC
Permalink
Post by Woody
Yes, I meant vertical spacing (the height of each line).
I definitely get a WM_MEASUREITEM message from the control, with a
control type of 102 (which should be ODT_something, but I can't find
any such constant with that value). The item height in the
MEASUREITEMSTRUCT is 14.
I agree that this message doesn't seem to be documented, except
inasmuch as a list control is a CWnd.
Regardless, this method did work in VS6, and doesn't work in VS2005.
Maybe I can get around the limitation by doing something to cause the
list control to need a larger vertical spacing, such as an icon.
The simplest way to change the row height in (report view of) a
CListCtrl is to display an icon with the desired height.

The icon can be a dummy icon which doesn't show, such as a transparent
icon with width of 1 pixel and height of the desired height.

All other ways that I know of require significant programming (such as
owner draw, which is often too much work).

@Joe Newcomer: WM_MEASUREITEM is documented as a message sent to a
list-view control (among other controls such as combo box):
http://msdn.microsoft.com/en-us/library/bb775925(VS.85).aspx
Woody
2011-07-14 07:47:36 UTC
Permalink
Post by Malachy Moses
@Joe Newcomer: WM_MEASUREITEM is documented as a message sent to a
list-view control (among other controls such as combo box):http://msdn.microsoft.com/en-us/library/bb775925(VS.85).aspx
I see this documentation, which mentions list-view controls. It does
not, however, say what Windows does with the filled-in
MEASUREITEMSTRUCT. It does not change the vertical spacing in report
view.
Joseph M. Newcomer
2011-07-14 14:04:35 UTC
Permalink
Many of those controls have the feel of having been "thrown together" rather than have
been "designed". The assumption that every line in a report view must be the same height
seems more than a little weird. Similarly, the rich edit control does not have any user
interface to set or read the "overwrite" status. I have no idea how such obvious features
were overlooked.
joe
Post by Woody
Post by Malachy Moses
@Joe Newcomer: WM_MEASUREITEM is documented as a message sent to a
list-view control (among other controls such as combo box):http://msdn.microsoft.com/en-us/library/bb775925(VS.85).aspx
I see this documentation, which mentions list-view controls. It does
not, however, say what Windows does with the filled-in
MEASUREITEMSTRUCT. It does not change the vertical spacing in report
view.
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Loading...