-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtapp.cpp
198 lines (162 loc) · 4.16 KB
/
tapp.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
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
/*
TAPP.CPP
Copyright (c) 1994 Shawn Halpenny
All rights reserved.
Source code module for TApplication class.
*/
#ifndef __WOLF_H
#include <wolf.h>
#endif
#ifndef __STDIO_H
#include <stdio.h>
#endif
extern PTApplication pTempApp;
//done
TApplication::TApplication(LPCSTR lpszAClassName, HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpszCmdLn, int nShow)
{
lpszClassName = lpszAClassName;
hInstance = hInst;
pTempApp = this; //see TWindowObject constructor for explanation
hPrevInstance = hPrevInst;
lpszCmdLine = lpszCmdLn;
nCmdShow = nShow;
nStatus = 0;
pMainWindow = NULL;
hAccel = 0;
} //TApplication::TApplication
//done
TApplication::~TApplication()
{
delete pMainWindow;
} //TApplication::~TApplication
//done
void TApplication::Run()
{
MSG AMsg;
if (nStatus != -1)
{
InitMainWindow();
pMainWindow->WndClass.lpszClassName = lpszClassName;
pMainWindow->Create();
pMainWindow->Show(nCmdShow);
do {
if (PeekMessage(&AMsg, 0, 0, 0, PM_NOREMOVE))
{
if (!GetMessage(&AMsg, 0, 0, 0))
break;
if (!ProcessMsgs(AMsg))
{
TranslateMessage(&AMsg);
DispatchMessage(&AMsg);
}
}
else
Idle();
} while (TRUE);
nStatus = (int) AMsg.wParam;
}
} //TApplication::Run
//done
void TApplication::AssignAccel(int nAccelID)
{
AssignAccel(MAKEINTRESOURCE(nAccelID));
} //TApplication::AssignAccel
//done
void TApplication::AssignAccel(LPCSTR lpszAccel)
{
hAccel = LoadAccelerators(hInstance, lpszAccel);
} //TApplication::AssignAccel
//done
int TApplication::ExecDialog(PTDialog pDialog)
{
int nRetval;
pDialog->Create();
nRetval = pDialog->nStatus;
delete pDialog;
return nRetval;
} //TApplication::ExecDialog
//done
int TApplication::Input(PTWindowObject pParent, LPSTR lpszBuffer, int nBufLen, LPCSTR lpszQuery, ...)
{
LPSTR lpArgs = (LPSTR) &lpszQuery + sizeof(lpszQuery);
char *pszBuf = new char[2048];
int nRetval;
vsprintf(pszBuf, lpszQuery, lpArgs);
nRetval = ExecDialog(new TInputDialog(pParent, pszBuf, lpszBuffer, nBufLen));
delete[] pszBuf;
return nRetval;
} //TApplication::Input
//done
int TApplication::FileOpen(PTWindowObject pParent, RFileDlgData ff)
{
return ExecDialog(new TFileDialog(pParent, FD_OPEN, ff));
} //TApplication::FileOpen
//done
int TApplication::FileSave(PTWindowObject pParent, RFileDlgData ff)
{
return ExecDialog(new TFileDialog(pParent, FD_SAVE, ff));
} //TApplication::FileSave
//done
void TApplication::Idle()
{
} //TApplication::Idle
//done
int TApplication::MsgBox(PTWindowObject pParent, UINT wStyle, LPCSTR lpszCaption, LPCSTR lpszFormat, ...)
{
LPSTR lpArgs = (LPSTR) &lpszFormat + sizeof(lpszFormat);
char *pszBuf = new char[2048];
int nRetval;
vsprintf(pszBuf, lpszFormat, lpArgs);
nRetval = MessageBox(pParent->hWindow, pszBuf, lpszCaption, wStyle);
delete[] pszBuf;
return nRetval;
} //TApplication::MsgBox
//done
BOOL TApplication::ProcessMsgs(MSG &msg)
{
BOOL bRetval = FALSE;
if (ProcessDlgMsgs(msg))
bRetval = TRUE;
if (ProcessAccels(msg))
bRetval = TRUE;
if (ProcessMDIAccels(msg))
bRetval = TRUE;
return bRetval;
} //TApplication::ProcessMsgs
//done
BOOL TApplication::ProcessDlgMsgs(MSG &AMsg)
{
HWND hParentWnd;
PTWindowObject pWindow, pParentWindow;
hParentWnd = GetParent(AMsg.hwnd);
pWindow = (PTWindowObject) MAKELP(GetProp(AMsg.hwnd, "WolfS"), GetProp(AMsg.hwnd, "WolfO"));
if (pWindow)
if (pWindow->IsFlagSet(WB_KBHANDLER))
if (IsDialogMessage(AMsg.hwnd, &AMsg))
return TRUE;
if (hParentWnd)
{
pParentWindow = (PTWindowObject) MAKELP(GetProp(hParentWnd, "WolfS"), GetProp(hParentWnd, "WolfO"));
if (pParentWindow)
if (pParentWindow->IsFlagSet(WB_KBHANDLER))
if (IsDialogMessage(hParentWnd, &AMsg))
return TRUE;
}
return FALSE;
} //TApplication::ProcessDlgMsgs
//done
BOOL TApplication::ProcessAccels(MSG &AMsg)
{
if (hAccel)
return TranslateAccelerator(pMainWindow->hWindow, hAccel, &AMsg);
else
return FALSE;
} //TApplication::ProcessAccels
//done
BOOL TApplication::ProcessMDIAccels(MSG &msg)
{
if (pMainWindow->Identify() == mdiframeClass)
return TranslateMDISysAccel(((PTMDIFrame) pMainWindow)->pClient->hWindow, &msg);
else
return FALSE;
} //TApplication::ProcessMDIAccels