How to center align the items in the first column of CListCtrl?
To center align the items in the first column of the CListCtrl, you can use the SetColumnWidth function of CListCtrl to set the width of the first column, and then use the SetItemText method of CListCtrl to set the text of each item. Before setting the text, align the text to the center.
The example code is shown below:
// 获取CListCtrl对象
CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_CTRL);
// 设置第一列的宽度
pListCtrl->SetColumnWidth(0, 200);
// 设置每一行的文本居中对齐
LV_ITEM lvItem;
lvItem.mask = LVIF_TEXT;
lvItem.iSubItem = 0;
lvItem.fmt = LVCFMT_CENTER; // 设置居中对齐
// 设置第一行的文本
lvItem.iItem = 0;
lvItem.pszText = _T("Item 1");
pListCtrl->SetItem(&lvItem);
// 设置第二行的文本
lvItem.iItem = 1;
lvItem.pszText = _T("Item 2");
pListCtrl->SetItem(&lvItem);
// 设置更多行的文本...
Please note that IDC_LIST_CTRL in the above code is the ID of the list control, and you need to replace it with the ID you are actually using. Additionally, only the text for the first two lines is set in this example, you can set more lines as needed.