GuiGridLayout.cpp
上传用户:wlkj888
上传日期:2022-08-01
资源大小:806k
文件大小:3k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // GuiGridLayout.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "GuiLib.h"
  5. #include "GuiGridLayout.h"
  6. #include "GuiDrawLayer.h"
  7. // CGuiGridLayout
  8. CControl::CControl(int nRow, int nCol, CWnd* pWnd)
  9. {
  10. ASSERT_VALID(pWnd);
  11. m_nRow=nRow;
  12. m_nCol=nCol;
  13. m_pWnd=pWnd;
  14. }
  15. ~CControl::CControl()
  16. {
  17. }
  18. int CControl::GetRows()
  19. {
  20. return m_nRow;
  21. }
  22. int CControl::GetCols()
  23. {
  24. return m_nCol;
  25. }
  26. CWnd* CControl::GetCWnd(int nRows,int nCol)
  27. {
  28. if (nRows==m_nRow && nCol == m_nCol)
  29. return m_pWnd;
  30. }
  31. IMPLEMENT_DYNAMIC(CGuiGridLayout, CWnd)
  32. CGuiGridLayout::CGuiGridLayout()
  33. {
  34. m_NumRows=0;
  35. m_NumCols=0;
  36. m_nInsets=1;
  37. m_GridBorder=GRIDNORMAL;
  38. m_pArray.RemoveAll();
  39. m_clr=GuiDrawLayer::GetRGBColorFace();
  40. m_NumRowsAc=0;
  41. m_NumColsAc=0;
  42. nNumItems=0;
  43. }
  44. CGuiGridLayout::~CGuiGridLayout()
  45. {
  46. }
  47. BEGIN_MESSAGE_MAP(CGuiGridLayout, CWnd)
  48. ON_WM_SIZE()
  49. ON_WM_PAINT()
  50. ON_WM_DESTROY()
  51. END_MESSAGE_MAP()
  52. // CGuiGridLayout message handlers
  53. BOOL CGuiGridLayout::Create(CWnd* pParentWnd,int nNumRows, int nNumCols)
  54. {
  55. // TODO: Add your specialized code here and/or call the base class
  56. m_NumRows=nNumRows;
  57. m_NumCols=nNumCols;
  58. return CWnd::Create(NULL,NULL,WS_VISIBLE|WS_CHILD,CRect(0,0,0,0), pParentWnd, 0x9999);
  59. }
  60. void CGuiGridLayout::OnSize(UINT nType, int cx, int cy)
  61. {
  62. CWnd::OnSize(nType, cx, cy);
  63. // TODO: Add your message handler code here
  64. }
  65. void CGuiGridLayout::SetBorders(GRIDBORDER GridBorder)
  66. {
  67. m_GridBorder=GridBorder;
  68. }
  69. void CGuiGridLayout::SetColors(COLORREF m_clrColor)
  70. {
  71. m_clr=m_clrColor;
  72. }
  73. void CGuiGridLayout::SetInsets(int nInsets)
  74. {
  75. m_nInsets=nInsets;
  76. }
  77. void CGuiGridLayout::Add(CWnd* pWnd)
  78. {
  79. m_NumColsAc++;
  80. if (m_NumColsAc >= nCol)
  81. if (m_NumRowsAc+1 < nRow)
  82. {
  83. m_NumColsAc=0;
  84. m_NumRowsAc++;
  85. }else
  86. {
  87. return ;
  88. }
  89. if (m_NumRowsAc < nRow)
  90. if (m_NumColsAc < nCol)
  91. {
  92. m_pArray.SetAtGrow(nNumItems, new CControl(m_NumRowsAc, m_NumColsAc,pWnd);
  93. }
  94. RecalLayout();
  95. }
  96. void CGuiGridLayout::Add(int nRow,int nCol, CWnd* pWnd)
  97. {
  98. ASSERT_VALID(pWnd);
  99. if (nRow> m_NumRows || nCol >m_NumCols)
  100. return ;
  101. m_NumRowsAc=nRow;
  102. m_NumColsAc=nCol;
  103. m_pArray.SetAtGrow(nNumItems, new CControl(nRow, nCol,pWnd);
  104. RecalLayout();
  105. }
  106. void CGuiGridLayout::RecalLayout()
  107. {
  108. }
  109. void CGuiGridLayout::OnPaint()
  110. {
  111. CPaintDC dc(this); // device context for painting
  112. // TODO: Add your message handler code here
  113. // Do not call CWnd::OnPaint() for painting messages
  114. }
  115. void CGuiGridLayout::OnDestroy()
  116. {
  117. for( int i=0; i<m_NumRows+m_NumCols; i++ )
  118.     {
  119.     CControl *pArr = (CControl*)m_pArray.GetAt(i);
  120.     if( pArr )
  121.         delete pArr;
  122.     }
  123. CWnd::OnDestroy();
  124. // TODO: Add your message handler code here
  125. }