-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyTabCtrl.cpp
134 lines (112 loc) · 3.41 KB
/
MyTabCtrl.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
124
125
126
127
128
129
130
131
132
133
134
// MyTabCtrl.cpp : implementation file
//
/////////////////////////////////////////////////////
// This class is provided as is and Ben Hill takes no
// responsibility for any loss of any kind in connection
// to this code.
/////////////////////////////////////////////////////
// Is is meant purely as a educational tool and may
// contain bugs.
/////////////////////////////////////////////////////
// ben@shido.fsnet.co.uk
// http://www.shido.fsnet.co.uk
/////////////////////////////////////////////////////
// Thanks to a mystery poster in the C++ forum on
// www.codeguru.com I can't find your name to say thanks
// for your Control drawing code. If you are that person
// thank you very much. I have been able to use some of
// you ideas to produce this sample application.
/////////////////////////////////////////////////////
#include "stdafx.h"
//#include "MyTabExample.h"
#include "OziGen.h"
#include "MyTabCtrl.h"
#include "TabTrack.h"
#include "TabGrid.h"
#include "TabMap.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyTabCtrl
CMyTabCtrl::CMyTabCtrl()
{
m_tabPages[0]=new CTabTrack;
m_tabPages[1]=new CTabGrid;
m_tabPages[2]=new CTabMap;
m_nNumberOfPages=3;
}
CMyTabCtrl::~CMyTabCtrl()
{
for(int nCount=0; nCount < m_nNumberOfPages; nCount++){
delete m_tabPages[nCount];
}
}
void CMyTabCtrl::Init()
{
// m_tabCurrent=0;
m_tabCurrent = AfxGetApp()->GetProfileInt("Main", "CurrentTab", 0);
m_tabPages[0]->Create(IDD_TAB_TRACK, this);
m_tabPages[1]->Create(IDD_TAB_GRID, this);
m_tabPages[2]->Create(IDD_TAB_MAP, this);
SetCurFocus(m_tabCurrent);
/*
m_tabPages[0]->ShowWindow(SW_HIDE);
m_tabPages[1]->ShowWindow(SW_HIDE);
m_tabPages[2]->ShowWindow(SW_HIDE);
*/
for(int nCount=0; nCount < m_nNumberOfPages; nCount++) {
if (m_tabCurrent == nCount) {
m_tabPages[nCount]->ShowWindow(SW_SHOW);
} else {
m_tabPages[nCount]->ShowWindow(SW_HIDE);
}
}
// m_tabPages[m_tabCurrent]->ShowWindow(SW_SHOW);
m_tabPages[m_tabCurrent]->SetFocus();
SetRectangle();
}
void CMyTabCtrl::SetRectangle()
{
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-1;
nYc=tabRect.bottom-nY-1;
/*
m_tabPages[0]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);
for(int nCount=1; nCount < m_nNumberOfPages; nCount++){
m_tabPages[nCount]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
}
*/
for(int nCount=0; nCount < m_nNumberOfPages; nCount++){
if (m_tabCurrent == nCount) {
m_tabPages[nCount]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);
} else {
m_tabPages[nCount]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
}
}
}
BEGIN_MESSAGE_MAP(CMyTabCtrl, CTabCtrl)
//{{AFX_MSG_MAP(CMyTabCtrl)
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyTabCtrl message handlers
void CMyTabCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
CTabCtrl::OnLButtonDown(nFlags, point);
if(m_tabCurrent != GetCurFocus()){
m_tabPages[m_tabCurrent]->ShowWindow(SW_HIDE);
m_tabCurrent=GetCurFocus();
m_tabPages[m_tabCurrent]->ShowWindow(SW_SHOW);
m_tabPages[m_tabCurrent]->SetFocus();
AfxGetApp()->WriteProfileInt("Main", "CurrentTab", m_tabCurrent);
}
}