CListCtrl显示文本befor图像(文本左,图像右)。如何对齐文本和图像左?

时间:2015-05-06 09:14:30

标签: c++ mfc

我使用列表控件来查看文本和图像,每个选定的项目都与特定页面相关。但我想显示图像然后是文本,列表是在报表视图(样式)中只有FULLROWSELECT的extendedstyle,图片列表包含位图图片(仅供测试)可以任何一个帮助吗?

    code::
    int fmt_col = LVCFMT_LEFT;
if( MCCObject::IsLanguageRTL())
    fmt_col = LVCFMT_RIGHT;
//c_MainList.ModifyStyle(LVS_ICON | LVS_LIST | LVS_REPORT, 0);
//c_MainList.ModifyStyle( 0, LVS_REPORT);
DWORD style = LVS_EX_FULLROWSELECT  ;
c_MainList.SetExtendedStyle( style);
c_MainList.InsertColumn(0, _T("Item Name"), fmt_col);


CRect rect;
c_MainList.GetClientRect(&rect);
int nColInterval = rect.Width() - 5;
c_MainList.SetColumnWidth(0,nColInterval);
CImageList *pImageList;
pImageList = new CImageList();
pImageList->Create( 32, 32, ILC_MASK | ILC_COLOR16,2, 2);
 //pImageList->Create( 40, 40, ILC_MASK | ILC_COLOR16, 2, 1);

CBitmap bitmap;


bitmap.LoadBitmap(  IDB_HRBITMAP32);
pImageList->Add( &bitmap, (COLORREF)0xFFFFFF);
bitmap.DeleteObject();

bitmap.LoadBitmap( IDB_HRBITMAP33);
pImageList->Add( &bitmap, (COLORREF)0xFFFFFF);
bitmap.DeleteObject();
c_MainList.SetImageList( pImageList, LVSIL_SMALL);

COLORREF col;
col = RGB(240,240,240);
c_MainList.SetBkColor(col);
c_MainList.SetTextBkColor(col);
c_MainList.SetRedraw(TRUE);

    CString item_str = _T("");
int i = 0;
LVITEM lvi;
CString strItem;

lvi.mask =    LVIF_TEXT|LVIF_IMAGE;
lvi.iItem = i;
lvi.iSubItem = 0;
lvi.iIndent = 2;
item_str = MCCObject::GetResourceString(IDS_EMPINFO);
lvi.pszText = (LPTSTR)(LPCTSTR) item_str;
lvi.iImage = 1;     // There are 8 images in the image list
c_MainList.InsertItem( &lvi);
//c_MainList.SetItem(&lvi);
//c_MainList.SetItemData( 0, (DWORD_PTR)0);

i++;
lvi.mask =  LVIF_IMAGE | LVIF_TEXT;
lvi.iItem = i;
lvi.iSubItem = 0;
item_str = MCCObject::GetResourceString(IDS_EMPDOC);
lvi.pszText = (LPTSTR)(LPCTSTR)  item_str;
lvi.iImage = 1;     // There are 8 images in the image list
c_MainList.InsertItem(&lvi);
//c_MainList.SetItemData( 1, (DWORD_PTR)1);
i++;
lvi.mask =  LVIF_IMAGE | LVIF_TEXT;
lvi.iItem = i;
lvi.iSubItem = 0;
item_str = MCCObject::GetResourceString(IDS_OFFICIALDETAILS);
lvi.pszText = (LPTSTR)(LPCTSTR) item_str;
lvi.iImage = 1;     // There are 8 images in the image list
c_MainList.InsertItem(&lvi);
    //c_MainList.SetItemData( 2, (DWORD_PTR)2);
i++;
lvi.mask =  LVIF_IMAGE | LVIF_TEXT;
lvi.iItem = i;
lvi.iSubItem = 0;
item_str = MCCObject::GetResourceString(IDS_EMPSALARY);
lvi.pszText = (LPTSTR)(LPCTSTR) item_str;
lvi.iImage = 1;     // There are 8 images in the image list
c_MainList.InsertItem(&lvi);
//c_MainList.SetItemData( 3, (DWORD_PTR)3);
i++;
lvi.mask =  LVIF_IMAGE | LVIF_TEXT;
lvi.iItem = i;
lvi.iSubItem = 0;
item_str = MCCObject::GetResourceString(IDS_WORKPERIODS);
lvi.pszText = (LPTSTR)(LPCTSTR) item_str;
lvi.iImage = 1;     // There are 8 images in the image list
c_MainList.InsertItem(&lvi);
//c_MainList.SetItemData( 4, (DWORD_PTR)4); 
i++;
lvi.mask =  LVIF_IMAGE | LVIF_TEXT;
lvi.iItem = i;
lvi.iSubItem = 0;
item_str = MCCObject::GetResourceString(IDS_EMPTIMESYS);
lvi.pszText = (LPTSTR)(LPCTSTR) item_str;
lvi.iImage = 1;     // There are 8 images in the image list
c_MainList.InsertItem(&lvi);

0 个答案:

没有答案