-
Notifications
You must be signed in to change notification settings - Fork 3
/
MainDialog.cpp
132 lines (100 loc) · 2.67 KB
/
MainDialog.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
// MainDialog.cpp : implementation file
//
#include "stdafx.h"
#include "ExtIODll.h"
#include "MainDialog.h"
#include "ExtIODialog.h"
#include "AdvancedDialog.h"
#define myARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
extern CMainDialog* m_pmodeless;
// CMainDialog dialog
IMPLEMENT_DYNAMIC(CMainDialog, CDialog)
CMainDialog::CMainDialog(CWnd* pParent /*=NULL*/)
: CDialog(CMainDialog::IDD, pParent)
{
}
CMainDialog::~CMainDialog()
{
}
void CMainDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CMainDialog, CDialog)
//ON_WM_DESTROY()
ON_WM_CLOSE()
ON_WM_SHOWWINDOW()
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnTabChange)
END_MESSAGE_MAP()
// CMainDialog message handlers
BOOL CMainDialog::OnInitDialog()
{
CDialog::OnInitDialog();
m_tab.SubclassWindow(*GetDlgItem(IDC_TAB1));
// create tabs
m_tab.InsertItem(0, "ExtIO");
m_tab.InsertItem(1, "Advanced");
// create tab dialogs
m_dlg[0] = new CExtIODialog;
m_dlg[1] = new CAdvancedDialog;
VERIFY(m_dlg[0]->Create(IDD_EXTIODIALOG, this));
VERIFY(m_dlg[1]->Create(IDD_ADVANCEDDIALOG, this));
CenterWindow();
return TRUE;
}
void CMainDialog::OnShowWindow(BOOL bShow, UINT nStatus)
{
// initialize tabbed view - show first dialog
ShowTabDlg(m_tab.GetCurSel());
}
void CMainDialog::ShowTabDlg(int tabSel)
{
// hide all tab dialogs
for(int idx = 0; idx < myARRAYSIZE(m_dlg); idx++)
m_dlg[idx]->ShowWindow(SW_HIDE);
// show selected one
CRect rc;
m_tab.GetClientRect(rc);
m_tab.AdjustRect(FALSE, rc);
//m_tab.ClientToScreen(rc); Seems that we do not need this for modeless dialogs
// as they are already operating with screen coordinates.
m_dlg[tabSel]->SetWindowPos(NULL, rc.left+2, rc.top+2, 0, 0, SWP_NOZORDER|SWP_NOSIZE|SWP_SHOWWINDOW|SWP_NOACTIVATE);
}
void CMainDialog::OnTabChange(NMHDR* pnmhdr, LRESULT* pResult)
{
ShowTabDlg(m_tab.GetCurSel());
*pResult = 0;
}
/*
void CMainDialog::OnDestroy()
{
AfxMessageBox("OnDestroy()");
for(int idx = 0; idx < myARRAYSIZE(m_dlg); idx++)
delete m_dlg[idx];
}
*/
//This is needed when we are closing the window using the ExtIO button.
void CMainDialog::PostNcDestroy()
{
CDialog::PostNcDestroy();
for(int idx = 0; idx < myARRAYSIZE(m_dlg); idx++)
{
if (m_dlg[idx])
{
delete m_dlg[idx];
m_dlg[idx]=0;
}
}
delete this;
m_pmodeless=NULL; //xx
}
// This is needed on a case we are closing window using the [X] at the corner
void CMainDialog::OnClose()
{
for(int idx = 0; idx < myARRAYSIZE(m_dlg); idx++)
{
if (m_dlg[idx])
m_dlg[idx]->ShowWindow(SW_HIDE);
}
CDialog::OnClose();
}