CheckBoxListCtrl.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // CheckBoxListCtrl.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CheckBoxListCtrl.h"
  5. #include "LYFZIPManage.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CCheckBoxListCtrl
  13. extern CFont g_listctrlfont;
  14. CCheckBoxListCtrl::CCheckBoxListCtrl()
  15. {
  16. }
  17. CCheckBoxListCtrl::~CCheckBoxListCtrl()
  18. {
  19. for(int i=0; i<m_pCheckArray.GetSize (); i++)
  20. {
  21. CButton *pBtn=m_pCheckArray.ElementAt (i);
  22. pBtn->DestroyWindow ();
  23. delete pBtn;
  24. }
  25. }
  26. BEGIN_MESSAGE_MAP(CCheckBoxListCtrl, CListCtrl)
  27. //{{AFX_MSG_MAP(CCheckBoxListCtrl)
  28. ON_WM_TIMER()
  29. ON_WM_DESTROY()
  30. //}}AFX_MSG_MAP
  31. END_MESSAGE_MAP()
  32. void CCheckBoxListCtrl::InitStyle()
  33. {
  34. SetFont (&g_listctrlfont);
  35. SetExtendedStyle(LVS_EX_FLATSB|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP);
  36. SetTimer(1, 1000, NULL);
  37. }
  38. void CCheckBoxListCtrl::AddCheckBox(int iItem, int pos, BOOL bCheck)
  39. {
  40. CButton *pBtn=new CButton;
  41. CRect rc;
  42. GetSubItemRect( iItem, pos, LVIR_BOUNDS, rc);
  43. rc.bottom =rc.top +13;
  44. RectFitDes(1,1,rc);
  45. pBtn->Create("",WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX|BS_FLAT, rc,this,123);
  46. pBtn->SetCheck (bCheck);
  47. m_pCheckArray.Add (pBtn);
  48. }
  49. BOOL CCheckBoxListCtrl::GetItemCheck(int iItem, int pos)
  50. {
  51. if(iItem*2+pos>=m_pCheckArray.GetSize ())return 0;
  52. CButton *pBtn=m_pCheckArray.ElementAt (iItem*2+pos);
  53. return pBtn->GetCheck ();
  54. }
  55. void CCheckBoxListCtrl::CheckAll(BOOL bCheck)
  56. {
  57. for(int i=0; i<m_pCheckArray.GetSize (); i++)
  58. {
  59. CButton *pBtn=m_pCheckArray.ElementAt (i);
  60. pBtn->SetCheck (bCheck);
  61. }
  62. }
  63. void CCheckBoxListCtrl::OnTimer(UINT nIDEvent)
  64. {
  65. // TODO: Add your message handler code here and/or call default
  66. if(m_pCheckArray.GetSize ()==0)return;
  67. for(int i=0; i<this->GetItemCount (); i++)
  68. {
  69. CRect rc;
  70. GetSubItemRect( i, 2, LVIR_BOUNDS, rc);
  71. rc.bottom =rc.top +13;
  72. RectFitDes(1,1,rc);
  73. CButton *pBtn=m_pCheckArray.ElementAt (i*2);
  74. pBtn->MoveWindow (rc);
  75. pBtn->Invalidate ();
  76. GetSubItemRect( i, 3, LVIR_BOUNDS, rc);
  77. rc.bottom =rc.top +13;
  78. RectFitDes(1,1,rc);
  79. pBtn=m_pCheckArray.ElementAt (i*2+1);
  80. pBtn->MoveWindow (rc);
  81. pBtn->Invalidate ();
  82. }
  83. }
  84. void CCheckBoxListCtrl::OnDestroy()
  85. {
  86. CListCtrl::OnDestroy();
  87. // TODO: Add your message handler code here
  88. KillTimer(1);
  89. }