共用方式為


CListCtrl::GetStringWidth

判斷所需要的最少的資料行寬度顯示所有指定的字串。

int GetStringWidth( 
   LPCTSTR lpsz  
) const;

參數

  • lpsz
    要判斷寬度 null 結尾字串的位址。

傳回值

的寬度,以像素為單位,字串所指向的 lpsz。

備註

這個傳回的寬度允許控制項的目前的字型和資料行的框線,,而小型圖示的不是寬度。

範例

       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(_T("column %d"), i);
            nWidth = 3*m_myListCtrl.GetStringWidth(strColumn)/2;
            m_myListCtrl.InsertColumn(i, strColumn, LVCFMT_LEFT, nWidth);
        }

需求

Header: afxcmn.h

請參閱

參考

CListCtrl 類別

階層架構圖表

CListCtrl::GetColumnWidth