ButtonGroup.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #pragma once
  2. #include "afxwin.h"
  3. #include <vector>
  4. #include "MyButton.h"
  5. using namespace std;
  6. class CMyButton;
  7. class CGoodsDlg;
  8. class CButtonGroup:public CWnd
  9. {
  10. DECLARE_DYNAMIC(CButtonGroup);
  11. public:
  12. CButtonGroup(void);
  13. public:
  14. ~CButtonGroup(void);
  15. public:
  16. CGoodsDlg* pParent;
  17. vector<CMyButton*> pButtons;
  18. UINT xAlign;
  19. UINT yAlign;
  20. UINT width;
  21. UINT height;
  22. UINT row;
  23. UINT column;
  24. UINT maxRow;
  25. UINT maxColumn;
  26. UINT x;
  27. UINT y;
  28. UINT groupIndex;
  29. UINT type;
  30. public:
  31. afx_msg void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
  32. void addButton(CString name, UINT nID);
  33. void changeButtonInfo(UINT index, CString name, CString otherInfo);
  34. CRect getCurRect(UINT row, UINT column)
  35. {
  36. CRect rt;
  37. rt.left = x + column * width + column * xAlign;
  38. rt.right = x + (column + 1) * width + column * xAlign;
  39. rt.top = y + row * height + row * xAlign;
  40. rt.bottom = y + (row + 1) * height + row * yAlign;
  41. return rt;
  42. }
  43. CRect getCurRect(UINT index)
  44. {
  45. CRect rt;
  46. UINT row = index / maxColumn;
  47. UINT column = index % maxColumn;
  48. rt.left = x + column * width + column * xAlign;
  49. rt.right = x + (column + 1) * width + column * xAlign;
  50. rt.top = y + row * height + row * xAlign;
  51. rt.bottom = y + (row + 1) * height + row * yAlign;
  52. return rt;
  53. }
  54. UINT getBottom()
  55. {
  56. return y + row * height + (row - 1) * yAlign;
  57. }
  58. UINT getRow(UINT index)
  59. {
  60. return index / maxColumn;
  61. }
  62. UINT getColumn(UINT index)
  63. {
  64. return index % maxColumn;
  65. }
  66. void handleClick(UINT index);
  67. };