CListCtrl 添加Colum 添加Item 修改Colum 修改风格
////////添加Colum
void CLEDScreenDecDlg1::AddListColumn()
{
CDC *pDC = GetDC();
CStringArray strArray;
strArray.Add(_T("发送卡号")); //0
strArray.Add(_T("端口号")); //1
strArray.Add(_T("接收卡号")); //2
strArray.Add(_T("接收卡温度")); //3
strArray.Add(_T("湿度")); //4
strArray.Add(_T("第二温度")); //5
strArray.Add(_T("收包数")); //6
strArray.Add(_T("丢包数")); //7
strArray.Add(_T("运行时间")); //8
strArray.Add(_T("SDRAM")); //9
strArray.Add(_T("OUTPUT PIN CHECK")); //10
strArray.Add(_T("接收卡电压")); //12
strArray.Add(_T("第一路外部电压")); //13
strArray.Add(_T("第二路外部电压")); //14
strArray.Add(_T("烟感 ")); //15
strArray.Add(_T("继电器状态")); //16
strArray.Add(_T("SPI FLASH")); //17
strArray.Add(_T("排线检测")); //18
LVCOLUMN lvColumn;
lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_ORDER /*| LVCF_MINWIDTH | LVCF_DEFAULTWIDTH*/;
lvColumn.fmt = LVCFMT_CENTER;
lvColumn.cchTextMax = MAX_PATH;
for (int i = 0; i< strArray.GetCount(); ++i)
{
lvColumn.iOrder = i;//显示时的偏移量
lvColumn.pszText = strArray[i].GetBuffer();
lvColumn.cx = pDC->GetTextExtent(strArray[i]).cx < 50 ?50:pDC->GetTextExtent(strArray[i]).cx;
m_listCtrl.InsertColumn(i, &lvColumn);
}
m_listCtrl.Scroll(CSize(0,0));
ReleaseDC(pDC);
}
////////////// 添加Item
void CLEDScreenDecDlg1::AddListItem()
{
m_listCtrl.DeleteAllItems();
LVITEM lvItem;
memset(&lvItem,0,sizeof(LVITEM));
lvItem.mask = LVIF_TEXT | LVIF_IMAGE;
lvItem.cchTextMax = MAX_PATH;
CString strText = _T("");
int count = g_screenStateInfoArray.GetCount();
ScreenStateInfo *pScreenstateinfo = NULL;
for (int i = 0; i< count; ++i)
{
pScreenstateinfo = g_screenStateInfoArray.GetAt(i);
m_listCtrl.InsertItem(i, _T(""));//Insert
lvItem.iItem = i;
CStringArray strArray;
strText.Format(_T("%d"), pScreenstateinfo->sendCardIndex);
strArray.Add(strText);
strText.Format(_T("%d"), pScreenstateinfo->port);
strArray.Add(strText);
strText.Format(_T("%d"), *((short *)pScreenstateinfo->cardIndex));
strArray.Add(strText);
strText.Format(_T("%d"), *((short *)pScreenstateinfo->temperature));
strArray.Add(strText);
strText.Format(_T("%d"), *((short *)pScreenstateinfo->humidity));
strArray.Add(strText);
strText.Format(_T("%d"), *((short *)pScreenstateinfo->reserved));
strArray.Add(strText);
strText.Format(_T("%d"), pScreenstateinfo->GetTotalPackCount());
strArray.Add(strText);
strText.Format(_T("%d"), pScreenstateinfo->GetErrorPackCount());
strArray.Add(strText);
strText.Format(_T("%d"), pScreenstateinfo->GetTotalTime());
strArray.Add(strText);
strText.Format(_T("%d"), pScreenstateinfo->sdramCheck);//特定
strArray.Add(strText);
strText.Format(_T("%d"), pScreenstateinfo->outPinCheck);//特定
strArray.Add(strText);
strText.Format(_T("%d"), pScreenstateinfo->rdvVoltage);
strArray.Add(strText);
strText.Format(_T("%d"), pScreenstateinfo->outerVoltage[0]);
strArray.Add(strText);
strText.Format(_T("%d"), pScreenstateinfo->outerVoltage[1]);
strArray.Add(strText);
strText.Format(_T("%d"), pScreenstateinfo->smoke);
strArray.Add(strText);
strText.Format(_T("%d"), pScreenstateinfo->relayStatus);
strArray.Add(strText);
strText.Format(_T("%d"), pScreenstateinfo->spiFlashSize);
strArray.Add(strText);
strText.Format(_T("%d"), 0);
strArray.Add(strText);
for (int j = 0; j< strArray.GetCount(); ++j)
{
lvItem.iImage = j%3;
lvItem.iSubItem = j;
lvItem.pszText = strArray[j].GetBuffer();
m_listCtrl.SetItem(&lvItem);//Set
strArray[i].ReleaseBuffer();
}
}
}
修改Colum
void CLEDScreenDecDlg0::ShowListColumn()
{
CDC *pDC = GetDC();
CDWordArray strArray;
strArray.Add(m_bSendCardIndex); //0发送卡索引
strArray.Add(m_bPort); //1
strArray.Add(m_bRcvIndex); //2
strArray.Add(m_bRcvTemp); //3
strArray.Add(m_bHumidity); //4
strArray.Add(m_bSecondTemp); //5
strArray.Add(m_bTotalPackage); //6
strArray.Add(m_bErrorCRCPackage); //7
strArray.Add(m_bCardRuntime); //8
strArray.Add(m_bSDRAM); //9
strArray.Add(m_bOutPutPinCheck); //10
strArray.Add(m_bRcvVoltage); //11
strArray.Add(m_bFirstExVoltage); //12
strArray.Add(m_bSecondExVoltage); //13
strArray.Add(m_bSmokeDec); //14
strArray.Add(m_bRelayState); //15
strArray.Add(m_bSPIFLASH); //16
strArray.Add(m_bLineDec); //17
strArray.Add(m_bBatteryVoltage); //18
TCHAR *pBuf = new TCHAR[MAX_PATH];
ZeroMemory(pBuf, MAX_PATH * sizeof(TCHAR));
LVCOLUMN lvColumn;
lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_ORDER /*| LVCF_MINWIDTH | LVCF_DEFAULTWIDTH*/;
lvColumn.cchTextMax = MAX_PATH;
lvColumn.pszText = pBuf;
for (int i = 0; i< strArray.GetCount(); ++i)
{
m_listCtrl.GetColumn(i, &lvColumn);
if (strArray.GetAt(i))
{
lvColumn.cx = pDC->GetTextExtent(lvColumn.pszText, _tcsclen(lvColumn.pszText)).cx < 50 ?50:pDC->GetTextExtent(lvColumn.pszText, _tcsclen(lvColumn.pszText)).cx;
}
else
lvColumn.cx = 0;
m_listCtrl.SetColumn(i, &lvColumn);
}
delete [] pBuf;
ReleaseDC(pDC);
}
//修改风格
DWORD dwStyle = m_listCtrl.GetExtendedStyle();
dwStyle |= LVS_EX_FULLROWSELECT | LVS_SHOWSELALWAYS | LVS_EX_HEADERDRAGDROP | LVS_EX_SUBITEMIMAGES | LVS_SMALLICON;
m_listCtrl.SetExtendedStyle(dwStyle);

浙公网安备 33010602011771号