CListCtrl :
DWORD dwStyle = m_ListCtrl.GetExtendedStyle();
dwStyle |= LVS_EX_FULLROWSELECT; // ( report listctrl)
dwStyle |= LVS_EX_GRIDLINES; // ( report listctrl)
dwStyle |= LVS_EX_SUBITEMIMAGES; //
dwStyle |= LVS_EX_ONECLICKACTIVATE; //
m_ListCtrl.SetExtendedStyle(dwStyle); //
CListCtrl item
LVITEM lvItem;
memset(&lvItem, 0, sizeof(LVITEM));
lvItem.iItem = nI;
lvItem.iSubItem = 2;
lvItem.mask = LVIF_IMAGE;
lvItem.iImage = 1; //
m_ListCtrl.SetItem(&lvItem);
CListCtrl item
CListCtrl OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult) , , item 。
//*********************************************************************************
//** :OnNMCustomdraw
//** :listctrl ,
//** :
//** :
//** :chenbo
//** :2008-10-23
//** :
//** :
//** :1.0
//*********************************************************************************
void CListCtrlEx::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
*pResult = CDRF_DODEFAULT;
NMLVCUSTOMDRAW * lplvdr=(NMLVCUSTOMDRAW*)pNMHDR;
NMCUSTOMDRAW &nmcd = lplvdr->nmcd;
switch(lplvdr->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT :
{
COLORREF ItemColor;
if( MapItemColor.Lookup(nmcd.dwItemSpec, ItemColor))
{
lplvdr->clrText = ItemColor;
*pResult = CDRF_DODEFAULT;
}
}
break;
}
}
//*********************************************************************************
//** :SetItemColor
//** : item
//** :
//** :
//** :chenbo
//** :2008-10-23
//** :
//** :
//** :1.0
//*********************************************************************************
void CListCtrlEx::SetItemColor(DWORD iItem, COLORREF color)
{
ASSERT(iItem >= 0);
MapItemColor.SetAt(iItem, color);
this->RedrawItems(iItem, iItem);
UpdateWindow();
}
ClistCtrl
BOOL CGeoCheckHelp::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_LBUTTONDOWN)
{
// Integer ( ), , ,
// , 0 1( CapsLock, NumLock,ScrollLock); (0000000000000001)2,
// , 15 1; (1000000000000000)2, , 0。 (0000000000000001)2,
// , 15 1; (1000000000000000)2, , 0
if (!(GetKeyState(VK_CONTROL)&0x8000) && !(GetKeyState(VK_SHIFT)&0x8000) )
{
if(IsMuitSelCur())
{
LVHITTESTINFO hitTest;
UINT uFlags = 0 ;
CPoint point;
point.SetPoint(pMsg->pt.x,pMsg->pt.y);
m_ListCtrl.ScreenToClient(&point);
hitTest.pt = point;
hitTest.flags = uFlags;
m_ListCtrl.HitTest(&hitTest);
int nRow = m_ListCtrl.HitTest(point);
CString strTem = m_ListCtrl.GetItemText(nRow,2);
CString strTep = m_ListCtrl.GetItemText(nRow,8);
LVHITTESTINFO sublvHit;
sublvHit.pt = point;
int nColumn = m_ListCtrl.SubItemHitTest(&sublvHit);
if(sublvHit.iSubItem == 2)
{
POSITION pos = m_ListCtrl.GetFirstSelectedItemPosition();
if (pos == NULL)
return TRUE;
else
{
do
{
int nItem = m_ListCtrl.GetNextSelectedItem(pos);
{
int nCheckID = vec1[nItem];
CString strCheckID;
strCheckID.Format(_T("%d"),nCheckID);
if ( strTem== _T("√") )
{
SetTableData(strCheckID,0);
m_ListCtrl.SetRedraw(false);
m_ListCtrl.SetItemText(nItem,2,_T("□"));
m_ListCtrl.SetRedraw(true);
}else
{
SetTableData(strCheckID,-1);
m_ListCtrl.SetRedraw(false);
m_ListCtrl.SetItemText(nItem,2,_T("√"));
m_ListCtrl.SetRedraw(true);
}
}
! , , !
--------------------------------------------------------------------------------
1. CListCtrl
LVS_ICON: item
LVS_SMALLICON: item
LVS_LIST: item
LVS_REPORT: item
windows ,“ ” “ , , , ”
LONG lStyle;
lStyle=GetWindowLong(m_ListCtrl.m_hWnd, GWL_STYLE); // style
lStyle &= ~LVS_TYPEMASK; //
lStyle |= LVS_REPORT; // style
SetWindowLong(m_ListCtrl.m_hWnd, GWL_STYLE, lStyle); // style
--------------------------------------------------------------------------------
2.
DWORD dwStyle = m_ListCtrl.GetExtendedStyle(); //
dwStyle |= LVS_EX_FULLROWSELECT; // (report )
dwStyle |= LVS_EX_GRIDLINES; // (report )
dwStyle |= LVS_EX_CHECKBOXES; //item checkbox
m_ListCtrl.SetExtendedStyle(dwStyle); //
--------------------------------------------------------------------------------
3.
m_ListCtrl.InsertColumn(0," ",LVCFMT_LEFT,50); //
m_ListCtrl.InsertColumn(1," ",LVCFMT_LEFT,50);
// :
int nRow=m_ListCtrl.InsertItem(0, "VC++"); //
m_ListCtrl.SetItemText(nRow,1,"Visual C++ 6.0"); //
//LVITEM :
LVITEM item={0};
item.iItem=0; //
item.mask=LVIF_TEXT; /*LVIF_IMAGE */;
item.cchTextMax=15;//
item.pszText="Visual C++ 6.0";
int nRow=m_ListCtrl.InsertItem(&item);
m_ListCtrl.SetItemText(nRow,1,"Visual C++ 6.0");
--------------------------------------------------------------------------------
4. Item
style Show selection always,
LVS_SHOWSELALWAYS
--------------------------------------------------------------------------------
5. Item
int nIndex = 0;
//
m_ListCtrl.SetItemState(nIndex,LVIS_SELECTED|
LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
//
m_ListCtrl.SetItemState(nIndex,0,LVIS_SELECTED|LVIS_FOCUSED);
--------------------------------------------------------------------------------
6. CListCtrl checkbox
CString str;
for(int i=0; i<m_ListCtrl.GetItemCount(); i++)
{
if(m_ListCtrl.GetItemState(i, LVIS_SELECTED)==
LVIS_SELECTED || m_ListCtrl.GetCheck(i))
{
str.Format(_T(" %d checkbox "), i);
AfxMessageBox(str);
}
}
--------------------------------------------------------------------------------
7. CListCtrl
// :
CString str;
for(int i=0; i<m_ListCtrl.GetItemCount(); i++)
{
if(m_ListCtrl.GetItemState(i, LVIS_SELECTED) == LVIS_SELECTED )
{
str.Format(_T(" %d "), i);
AfxMessageBox(str);
}
}
// :
POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
if(pos==NULL)
TRACE0("No items were selected!
");
else
{
while(pos)
{
int nItem=m_ListCtrl.GetNextSelectedItem(pos);
TRACE1("Item %d was selected!
", nItem);
//
}
}
--------------------------------------------------------------------------------
8. item
TCHAR szBuf[1024];
LVITEM lvi;
lvi.iItem = nItemIndex;
lvi.iSubItem = 0;
lvi.mask = LVIF_TEXT;
lvi.pszText = szBuf;
lvi.cchTextMax = 1024;
m_ListCtrl.GetItem(&lvi);
item , msdn
Q173242: Use Masks to Set/Get Item States in CListCtrl
http://support.microsoft.com/kb/173242/en-us
--------------------------------------------------------------------------------
9. CListCtrl header
LVCOLUMN lvcol;
char str[256];
int nColNum;
CString strColumnName[3];// 3
nColNum = 0;
lvcol.mask = LVCF_TEXT;
lvcol.pszText = str;
lvcol.cchTextMax = 256;
while(m_list.GetColumn(nColNum, &lvcol))
{
strColumnName[nColNum] = lvcol.pszText;
nColNum++;
}
--------------------------------------------------------------------------------
10. CListCtrl ,
m_ListCtrl.EnsureVisible(i, FALSE);
--------------------------------------------------------------------------------
11. CListCtrl
int nHeadNum=m_ListCtrl.GetHeaderCtrl()->GetItemCount();
--------------------------------------------------------------------------------
12.
:
while(m_ListCtrl.DeleteColumn(0))
// , 。
:
int nColumns = 3; //
for(int i=nColumns-1; i>=0; i--)
m_ListCtrl.DeleteColumn(i);
--------------------------------------------------------------------------------
13. CListCtrl
listctrl NM_CLICK
void CMyDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// :
DWORD dwPos=GetMessagePos();
CPoint point( LOWORD(dwPos), HIWORD(dwPos));
m_ListCtrl.ScreenToClient(&point);
LVHITTESTINFO lvinfo;
lvinfo.pt=point;
lvinfo.flags=LVHT_ABOVE;
int nItem=m_ListCtrl.SubItemHitTest(&lvinfo);
if(nItem!=-1)
{
CString strtemp;
strtemp.Format(" %d %d ",
lvinfo.iItem, lvinfo.iSubItem);
AfxMessageBox(strtemp);
}
// :
NM_LISTVIEW* pNMListView=(NM_LISTVIEW*)pNMHDR;
if(pNMListView->iItem!=-1)
{
CString strtemp;
strtemp.Format(" %d %d ",
pNMListView->iItem, pNMListView->iSubItem);
AfxMessageBox(strtemp);
}
*pResult = 0;
}
--------------------------------------------------------------------------------
14. CListCtrl checkbox
listctrl NM_CLICK
void CMyDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
DWORD dwPos=GetMessagePos();
CPoint point(LOWORD(dwPos), HIWORD(dwPos));
m_ListCtrl.ScreenToClient(&point);
LVHITTESTINFO lvinfo;
lvinfo.pt=point;
lvinfo.flags=LVHT_ABOVE;
UINT nFlag;
int nItem=m_ListCtrl.HitTest(point, &nFlag);
// checkbox
if(nFlag==LVHT_ONITEMSTATEICON)
{
AfxMessageBox(" listctrl checkbox ");
}
*pResult = 0;
}
--------------------------------------------------------------------------------
15. CListCtrl item
CListCtrl NM_RCLICK
void CMyDlg::OnRclickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView=(NM_LISTVIEW*)pNMHDR;
if(pNMListView->iItem!=-1)
{
DWORD dwPos = GetMessagePos();
CPoint point( LOWORD(dwPos), HIWORD(dwPos) );
CMenu menu;
VERIFY( menu.LoadMenu( IDR_MENU1 ) );
CMenu* popup = menu.GetSubMenu(0);
ASSERT( popup != NULL );
popup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,
point.x, point.y, this );
}
*pResult = 0;
}
--------------------------------------------------------------------------------
16. CListCtrl ,
m_ListCtrl.SetRedraw(FALSE);
//
m_ListCtrl.SetRedraw(TRUE);
m_ListCtrl.Invalidate();
m_ListCtrl.UpdateWindow();
//
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cwnd.3a3a.setredraw.asp
CSDN , :http://blog.csdn.net/sghgcn/archive/2009/03/05/3958219.aspx
}
while(pos);
}
return TRUE;
}
if (sublvHit.iSubItem == 8)
{
POSITION pos = m_ListCtrl.GetFirstSelectedItemPosition();
if (pos == NULL)
return TRUE;
else
{
do
{
int nItem = m_ListCtrl.GetNextSelectedItem(pos);
{
int nCheckID = vec1[nItem];
CString strCheckID;
strCheckID.Format(_T("%d"),nCheckID);
if ( strTep== _T("√") )
{
SetMoreTableData(strCheckID,0);
m_ListCtrl.SetRedraw(false);
m_ListCtrl.SetItemText(nItem,8,_T("□"));
m_ListCtrl.SetRedraw(true);
}else
{
SetMoreTableData(strCheckID,-1);
m_ListCtrl.SetRedraw(false);
m_ListCtrl.SetItemText(nItem,8,_T("√"));
m_ListCtrl.SetRedraw(true);
}
}
}
while(pos);
}
return TRUE;
}
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}