CheckBoxListCtrl.cpp 2.3 KB

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