-
Notifications
You must be signed in to change notification settings - Fork 0
/
SplashScreen.cpp
126 lines (98 loc) · 3.17 KB
/
SplashScreen.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
/* Copyright (c) 2002-2012 Croteam Ltd.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as published by
the Free Software Foundation
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
#include "StdH.h"
#include "resource.h"
#define NAME "Splash"
static HBITMAP _hbmSplash = NULL;
static BITMAP _bmSplash;
static HBITMAP _hbmSplashMask = NULL;
static BITMAP _bmSplashMask;
static HWND hwnd = NULL;
static long FAR PASCAL SplashWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_PAINT: {
PAINTSTRUCT ps;
BeginPaint(hWnd, &ps);
HDC hdcMem = CreateCompatibleDC(ps.hdc);
SelectObject(hdcMem, _hbmSplashMask);
BitBlt(ps.hdc, 0, 0, _bmSplash.bmWidth, _bmSplash.bmHeight, hdcMem, 0, 0, SRCAND);
SelectObject(hdcMem, _hbmSplash);
BitBlt(ps.hdc, 0, 0, _bmSplash.bmWidth, _bmSplash.bmHeight, hdcMem, 0, 0, SRCPAINT);
DeleteDC(hdcMem);
EndPaint(hWnd, &ps);
return 0;
} break;
case WM_ERASEBKGND:
return 1;
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
void ShowSplashScreen(HINSTANCE hInstance) {
_hbmSplash = LoadBitmapA(hInstance, (char*)IDB_SPLASH);
if (_hbmSplash == NULL) {
return;
}
_hbmSplashMask = LoadBitmapA(hInstance, (char*)IDB_SPLASHMASK);
if (_hbmSplashMask == NULL) {
return;
}
GetObject(_hbmSplash, sizeof(BITMAP), (LPSTR)&_bmSplash);
GetObject(_hbmSplashMask, sizeof(BITMAP), (LPSTR)&_bmSplashMask);
if (_bmSplashMask.bmWidth != _bmSplash.bmWidth
|| _bmSplashMask.bmHeight != _bmSplash.bmHeight) {
return;
}
int iScreenX = ::GetSystemMetrics(SM_CXSCREEN); // screen size
int iScreenY = ::GetSystemMetrics(SM_CYSCREEN);
WNDCLASSA wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = SplashWindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, (LPCTSTR)IDR_MAINFRAME);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NAME;
wc.lpszClassName = NAME;
RegisterClassA(&wc);
// create a window
hwnd = CreateWindowExA(
WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW,
NAME,
"SeriousSam loading...", // title
WS_POPUP,
iScreenX / 2 - _bmSplash.bmWidth / 2,
iScreenY / 2 - _bmSplash.bmHeight / 2,
_bmSplash.bmWidth, _bmSplash.bmHeight, // window size
NULL,
NULL,
hInstance,
NULL);
if (!hwnd) {
return;
}
ShowWindow(hwnd, SW_SHOW);
RECT rect;
GetClientRect(hwnd, &rect);
InvalidateRect(hwnd, &rect, TRUE);
UpdateWindow(hwnd);
}
void HideSplashScreen(void) {
if (hwnd == NULL) {
return;
}
DestroyWindow(hwnd);
DeleteObject(_hbmSplash);
DeleteObject(_hbmSplashMask);
}