TabCtrlEx.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #include "stdafx.h"
  2. #include "resource.h"
  3. #include "TabCtrlEx.h"
  4. #include "TabOne.h"
  5. #include "TabTwo.h"
  6. #include "TabThree.h"
  7. #include "TabFour.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. CTabCtrlEx::CTabCtrlEx()
  14. {
  15. m_tabPages[0]=new CTabOne;
  16. m_tabPages[1]=new CTabTwo;
  17. m_tabPages[2]=new CTabThree;
  18. m_tabPages[3]=new CTabFour;
  19. m_nNumberOfPages = 4;
  20. SetBkColor(RGB(192, 192, 192));
  21. SetTextColor(RGB(0, 0, 0));
  22. }
  23. CTabCtrlEx::~CTabCtrlEx()
  24. {
  25. for(int nCount=0; nCount < m_nNumberOfPages; nCount++)
  26. {
  27. delete m_tabPages[nCount];
  28. }
  29. }
  30. void CTabCtrlEx::Init()
  31. {
  32. InsertItem(0, "Service");
  33. InsertItem(1, "Dag");
  34. InsertItem(2, "Details");
  35. InsertItem(3, "Connections");
  36. m_tabCurrent=0;
  37. m_tabPages[0]->Create(IDD_TAB_ONE, this);
  38. m_tabPages[1]->Create(IDD_TAB_TWO, this);
  39. m_tabPages[2]->Create(IDD_TAB_THREE, this);
  40. m_tabPages[3]->Create(IDD_FAB_FOUR, this);
  41. m_tabPages[0]->ShowWindow(SW_SHOW);
  42. m_tabPages[1]->ShowWindow(SW_HIDE);
  43. m_tabPages[2]->ShowWindow(SW_HIDE);
  44. m_tabPages[3]->ShowWindow(SW_HIDE);
  45. SetRectangle();
  46. }
  47. void CTabCtrlEx::SetRectangle()
  48. {
  49. CRect tabRect, itemRect;
  50. int nX, nY, nXc, nYc;
  51. GetClientRect(&tabRect);
  52. GetItemRect(0, &itemRect);
  53. nX=itemRect.left;
  54. nY=itemRect.bottom+1;
  55. nXc=tabRect.right-itemRect.left-1;
  56. nYc=tabRect.bottom-nY-1;
  57. m_tabPages[0]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);
  58. for(int nCount=1; nCount < m_nNumberOfPages; nCount++)
  59. {
  60. m_tabPages[nCount]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
  61. }
  62. }
  63. BEGIN_MESSAGE_MAP(CTabCtrlEx, CTabCtrl)
  64. //{{AFX_MSG_MAP(CTabCtrlEx)
  65. ON_WM_LBUTTONDOWN()
  66. ON_WM_SIZE()
  67. //}}AFX_MSG_MAP
  68. END_MESSAGE_MAP()
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CTabCtrlEx message handlers
  71. void CTabCtrlEx::OnLButtonDown(UINT nFlags, CPoint point)
  72. {
  73. CTabCtrl::OnLButtonDown(nFlags, point);
  74. if(m_tabCurrent != GetCurFocus())
  75. {
  76. m_tabPages[m_tabCurrent]->ShowWindow(SW_HIDE);
  77. m_tabCurrent=GetCurFocus();
  78. m_tabPages[m_tabCurrent]->ShowWindow(SW_SHOW);
  79. m_tabPages[m_tabCurrent]->SetFocus();
  80. }
  81. }
  82. void CTabCtrlEx::OnSize(UINT nType, int cx, int cy)
  83. {
  84. CTabCtrl::OnSize(nType, cx, cy);
  85. CRect rect;
  86. RECT rcTab;
  87. GetWindowRect(rect);
  88. ScreenToClient(rect);
  89. GetItemRect(0, &rcTab);
  90. int dx = 2 * GetSystemMetrics(SM_CXEDGE);
  91. int dy = 2 * GetSystemMetrics(SM_CYEDGE);
  92. for(int nCount=0; nCount < m_nNumberOfPages; nCount++)
  93. {
  94. m_tabPages[nCount]->SetWindowPos(NULL, 0, 0, rect.Width() - (2 * dx), rect.Height() - (2 * dy) - (rcTab.bottom - rcTab.top), SWP_NOMOVE | SWP_NOZORDER);;
  95. }
  96. }