15,979
社区成员
发帖
与我相关
我的任务
分享
m_cameraList.GetClientRect(&rect);
// 为列表视图控件添加全行选中和栅格风格
m_cameraList.SetExtendedStyle(m_cameraList.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_SUBITEMIMAGES);
// 为列表视图控件添加四列
m_cameraList.InsertColumn(0, _T("是否启用"), LVCFMT_CENTER, rect.Width()/5, 0);
m_cameraList.InsertColumn(1, _T("名字"), LVCFMT_CENTER, rect.Width()/5, 1);
m_cameraList.InsertColumn(2, _T("端口"), LVCFMT_CENTER, rect.Width()/5, 2);
m_cameraList.InsertColumn(3, _T("类型"), LVCFMT_CENTER, rect.Width()/5, 3);
m_cameraList.InsertColumn(4, _T("相机ID"), LVCFMT_CENTER, rect.Width()/5, 4);
//图像列表与CListCtrl控件关联
m_ImageList.Create(32, 32, ILC_COLOR32, 2, 20);
m_ImageList.Add(AfxGetApp()->LoadIconW(IDI_ICON1));
m_ImageList.Add(AfxGetApp()->LoadIconW(IDI_ICON2));
m_cameraList.SetImageList(&m_ImageList,LVSIL_SMALL);
m_cameraList.InsertItem(0,false,0);
m_ImageList.Detach();
if (nCol == 0)
{
Image image_true(_T("res/png/true.png"));
Image image_false(_T("res/png/false.png"));
Graphics gh(lpDrawItemStruct->hDC);
if('t' == lpBuffer[0])
{
gh.DrawImage(&image_true,rcItem.left+(rcItem.right-rcItem.left)/2-8,rcItem.top+(rcItem.bottom-rcItem.top)/2-12,16,16);
}else
{
gh.DrawImage(&image_false,rcItem.left+(rcItem.right-rcItem.left)/2-8,rcItem.top+(rcItem.bottom-rcItem.top)/2-12,16,16);
}
}else
{
CFont nFont ,* nOldFont;
nFont.CreateFont(m_fontHeight,m_fontWith,0,0,0,FALSE,FALSE,0,0,0,0,0,0,_TEXT("微软雅黑"));//创建字体
DrawText(lpDrawItemStruct->hDC, lpBuffer,strlenT(lpBuffer),
&rcItem, uFormat) ;
pDC->SelectStockObject(SYSTEM_FONT) ;
}
void CMyListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
TCHAR lpBuffer[256];
LV_ITEM lvi;
lvi.mask = LVIF_TEXT | LVIF_PARAM ;
lvi.iItem = lpDrawItemStruct->itemID ;
lvi.iSubItem = 0;
lvi.pszText = lpBuffer ;
lvi.cchTextMax = sizeof(lpBuffer);
VERIFY(GetItem(&lvi));
LV_COLUMN lvc, lvcprev ;
::ZeroMemory(&lvc, sizeof(lvc));
::ZeroMemory(&lvcprev, sizeof(lvcprev));
lvc.mask = LVCF_WIDTH | LVCF_FMT;
lvcprev.mask = LVCF_WIDTH | LVCF_FMT;
for ( int nCol=0; GetColumn(nCol, &lvc); nCol++)
{
if ( nCol > 0 )
{
// Get Previous Column Width in order to move the next display item
GetColumn(nCol-1, &lvcprev) ;
lpDrawItemStruct->rcItem.left += lvcprev.cx ;
lpDrawItemStruct->rcItem.right += lpDrawItemStruct->rcItem.left ;
}
// Get the text
::ZeroMemory(&lvi, sizeof(lvi));
lvi.iItem = lpDrawItemStruct->itemID;
lvi.mask = LVIF_TEXT | LVIF_PARAM;
lvi.iSubItem = nCol;
lvi.pszText = lpBuffer;
lvi.cchTextMax = sizeof(lpBuffer);
VERIFY(GetItem(&lvi));
CDC* pDC;
pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
if ( lpDrawItemStruct->itemState & ODS_SELECTED )
{
pDC->FillSolidRect(&lpDrawItemStruct->rcItem, GetSysColor(COLOR_HIGHLIGHT)) ;
pDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT)) ;
}
else
{
pDC->FillSolidRect(&lpDrawItemStruct->rcItem, GetSysColor(COLOR_WINDOW)) ;
pDC->SetTextColor(GetSysColor(COLOR_WINDOWTEXT)) ;
}
pDC->SelectObject(GetStockObject(DEFAULT_GUI_FONT));
UINT uFormat = DT_LEFT ;
::DrawText(lpDrawItemStruct->hDC, lpBuffer, strlen(lpBuffer),
&lpDrawItemStruct->rcItem, uFormat) ;
pDC->SelectStockObject(SYSTEM_FONT) ;
}
}