ButtonGroup.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "stdafx.h"
  2. #include "ButtonGroup.h"
  3. #include ".\weak_business_ctrl\GoodsDlg.h"
  4. IMPLEMENT_DYNAMIC(CButtonGroup, CWnd)
  5. CButtonGroup::CButtonGroup(void):
  6. maxColumn(6)
  7. ,xAlign(10)
  8. ,yAlign(10)
  9. ,width(176)
  10. ,height(113)
  11. ,x(50)
  12. ,y(50)
  13. ,groupIndex(0)
  14. ,type(0)
  15. {
  16. }
  17. CButtonGroup::~CButtonGroup(void)
  18. {
  19. for (size_t i = 0; i < pButtons.size(); i++)
  20. {
  21. delete(pButtons[i]);
  22. pButtons[i] = NULL;
  23. }
  24. }
  25. void CButtonGroup::addButton(CString name, UINT nID)
  26. {
  27. CMyButton* pBtn = new CMyButton;
  28. pButtons.push_back(pBtn);
  29. CString str;
  30. str.Format("%d",pButtons.size());
  31. pBtn->Create("a",WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,getCurRect(pButtons.size()-1),pParent,nID);
  32. pBtn->name = name;
  33. pBtn->index = pButtons.size() - 1;
  34. pBtn->type = type;
  35. pBtn->pParent = this;
  36. row = pButtons.size() / maxColumn + 1;
  37. if (pButtons.size() % maxColumn == 0)
  38. {
  39. row -= 1;
  40. }
  41. column = maxColumn;
  42. }
  43. void CButtonGroup::changeButtonInfo(UINT index, CString name, CString otherInfo)
  44. {
  45. pButtons[index]->name = name;
  46. pButtons[index]->strInfo = otherInfo;
  47. ::SendMessage(pButtons[index]->m_hWnd,WM_PAINT,(LPARAM)0,(WPARAM)0);
  48. }
  49. void CButtonGroup::handleClick(UINT index)
  50. {
  51. UINT i = groupIndex;
  52. pParent->SendMessage(WM_BUTTONGROUP_MSG,groupIndex,index);
  53. if (type == 1)
  54. {
  55. for (size_t i = 0; i < pButtons.size(); i++)
  56. {
  57. if (i == index)
  58. {
  59. pButtons[i]->changeColor(TRUE);
  60. }
  61. else
  62. {
  63. pButtons[i]->changeColor(FALSE);
  64. }
  65. }
  66. }
  67. }
  68. void CButtonGroup::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
  69. {
  70. }