View Control SubItem padding for custom

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

在报告视图中列出视图

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.


使用ListView标题消息HDM_GETBITMAPMARGIN查看链接文本


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.


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 );
链接地址: http://www.djcxy.com/p/41768.html

上一篇: 优化LINQ to SQL查询

下一篇: 查看自定义的控件子项填充