-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMainFrm.cpp
More file actions
executable file
·378 lines (304 loc) · 11.4 KB
/
MainFrm.cpp
File metadata and controls
executable file
·378 lines (304 loc) · 11.4 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "TrackEditor.h"
#include "MainFrm.h"
#include "ToolBarUtils.h"
#include "TrackInfo.h"
#include "TrackPropertySheet.h"
#include "Splash.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//
extern CTrackEditorApp theApp;
extern void
LoadControlBarPosition(CFrameWnd* frame, CControlBar* cntrl, CString strStringItem);
extern void
SaveControlBarPosition(CFrameWnd* frame, CControlBar* cntrl, CString strStringItem);
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
ON_WM_INITMENU()
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_SIZE()
ON_COMMAND(IDC_SAVE_TRACK_IMAGE, OnSaveTrackImage)
ON_COMMAND(ID_ZOOMCOMBO, OnZoomcombo)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
// ON_COMMAND(ID_HELP, CMDIFrameWnd::OnHelp)
// ON_COMMAND(ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp)
// ON_COMMAND(ID_DEFAULT_HELP, CMDIFrameWnd::OnHelpFinder)
static UINT indicators[] = {
ID_SEPARATOR,// status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame() {}
void CMainFrame::SavePositions()
{
// SaveControlBarPosition(this,&m_wndToolBar,"Track_Toolbar");
// SaveControlBarPosition(this,&m_wndToolsToolBar,"Tools_Toolbar");
// SaveControlBarPosition(this,&m_wndShowToolBar,"View_Toolbar");
// SaveControlBarPosition(this,&m_wndObjectToolBar,"Object_Toolbar");
}
#define SNAP_WIDTH 80
#define PROFILE(x, y, b) \
AfxGetApp()->GetProfileInt(CString(#y), CString(#x), b);
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1) return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP, CRect(0, 0, 0, 0), IDR_MAINFRAME) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) {
TRACE0("Failed to create toolbar\n");
return -1;// fail to create
}
if (!m_wndToolsToolBar.CreateEx(this, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP, CRect(0, 0, 0, 0), IDR_TOOLS) || !m_wndToolsToolBar.LoadToolBar(IDR_TOOLS)) {
TRACE0("Failed to create toolbar\n");
return -1;// fail to create
}
if (!m_wndObjectToolBar.CreateEx(this, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP, CRect(0, 0, 0, 0), IDR_OBJECT) || !m_wndObjectToolBar.LoadToolBar(IDR_OBJECT)) {
TRACE0("Failed to create toolbar\n");
return -1;// fail to create
}
if (!m_wndShowToolBar.CreateEx(this, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP, CRect(0, 0, 0, 0), IDR_SHOW) || !m_wndShowToolBar.LoadToolBar(IDR_SHOW)) {
TRACE0("Failed to create toolbar\n");
return -1;// fail to create
}
if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators) / sizeof(UINT))) {
TRACE0("Failed to create status bar\n");
return -1;// fail to create
}
// TODO: Remove this if you don't want tool tips or a resizeable toolbar
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_GRIPPER | CBRS_BORDER_3D | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC | TBSTYLE_WRAPABLE);
m_wndToolBar.SetHeight(28);
m_wndToolsToolBar.SetBarStyle(m_wndToolsToolBar.GetBarStyle() | CBRS_GRIPPER | CBRS_BORDER_3D | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC | TBSTYLE_WRAPABLE);
m_wndToolsToolBar.SetHeight(28);
m_wndObjectToolBar.SetBarStyle(
m_wndObjectToolBar.GetBarStyle() | CBRS_GRIPPER | CBRS_BORDER_3D | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC | TBSTYLE_WRAPABLE);
m_wndObjectToolBar.SetHeight(28);
m_wndShowToolBar.SetBarStyle(m_wndShowToolBar.GetBarStyle() | CBRS_GRIPPER | CBRS_BORDER_3D | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC | TBSTYLE_WRAPABLE);
m_wndShowToolBar.SetHeight(28);
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndShowToolBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndObjectToolBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolsToolBar.EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
DockControlBar(&m_wndToolsToolBar);
DockControlBar(&m_wndObjectToolBar);
DockControlBar(&m_wndShowToolBar);
int TreeHeight = PROFILE(TreeHeight, Preferences, 10);
int TreeWidth = PROFILE(TreeWidth, Preferences, 110);
if (!m_wndDlgBar.Create(this, CSize(TreeWidth, TreeHeight), AFX_IDW_CONTROLBAR_FIRST + 32, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_LEFT)) {
AfxMessageBox("Failed to create DlgBar", MB_OK);
return -1;// fail to create
}
m_wndDlgBar.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
DockControlBar(&m_wndDlgBar);
theApp.theMainTree = &m_wndDlgBar;
int PropHeight = PROFILE(PropHeight, Preferences, 100);
int PropWidth = PROFILE(PropWidth, Preferences, 200);
if (!m_wndProperty.Create(
this, CSize(PropWidth, PropHeight), AFX_IDW_CONTROLBAR_FIRST + 33, LVS_REPORT | WS_CHILD | WS_VISIBLE | CBRS_ALIGN_BOTTOM)) {
AfxMessageBox("Failed to create DlgBar", MB_OK);
return -1;// fail to create
}
m_wndProperty.EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndProperty);
m_listControlBars.AddTail(&m_wndDlgBar);
m_listControlBars.AddTail(&m_wndProperty);
theApp.theMainPropertyTable = &m_wndProperty;
EnableDocking(CBRS_ALIGN_ANY);
if (IsIE4Capable()) {
LoadBarState("ToolBars");
}
// CG: The following line was added by the Splash Screen component.
CSplashWnd::ShowSplashScreen(this);
return 0;
}
void CMainFrame::RecalcLayout(BOOL bNotify)
{
CMDIFrameWnd::RecalcLayout(bNotify);
CMDIFrameWnd::RecalcLayout(bNotify);
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.lpszClass = AfxRegisterWndClass(
CS_DBLCLKS, AfxGetApp()->LoadStandardCursor(IDC_ARROW), (HBRUSH)(COLOR_WINDOW + 1), AfxGetApp()->LoadIcon(IDR_MAINFRAME));
return CMDIFrameWnd::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif//_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CMDIFrameWnd::OnSize(nType, cx, cy);
RecalcLayout(TRUE);
// m_wndDlgBar.SetWindowPos(NULL,0,0,cx,cy,SWP_NOMOVE);
// TODO: Add your message handler code here
}
void CMainFrame::OnSaveTrackImage()
{
// TODO: Add your command handler code here
}
void CMainFrame::OnZoomcombo()
{
// TODO: Add your command handler code here
AfxMessageBox("Combo");
}
void CMainFrame::OnClose()
{
// Save main window position
CWinApp* app = AfxGetApp();
WINDOWPLACEMENT wp;
GetWindowPlacement(&wp);
app->WriteProfileInt("Frame", "Status", wp.showCmd);
app->WriteProfileInt("Frame", "Top", wp.rcNormalPosition.top);
app->WriteProfileInt("Frame", "Left", wp.rcNormalPosition.left);
app->WriteProfileInt("Frame", "Bottom", wp.rcNormalPosition.bottom);
app->WriteProfileInt("Frame", "Right", wp.rcNormalPosition.right);
SaveToolBarPositions();
CMDIFrameWnd::OnClose();
}
void CMainFrame::SaveToolBarPositions()
{
if (IsIE4Capable()) {
SaveBarState("ToolBars");
}
}
void CMainFrame::OnInitMenu(CMenu* pMenu)
{
CMDIFrameWnd::OnInitMenu(pMenu);
// CG: This block added by 'Tip of the Day' component.
{
// TODO: This code adds the "Tip of the Day" menu item
// on the fly. It may be removed after adding the menu
// item to all applicable menu items using the resource
// editor.
// Add Tip of the Day menu item on the fly!
static CMenu* pSubMenu = NULL;
CString strHelp;
strHelp.LoadString(CG_IDS_TIPOFTHEDAYHELP);
CString strMenu;
int nMenuCount = pMenu->GetMenuItemCount();
BOOL bFound = FALSE;
for (int i = 0; i < nMenuCount; i++) {
pMenu->GetMenuString(i, strMenu, MF_BYPOSITION);
if (strMenu == strHelp) {
pSubMenu = pMenu->GetSubMenu(i);
bFound = TRUE;
ASSERT(pSubMenu != NULL);
}
}
CString strTipMenu;
strTipMenu.LoadString(CG_IDS_TIPOFTHEDAYMENU);
if (!bFound) {
// Help menu is not available. Please add it!
if (pSubMenu == NULL) {
// The same pop-up menu is shared between mainfrm and frame
// with the doc.
static CMenu popUpMenu;
pSubMenu = &popUpMenu;
pSubMenu->CreatePopupMenu();
pSubMenu->InsertMenu(0, MF_STRING | MF_BYPOSITION, CG_IDS_TIPOFTHEDAY, strTipMenu);
}
pMenu->AppendMenu(MF_STRING | MF_BYPOSITION | MF_ENABLED | MF_POPUP,
(UINT)pSubMenu->m_hMenu,
strHelp);
DrawMenuBar();
} else {
// Check to see if the Tip of the Day menu has already been added.
pSubMenu->GetMenuString(0, strMenu, MF_BYPOSITION);
if (strMenu != strTipMenu) {
// Tip of the Day submenu has not been added to the
// first position, so add it.
pSubMenu->InsertMenu(0, MF_BYPOSITION);// Separator
pSubMenu->InsertMenu(0, MF_STRING | MF_BYPOSITION, CG_IDS_TIPOFTHEDAY, strTipMenu);
}
}
}
}
#include <windows.h>
#include <shlwapi.h>
HRESULT
GetComCtlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor)
{
HINSTANCE hComCtl;
if (IsBadWritePtr(pdwMajor, sizeof(DWORD)) || IsBadWritePtr(pdwMinor, sizeof(DWORD)))
return E_INVALIDARG;
// load the DLL
hComCtl = LoadLibrary(TEXT("comctl32.dll"));
if (hComCtl) {
HRESULT hr = S_OK;
DLLGETVERSIONPROC pDllGetVersion;
/*
You must get this function explicitly because earlier versions of the DLL
don't implement this function. That makes the lack of implementation of the
function a version marker in itself.
*/
pDllGetVersion =
(DLLGETVERSIONPROC)GetProcAddress(hComCtl, TEXT("DllGetVersion"));
if (pDllGetVersion) {
DLLVERSIONINFO dvi;
ZeroMemory(&dvi, sizeof(dvi));
dvi.cbSize = sizeof(dvi);
hr = (*pDllGetVersion)(&dvi);
if (SUCCEEDED(hr)) {
*pdwMajor = dvi.dwMajorVersion;
*pdwMinor = dvi.dwMinorVersion;
} else {
hr = E_FAIL;
}
} else {
/*
If GetProcAddress failed, then the DLL is a version previous to the one
shipped with IE 3.x.
*/
*pdwMajor = 4;
*pdwMinor = 0;
}
FreeLibrary(hComCtl);
return hr;
}
return E_FAIL;
}
BOOL CMainFrame::IsIE4Capable()
{
DWORD pdwMajor;
DWORD pdwMinor;
if (FAILED(GetComCtlVersion(&pdwMajor, &pdwMinor))) {
return FALSE;
}
if (pdwMajor == 4 && pdwMinor < 71) {
return FALSE;
}
return TRUE;
}