Export (0) Print
Expand All
Expand Minimize

CListCtrl::GetStringWidth

Determines the minimum column width necessary to display all of a given string.

int GetStringWidth(
   LPCTSTR lpsz 
) const;

Parameters

lpsz
Address of a null-terminated string whose width is to be determined.

Return Value

The width, in pixels, of the string pointed to by lpsz.

Remarks

The returned width takes into account the control's current font and column margins, but not the width of a small icon.

Example

// The pointer to my list view control.
extern CListCtrl* pmyListCtrl;

CString strColumn;
int nWidth;

// Insert six columns in the list view control. Make the width of
// the column be the width of the column header plus 50%.
for (int i=0;i < 6;i++)
{
   strColumn.Format(TEXT("column %d"), i);
   nWidth = 3*pmyListCtrl->GetStringWidth(strColumn)/2;
   pmyListCtrl->InsertColumn(i, strColumn, LVCFMT_LEFT, nWidth);
}

See Also

CListCtrl Overview | Class Members | Hierarchy Chart | CListCtrl::GetColumnWidth

Show:
© 2014 Microsoft