-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSplashWnd.cpp
More file actions
314 lines (255 loc) · 6.48 KB
/
Copy pathSplashWnd.cpp
File metadata and controls
314 lines (255 loc) · 6.48 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
// SplashWnd.cpp : implementation file
//
// ©1998-2001 Codejock Software, All Rights Reserved.
// Based on the Visual C++ splash screen component.
//
// support@codejock.com
// http://www.codejock.com
//
//////////////////////////////////////////////////////////////////////
#include "pch.h"
#include "SplashWnd.h"
#include "TestButton.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Splash Screen class
BOOL CSplashWnd::m_bShowSplashWnd;
CSplashWnd* CSplashWnd::m_pSplashWnd;
BOOL CSplashWnd::m_bFileVersion = TRUE;
BOOL CSplashWnd::m_bLicensedName = TRUE;
CSplashWnd::CSplashWnd()
{
m_bShow = FALSE;
m_crTextCol = RGB(0, 0, 0);
nCurrStep = 100;
// initialize the fonts:
InitFonts();
m_sCompaneyName.LoadStringW(IDS_STRINGCOMPANYNAME);
}
CSplashWnd::~CSplashWnd()
{
// Clear the static window pointer.
ASSERT(m_pSplashWnd == this);
m_pSplashWnd = NULL;
}
BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)
//{{AFX_MSG_MAP(CSplashWnd)
ON_WM_PAINT()
ON_WM_TIMER()
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CSplashWnd::EnableSplashScreen(BOOL bEnable /*= TRUE*/)
{
m_bShowSplashWnd = bEnable;
}
BOOL CSplashWnd::ShowSplashScreen(UINT uTimeOut, UINT uBitmapID, CString strFileVers, CWnd* pParentWnd /*= NULL*/)
{
ASSERT(uTimeOut && uBitmapID);
if (!m_bShowSplashWnd || m_pSplashWnd != NULL)
{
return FALSE;
}
// Allocate a new splash screen, and create the window.
m_pSplashWnd = new CSplashWnd;
if (!m_pSplashWnd->m_bitmap.LoadBitmap(uBitmapID))
{
return FALSE;
}
BITMAP bm;
m_pSplashWnd->m_bitmap.GetBitmap(&bm);
CString strWndClass = AfxRegisterWndClass(0,
AfxGetApp()->LoadStandardCursor(IDC_ARROW));
if (!m_pSplashWnd->CreateEx(WS_EX_TOPMOST, strWndClass, NULL, WS_POPUP | WS_VISIBLE,
0, 0, 10, 10, pParentWnd->GetSafeHwnd(), NULL))
{
TRACE0("Failed to create splash screen.\n");
delete m_pSplashWnd;
return FALSE;
}
// Center the window.
m_pSplashWnd->ShowWindow(SW_HIDE);
m_pSplashWnd->SetWindowPos(&wndTop, 0 , 0, bm.bmWidth, bm.bmHeight, SWP_NOZORDER);
m_pSplashWnd->CenterWindow();
m_pSplashWnd->ShowWindow(SW_SHOW);
m_pSplashWnd->m_sFileVersion = strFileVers;
// Set a timer to destroy the splash screen.
m_pSplashWnd->SetTimer(0, uTimeOut, NULL);
return TRUE;
}
CSplashWnd * CSplashWnd::GetCurrentWindow()
{
return (m_pSplashWnd);
}
BOOL CSplashWnd::PreTranslateAppMessage(MSG* pMsg)
{
/*
if (m_pSplashWnd == NULL)
return FALSE;
// If we get a keyboard or mouse message, hide the splash screen.
if (pMsg->message == WM_KEYDOWN ||
pMsg->message == WM_SYSKEYDOWN ||
pMsg->message == WM_LBUTTONDOWN ||
pMsg->message == WM_RBUTTONDOWN ||
pMsg->message == WM_MBUTTONDOWN ||
pMsg->message == WM_NCLBUTTONDOWN ||
pMsg->message == WM_NCRBUTTONDOWN ||
pMsg->message == WM_NCMBUTTONDOWN)
{
m_pSplashWnd->HideSplashScreen();
return TRUE; // message handled here
}
*/
return FALSE; // message not handled
}
void CSplashWnd::HideSplashScreen()
{
// Destroy the window, and update the mainframe.
DestroyWindow();
AfxGetMainWnd()->UpdateWindow();
}
void CSplashWnd::PostNcDestroy()
{
delete this;
}
void CSplashWnd::OnPaint()
{
if (!m_bShow)
ShowWindow(SW_HIDE);
CPaintDC dc(this);
int nOldBkMode = 0, iX = 0, iY = 0;
CDC dcImage;
CRect rectC;
GetClientRect(&rectC);
ClientToScreen(rectC);
int iCX = rectC.Width();
int iCY = rectC.Height();
if (dcImage.CreateCompatibleDC(&dc))
{
BITMAP bm;
m_bitmap.GetBitmap(&bm);
if (m_iX < bm.bmWidth)
{
m_iX = bm.bmWidth;
m_iY = bm.bmHeight;
}
// select color and mode for the text:
dc.SetTextColor(m_crTextCol);
nOldBkMode = dc.SetBkMode(TRANSPARENT);
// select the font and save the default font:
HFONT def_font;
def_font = (HFONT) SelectObject(dc.m_hDC, m_Font.m_hObject);
if (m_bLicensedName)
{
// DrawText over bitmap
m_csTextExt = dc.GetOutputTextExtent(m_sCompaneyName);
dc.SetTextColor(RGB(154, 185, 215));
dc.TextOut(18,
iCY - 75,
m_sCompaneyName);
if (m_csTextExt.cx > iX)
iX = m_csTextExt.cx;
if (m_csTextExt.cy > iY)
iY = m_csTextExt.cy;
}
if (m_bFileVersion)
{
(HFONT) SelectObject(dc.m_hDC, m_Font.m_hObject);
// DrawText over bitmap
m_csTextExt = dc.GetOutputTextExtent(m_sFileVersion);
dc.SetTextColor(RGB(0, 0, 0));
dc.TextOut(18,
iCY - 60,
m_sFileVersion);
if (m_csTextExt.cx > iX)
iX = m_csTextExt.cx;
if (m_csTextExt.cy > iY)
iY = m_csTextExt.cy;
}
// re-select the old objects and clean up:
dc.SetBkMode(nOldBkMode);
SelectObject(dc.m_hDC , def_font);
if (m_iX<iX || m_iY < iY)
{
m_iX = iX + 50;
m_iY = iY*2;
SetWindowPos(&wndTop, 0, 0, m_iX, m_iY, SWP_NOZORDER);
CenterWindow();
RedrawWindow();
}
if (!m_bShow)
{
ShowWindow(SW_SHOW);
m_bShow = TRUE;
}
}
}
void CSplashWnd::InitFonts()
{
VERIFY(m_Font.CreateFont
(13,
0,
0,
0,
FW_MEDIUM,
0,
0,
0,
0,
0,
0,
0,
0,
_T("Tahoma")));
}
BOOL CSplashWnd::OnEraseBkgnd(CDC* pDC)
{
// TODO:
CRect rect, rect2; // We use rect to get the client area size
GetClientRect(rect);
CBitmap* pbmpOldBitmap1;
CBitmap bmpMainBitmap2;
CBitmap* pbmpOldBitmap2;
CDC dcMem1;
CDC dcMem2;
dcMem1.CreateCompatibleDC(NULL); // Create double CDCs
dcMem2.CreateCompatibleDC(NULL);
// We create an empty bitmap of the client rect size
bmpMainBitmap2.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
// Select the bitmaps
pbmpOldBitmap1 = dcMem1.SelectObject(&m_bitmap);
pbmpOldBitmap2 = dcMem2.SelectObject(&bmpMainBitmap2);
dcMem1.GetClipBox(rect2);
// We stretch the small bitmap to the background
dcMem2.StretchBlt(0, 0, rect.Width(), rect.Height(), &dcMem1, 0, 0, rect2.Width(), rect2.Height(), SRCCOPY);
// We blit the big one to the screen
pDC->BitBlt(0, 0, rect.Width(), rect.Height(), &dcMem2, 0, 0, SRCCOPY);
// Cleaning up
dcMem1.SelectObject(pbmpOldBitmap1);
dcMem1.DeleteDC();
dcMem2.SelectObject(pbmpOldBitmap2);
dcMem2.DeleteDC();
return TRUE;
// return CWnd::OnEraseBkgnd(pDC);
}
LRESULT CSplashWnd::SplashWinProc(UINT message, WPARAM wParam, LPARAM lParam)
{
return m_pSplashWnd->WindowProc(message, wParam, lParam);
}
void CSplashWnd::OnTimer(UINT_PTR nIDEvent)
{
nCurrStep--;
if (nCurrStep <= 0)
{
KillTimer(nIDEvent);
// Destroy the splash screen window.
HideSplashScreen();
}
else {
theApp.DlgTransparent(m_hWnd, nCurrStep);
}
}