-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTabSheet.cpp
123 lines (94 loc) · 2.66 KB
/
TabSheet.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// TabSheet.cpp : implementation file
//
#include "stdafx.h"
#include "APMAlert.h"
#include "TabSheet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTabSheet
CTabSheet::CTabSheet()
{
m_nNumOfPages = 0;
m_nCurrentPage = 0;
}
CTabSheet::~CTabSheet()
{
}
BEGIN_MESSAGE_MAP(CTabSheet, CTabCtrl)
//{{AFX_MSG_MAP(CTabSheet)
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTabSheet message handlers
BOOL CTabSheet::AddPage(LPCTSTR title, CDialog *pDialog, UINT ID)
{
if (MAXPAGE == m_nNumOfPages)
return FALSE;
m_nNumOfPages++;
m_pPages[m_nNumOfPages - 1] = pDialog;
m_IDD[m_nNumOfPages - 1] = ID;
m_Title[m_nNumOfPages - 1] = title;
return TRUE;
}
void CTabSheet::SetRect()
{
CRect tabRect, itemRect;
int nX, nY, nXc, nYc;
GetClientRect(&tabRect);
GetItemRect(0, &itemRect);
nX = itemRect.left;
nY = itemRect.bottom + 1;
nXc = tabRect.right - itemRect.left - 2;
nYc = tabRect.bottom - nY - 2;
m_pPages[0]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);
for (int nCount = 1; nCount < m_nNumOfPages; nCount++)
m_pPages[nCount]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
}
void CTabSheet::Show()
{
int i = 0;
for (i = 0; i < m_nNumOfPages; i++)
{
m_pPages[i]->Create(m_IDD[i], this);
InsertItem(i, m_Title[i]);
}
m_pPages[0]->ShowWindow(SW_SHOW);
for (i = 1; i < m_nNumOfPages; i++)
m_pPages[i]->ShowWindow(SW_HIDE);
SetRect();
}
void CTabSheet::OnLButtonDown(UINT nFlags, CPoint point)
{
CTabCtrl::OnLButtonDown(nFlags, point);
if (m_nCurrentPage != GetCurFocus())
{
m_pPages[m_nCurrentPage]->ShowWindow(SW_HIDE);
m_nCurrentPage = GetCurFocus();
m_pPages[m_nCurrentPage]->ShowWindow(SW_SHOW);
// m_pPages[m_nCurrentPage]->SetFocus();
}
}
int CTabSheet::SetCurSel(int nItem)
{
if (nItem < 0 || nItem >= m_nNumOfPages)
return -1;
int ret = m_nCurrentPage;
if (m_nCurrentPage != nItem)
{
m_pPages[m_nCurrentPage]->ShowWindow(SW_HIDE);
m_nCurrentPage = nItem;
m_pPages[m_nCurrentPage]->ShowWindow(SW_SHOW);
// m_pPages[m_nCurrentPage]->SetFocus();
CTabCtrl::SetCurSel(nItem);
}
return ret;
}
int CTabSheet::GetCurSel()
{
return CTabCtrl::GetCurSel();
}