7

When using custom-draw (NM_CUSTOMDRAW) to draw the entire contents of a ListView SubItem (in Report/Details view), it would be nice to be able to apply the same left and right padding in my custom paint method that is applied by the control itself for non-custom-drawn items.

Is there a way to programmatically retrieve this padding value? Is it related to the width of a particular character (" " or "w" or something?) or is it a fixed value (6px on left and 3px on right or something) or...?

EDIT: To clarify, I want to add the same padding to my NM_CUSTOMDRAWn SubItems that the control adds to items that it draws, and the metric that I'm looking for, for example, is the white space between the beginning of the 2nd column and the word "Siamese" in the following screenshot (Note: screenshot from MSDN added to help explain my question):

List View in Report View
(source: microsoft.com)

Note that the word "Siamese" is aligned with the header item ("Breed"). I would like to be able to guarantee the same alignment for custom-drawn items.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
David Citron
  • 43,219
  • 21
  • 62
  • 72

5 Answers5

2

use ListView Header message HDM_GETBITMAPMARGIN see link text

Almaz
  • 21
  • 2
1

ListView_GetSubItemRect (LVM_GETSUBITEMTECT)

http://msdn.microsoft.com/en-us/library/ms930172.aspx

Despite what the documentation says I suspect LVIR_LABEL returns just the returns the bounding rectangle of the item text, as per ListView_GetItemRect.

(This just kept niggling me as I though I had actually seen an answer somewhere when playing with NM_CUSTOMDRAW).

Edit After Comment 2:

I imagine you have seen NMLVCUSTOMDRAW which if you are willing to use Version 6.0. has rcText. I wouldn't since I use Win2K.

Given what you have found I would go back to the suggestion of using ListView_GetItemRect to get LVIR_LABEL and compare that with LVIR_BOUNDS and use the difference.

David L Morris
  • 1,461
  • 1
  • 12
  • 19
  • Unfortunately no. It was easy to try, and the value returned by LVIR_BOUNDS and LVIR_LABEL are identical: they both return the entire subitem, wall-to-wall. – David Citron Sep 12 '08 at 04:32
  • So the documentation is correct, which makes it seem like Win32 is in error. What a pain. – David L Morris Sep 13 '08 at 01:12
1

the way for doing this is retrieving the format of the corresponding column with ListView_GetColumn() then check the retrieved myLVCOLUMN.mask

LVCOLUMN myLVCOLUMN;
myLVCOLUMN.mask=LVCF_FMT;
ListView_GetColumn(hwnd,nCol,&myLVCOLUMN);

then when we draw the corresponding label belonging to that column

if(myLVCOLUMN.fmt & LVCFMT_CENTER)
    DrawText(x,x,x,x, DT_CENTER | DT_WORD_ELLIPSIS );
else if (myLVCOLUMN.fmt & LVCFMT_RIGHT)
    DrawText(x,x,x,x, DT_RIGHT | DT_WORD_ELLIPSIS );
else
    DrawText(x,x,x,x, DT_LEFT | DT_WORD_ELLIPSIS );
Patrick
  • 11
  • 1
0

I would assume that GetSystemMetrics() is that you need to look at. I think that SM_CXEDGE and SM_CYEDGE are probably the values you want, but don't quote me on that. ;-)

Andrew
  • 11,894
  • 12
  • 69
  • 85
  • SM_CXEDGE and SM_CYEDGE are the window border widths. I'm looking for the internal leading and trailing padding in each table cell in a ListView control that's in "Report View" mode. Or am I missing something? – David Citron Sep 10 '08 at 01:28
0

Can only guess without seeing your output.

A few suggestions: If you are using the DrawTextEx function, have you have experimented with DT_INTERNAL et al?

Are you accidentally putting in a blank image/icon.

Does it look ok in classic screen mode? If so I would look at XP Theme functions to see if some thing is going on.

Late edit after first comment:

I wonder if the size of rectangle matches the space required for the LVN_ENDLABELEDIT edit box around the text so the text doesn't move (or for a focus rectangle)?

I guess you could compare the result of LVM_GETITEMRECT with LVIR_LABEL on the first column and use the difference as your left border.

David L Morris
  • 1,461
  • 1
  • 12
  • 19
  • If you custom draw a List-View Subitem (NM_CUSTOMDRAW), the you get an NMLVCUSTOMDRAW structure that contains a DC and bounding rect that is the entire "table cell" space from floor to ceiling and wall to wall. I want to know what padding to apply in my custom draw method so my contents a – David Citron Sep 11 '08 at 05:02
  • I have used NM_CUSTOMDRAW, but only to change the background colours of individual cells (CDDS_ITEMPREPAINT), and let it fall through to LVN_GETDISPINFO on the main proc. – David L Morris Sep 11 '08 at 05:47