// CheckBoxListCtrl.cpp : implementation file // #include "stdafx.h" #include "CheckBoxListCtrl.h" #include "LYFZIPManage.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CCheckBoxListCtrl extern CFont g_listctrlfont; CCheckBoxListCtrl::CCheckBoxListCtrl() { } CCheckBoxListCtrl::~CCheckBoxListCtrl() { for(int i=0; iDestroyWindow (); delete pBtn; } } BEGIN_MESSAGE_MAP(CCheckBoxListCtrl, CListCtrl) //{{AFX_MSG_MAP(CCheckBoxListCtrl) ON_WM_TIMER() ON_WM_DESTROY() //}}AFX_MSG_MAP END_MESSAGE_MAP() void CCheckBoxListCtrl::InitStyle() { SetFont (&g_listctrlfont); SetExtendedStyle(LVS_EX_FLATSB|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP); SetTimer(1, 1000, NULL); } void CCheckBoxListCtrl::AddCheckBox(int iItem, int pos, BOOL bCheck) { CButton *pBtn=new CButton; CRect rc; GetSubItemRect( iItem, pos, LVIR_BOUNDS, rc); rc.bottom =rc.top +13; RectFitDes(1,1,rc); pBtn->Create("",WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX|BS_FLAT, rc,this,123); pBtn->SetCheck (bCheck); m_pCheckArray.Add (pBtn); } BOOL CCheckBoxListCtrl::GetItemCheck(int iItem, int pos) { if(iItem*2+pos>=m_pCheckArray.GetSize ())return 0; CButton *pBtn=m_pCheckArray.ElementAt (iItem*2+pos); return pBtn->GetCheck (); } void CCheckBoxListCtrl::CheckAll(BOOL bCheck) { for(int i=0; iSetCheck (bCheck); } } void CCheckBoxListCtrl::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default if(m_pCheckArray.GetSize ()==0)return; for(int i=0; iGetItemCount (); i++) { CRect rc; GetSubItemRect( i, 2, LVIR_BOUNDS, rc); rc.bottom =rc.top +13; RectFitDes(1,1,rc); CButton *pBtn=m_pCheckArray.ElementAt (i*2); pBtn->MoveWindow (rc); pBtn->Invalidate (); GetSubItemRect( i, 3, LVIR_BOUNDS, rc); rc.bottom =rc.top +13; RectFitDes(1,1,rc); pBtn=m_pCheckArray.ElementAt (i*2+1); pBtn->MoveWindow (rc); pBtn->Invalidate (); } } void CCheckBoxListCtrl::OnDestroy() { CListCtrl::OnDestroy(); // TODO: Add your message handler code here KillTimer(1); }