<p>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.</p>
<p>Is there a way to programmatically retrieve this padding value? Is it
related to the width of a particular character (&quot; &quot; or &quot;w&quot; or something?) or
is it a fixed value (6px on left and 3px on right or something) or...?</p>
<p>EDIT: To clarify, <strong>I want to add the same padding to my NM_CUSTOMDRAWn SubItems that the control adds to items that it draws</strong>, and the metric that I'm looking for, for example, is the white space between the beginning of the 2nd column and the word &quot;Siamese&quot; in the following screenshot (<em>Note: screenshot from MSDN added to help explain my question</em>):</p>
<p><a href="https://i.stack.imgur.com/yTHoy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yTHoy.png" alt="List View in Report View" /></a><br />
<sub>(source: <a href="https://msdn.microsoft.com/Bb774735.lv_detailsview(en-us,VS.85).png" rel="nofollow noreferrer">microsoft.com</a>)</sub></p>
<p>Note that the word &quot;Siamese&quot; is aligned with the header item (&quot;Breed&quot;). I would like to be able to guarantee the same alignment for custom-drawn items.</p>

[{'answer_id': 51577, 'author': 'Andrew', 'author_id': 826, 'author_profile': 'https://Stackoverflow.com/users/826', 'pm_score': 0, 'selected': False, 'text': "<p>I would assume that <em>GetSystemMetrics()</em> is that you need to look at. I think that <strong>SM_CXEDGE</strong> and <strong>SM_CYEDGE</strong> are probably the values you want, but don't quote me on that. ;-)</p>\n"}, {'answer_id': 55646, 'author': 'David L Morris', 'author_id': 3137, 'author_profile': 'https://Stackoverflow.com/users/3137', 'pm_score': 0, 'selected': False, 'text': "<p>Can only guess without seeing your output.  </p>\n\n<p>A few suggestions: If you are using the DrawTextEx function, have you have experimented with DT_INTERNAL et al?  </p>\n\n<p>Are you accidentally putting in a blank image/icon. </p>\n\n<p>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.</p>\n\n<p>Late edit after first comment:</p>\n\n<p>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)?</p>\n\n<p>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.</p>\n"}, {'answer_id': 55898, 'author': 'David L Morris', 'author_id': 3137, 'author_profile': 'https://Stackoverflow.com/users/3137', 'pm_score': 1, 'selected': False, 'text': '<p>ListView_GetSubItemRect  (LVM_GETSUBITEMTECT)</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/ms930172.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms930172.aspx</a></p>\n\n<p>Despite what the documentation says I suspect LVIR_LABEL returns just the returns the bounding rectangle of the item text, as per ListView_GetItemRect.</p>\n\n<p>(This just kept niggling me as I though I had actually seen an answer somewhere when playing with NM_CUSTOMDRAW).</p>\n\n<p>Edit After Comment 2:</p>\n\n<p>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.</p>\n\n<p>Given what you have found I would go back to the suggestion of using \nListView_GetItemRect to get LVIR_LABEL and compare that with LVIR_BOUNDS and use the difference.</p>\n'}, {'answer_id': 1937775, 'author': 'Almaz', 'author_id': 235729, 'author_profile': 'https://Stackoverflow.com/users/235729', 'pm_score': 2, 'selected': False, 'text': '<p>use ListView Header message HDM_GETBITMAPMARGIN\nsee <a href="http://msdn.microsoft.com/en-us/library/bb775314(VS.85).aspx" rel="nofollow noreferrer">link text</a></p>\n'}, {'answer_id': 8448191, 'author': 'Patrick', 'author_id': 1090057, 'author_profile': 'https://Stackoverflow.com/users/1090057', 'pm_score': 1, 'selected': False, 'text': '<p>the way for doing this is retrieving the format of the corresponding column with \nListView_GetColumn()\nthen check the retrieved myLVCOLUMN.mask</p>\n\n<pre><code>LVCOLUMN myLVCOLUMN;\nmyLVCOLUMN.mask=LVCF_FMT;\nListView_GetColumn(hwnd,nCol,&amp;myLVCOLUMN);\n</code></pre>\n\n<p>then when we draw the corresponding label belonging to that column</p>\n\n<pre><code>if(myLVCOLUMN.fmt &amp; LVCFMT_CENTER)\n    DrawText(x,x,x,x, DT_CENTER | DT_WORD_ELLIPSIS );\nelse if (myLVCOLUMN.fmt &amp; LVCFMT_RIGHT)\n    DrawText(x,x,x,x, DT_RIGHT | DT_WORD_ELLIPSIS );\nelse\n    DrawText(x,x,x,x, DT_LEFT | DT_WORD_ELLIPSIS );\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/51109', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5309/']