-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplashScreen.cpp
More file actions
117 lines (114 loc) · 2.97 KB
/
splashScreen.cpp
File metadata and controls
117 lines (114 loc) · 2.97 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
#include <Windows.h>
#include <gdiplus.h>
#include <stdio.h>
#include <cassert>
#include "globalVars.h"
#include "splashScreen.h"
#include "appconst.h"
void registerSplashClass(void)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)splashWindowProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = ghInstance;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = SplashWndClass;
wcex.hIconSm = NULL;
if (!RegisterClassEx(&wcex))
{
MessageBox(NULL, TEXT("Window class registration failed"), TEXT("Error"), MB_ICONERROR);
}
}
void createSplashScreen(void)
{
splashScreen = CreateWindowEx(WS_EX_TOOLWINDOW,
SplashWndClass,
NULL,
WS_OVERLAPPED | SS_BITMAP,
wpInitPosX,
wpInitPosY,
splashScreenWidth,
splashScreenHeight,
NULL,
NULL,
ghInstance,
NULL);
if (!splashScreen)
{
MessageBox(NULL, TEXT("Window creation failed"), TEXT("Error"), MB_ICONERROR);
}
lpSplashWndProc = (WNDPROC)SetWindowLongPtr(splashScreen, GWL_WNDPROC, (LONG_PTR)&splashWindowProc);
}
LRESULT CALLBACK splashWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_NCCALCSIZE: //CAPTURE THIS MESSAGE AND RETURN NULL
return NULL;
case WM_CREATE:
SetTimer(hWnd, ID_TIMER_INIT, 1000, NULL);
SetTimer(hWnd, ID_TIMER_LOAD, 2000, NULL);
SetTimer(hWnd, ID_TIMER_DONE, 4000, NULL);
SetTimer(hWnd, ID_TIMER_CLOSE, 5000, NULL);
break;
case WM_PAINT:
{
PAINTSTRUCT ps = { 0 };
RECT rect = { 0 };
HDC hDC = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rect);
InflateRect(&rect, -2, -2);
Rectangle(hDC, rect.left, rect.top, rect.right, rect.bottom);
InflateRect(&rect, -15, -15);
HFONT hFont = CreateFont(-35, -35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("Arial"));
HFONT hOldFont = (HFONT)SelectObject(hDC, hFont);
DrawText(hDC, SZ_SPLASH, lstrlen(SZ_SPLASH), &rect, DT_WORDBREAK);
SelectObject(hDC, hOldFont);
EndPaint(hWnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_TIMER:
{
HDC hDC = GetDC(hWnd);
RECT rect = { 0 };
GetClientRect(hWnd, &rect);
KillTimer(hWnd, wParam);
switch (wParam)
{
case ID_TIMER_CLOSE:
DestroyWindow(hWnd);
break;
case ID_TIMER_INIT:
TextOut(hDC, rect.right - 200, rect.bottom - 20, SZ_INIT, lstrlen(SZ_INIT));
break;
case ID_TIMER_LOAD:
TextOut(hDC, rect.right - 200, rect.bottom - 20, SZ_LOAD, lstrlen(SZ_LOAD));
break;
case ID_TIMER_DONE:
TextOut(hDC, rect.right - 200, rect.bottom - 20, SZ_CLOSE, lstrlen(SZ_CLOSE));
break;
}
ReleaseDC(hWnd, hDC);
}
break;
default:
{
break;
}
}
return (DefWindowProcW(hWnd, message, wParam, lParam));
}
void showSplashScreen(void)
{
registerSplashClass();
createSplashScreen();
}