-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplash.cpp
More file actions
124 lines (98 loc) · 3.22 KB
/
Copy pathsplash.cpp
File metadata and controls
124 lines (98 loc) · 3.22 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
#include <windows.h>
#include <gdiplus.h>
#include <thread>
#include <chrono>
#pragma comment(lib, "gdiplus.lib")
using namespace Gdiplus;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void ShowSplashScreen(HDC hdc);
const int splashScreenWidth = 540;
const int splashScreenHeight = 250;
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) {
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
const wchar_t CLASS_NAME[] = L"TransparentSplash";
WNDCLASSW wc = {};
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
RegisterClassW(&wc);
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
int windowWidth = 540;
int windowHeight = 250;
int windowPosX = (screenWidth - windowWidth) / 2;
int windowPosY = (screenHeight - windowHeight) / 2;
HWND hwnd = CreateWindowExW(
WS_EX_LAYERED | WS_EX_TOPMOST | WS_EX_TOOLWINDOW,
CLASS_NAME,
L"Transparent Splash Screen",
WS_POPUP,
windowPosX, windowPosY, windowWidth, windowHeight,
NULL,
NULL,
hInstance,
NULL
);
if (hwnd == NULL) {
MessageBoxW(NULL, L"Window Creation Failed!", L"Error", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
// Set the window to be transparent with alpha blending
SetLayeredWindowAttributes(hwnd, 0, 255, LWA_ALPHA);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
std::thread([](HWND hwnd) {
std::this_thread::sleep_for(std::chrono::seconds(4));
PostMessage(hwnd, WM_CLOSE, 0, 0);
}, hwnd).detach();
MSG msg = {};
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
GdiplusShutdown(gdiplusToken);
return 0;
}
#ifdef __cplusplus
extern "C" {
#endif
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
return wWinMain(hInstance, hPrevInstance, GetCommandLineW(), nCmdShow);
}
#ifdef __cplusplus
}
#endif
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
ShowSplashScreen(hdc);
EndPaint(hwnd, &ps);
} break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
void ShowSplashScreen(HDC hdc) {
Graphics graphics(hdc);
Image image(L"splash.png");
if (image.GetLastStatus() != Ok) {
MessageBoxW(NULL, L"Failed to load image!", L"Error", MB_ICONEXCLAMATION | MB_OK);
return;
}
int imgWidth = image.GetWidth();
int imgHeight = image.GetHeight();
// Calculate the center position for the image within the window
int x = (splashScreenWidth - imgWidth) / 2;
int y = (splashScreenHeight - imgHeight) / 2;
graphics.DrawImage(&image, x, y, imgWidth, imgHeight);
}