ListCtr的用法
//自己封装了一个插入List行的函数
int CMyListCtrl::insertRow(int nPos,int nNoOfCols,LPCTSTR pText,...)
{
va_list argList;
va_start(argList, pText);
int nCount,nIndex;
nIndex = m_pList->InsertItem(nPos,pText);
for(nCount=1;nCount<nNoOfCols;nCount++)
{ LPCSTR p = va_arg(argList,LPCSTR);
m_pList->SetItemText(nIndex,nCount,p);
}
va_end(argList);
return nIndex;
}
//初始化ListCtrl风格,表头的函数
void CMyListCtrl::initListCtrl(CWnd *cwnd,int nID)
{
CWnd *m_cwnd =cwnd;
ASSERT(m_cwnd!=NULL);
//CListCtrl *m_pList = mlist;
m_pList = (CListCtrl*)cwnd->GetDlgItem(nID);
DWORD dwStyle= GetWindowLong(m_pList->m_hWnd, GWL_STYLE);
SetWindowLong( m_pList->m_hWnd, GWL_STYLE, dwStyle | LVS_REPORT);
//设置ListCtrl可以整行选择和网格条纹
DWORD styles = m_pList->GetExtendedStyle();
m_pList->SetExtendedStyle(styles|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
m_pList->SetBkColor(RGB(0xFF, 0xFF, 0xE0));
m_pList->SetTextBkColor(RGB(0xFF, 0xFF, 0xE0));
//设置列的题头
m_pList->InsertColumn(1,"序号",LVCFMT_CENTER,40);
m_pList->InsertColumn(2,"产品名称",LVCFMT_CENTER,100);
m_pList->InsertColumn(3,"数量",LVCFMT_CENTER,40);
m_pList->InsertColumn(4,"类型",LVCFMT_CENTER,80);
m_pList->InsertColumn(5,"单价",LVCFMT_CENTER,40);
m_pList->InsertColumn(6,"生产厂家",LVCFMT_CENTER,130);
m_pList->InsertColumn(7,"消费日期",LVCFMT_CENTER,80);
m_pList->InsertColumn(7,"备注",LVCFMT_CENTER,200);
}