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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
/*
Splash Screen Plugin for Miranda NG (www.miranda-ng.org)
(c) 2004-2007 nullbie, (c) 2005-2007 Thief
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "stdafx.h"
BOOL bpreviewruns;
MyBitmap *SplashBmp, *tmpBmp;
LRESULT CALLBACK SplashWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case WM_LOADED:
#ifdef _DEBUG
logMessage(L"WM_LOADED", L"called");
#endif
if (!options.showtime)
SetTimer(hwnd, 7, 2000, nullptr);
break;
case WM_LBUTTONDOWN:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case WM_TIMER:
#ifdef _DEBUG
wchar_t b[40];
mir_snwprintf(b, L"%d", wParam);
logMessage(L"Timer ID", b);
mir_snwprintf(b, L"%d", options.showtime);
logMessage(L"ShowTime value", b);
#endif
if (options.showtime > 0) { // TimeToShow enabled
if (wParam == 6) {
PostMessage(hwnd, WM_CLOSE, 0, 0);
#ifdef _DEBUG
logMessage(L"Showtime timer", L"triggered");
#endif
}
}
else {
PostMessage(hwnd, WM_CLOSE, 0, 0);
if (wParam == 7) {
#ifdef _DEBUG
logMessage(L"On Modules Loaded timer", L"triggered");
#endif
}
}
break;
case WM_RBUTTONDOWN:
ShowWindow(hwndSplash, SW_HIDE);
DestroyWindow(hwndSplash);
bpreviewruns = false; // preview is stopped.
break;
case WM_CLOSE:
{
RECT rc; GetWindowRect(hwndSplash, &rc);
POINT ptDst = { rc.left, rc.top };
POINT ptSrc = { 0, 0 };
SIZE sz = { rc.right - rc.left, rc.bottom - rc.top };
BLENDFUNCTION blend;
blend.BlendOp = AC_SRC_OVER;
blend.BlendFlags = 0;
blend.SourceConstantAlpha = 255;
blend.AlphaFormat = AC_SRC_ALPHA;
// Fade Out
if (options.fadeout) {
int i;
for (i = 255; i >= 0; i -= options.fosteps) {
blend.SourceConstantAlpha = i;
UpdateLayeredWindow(hwndSplash, nullptr, &ptDst, &sz, SplashBmp->getDC(), &ptSrc, 0xffffffff, &blend, LWA_ALPHA);
Sleep(1);
}
}
}
if (bserviceinvoked) bserviceinvoked = false;
if (bpreviewruns) bpreviewruns = false;
DestroyWindow(hwndSplash);
break;
case WM_MOUSEMOVE:
if (bserviceinvoked)
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case WM_DESTROY:
#ifdef _DEBUG
logMessage(L"WM_DESTROY", L"called");
#endif
ShowWindow(hwndSplash, SW_HIDE);
DestroyWindow(hwndSplash);
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
void __cdecl SplashThread(void *arg)
{
IGraphBuilder *pGraph = nullptr;
IMediaControl *pControl = nullptr;
if (options.playsnd) {
// Initialize the COM library.
CoInitialize(nullptr);
// Create the filter graph manager and query for interfaces.
CoCreateInstance(CLSID_FilterGraph, nullptr, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph);
// Get MediaControl Interface
pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
// Build the graph. IMPORTANT: Change this string to a file on your system.
pGraph->RenderFile(szSoundFile, nullptr);
// Run the graph.
pControl->Run();
}
WNDCLASSEX wcl;
wcl.cbSize = sizeof(wcl);
wcl.lpfnWndProc = SplashWindowProc;
wcl.style = 0;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.hInstance = g_plugin.getInst();
wcl.hIcon = nullptr;
wcl.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcl.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
wcl.lpszMenuName = nullptr;
wcl.lpszClassName = SPLASH_CLASS;
wcl.hIconSm = nullptr;
RegisterClassEx(&wcl);
RECT DesktopRect;
int w = GetSystemMetrics(SM_CXSCREEN);
int h = GetSystemMetrics(SM_CYSCREEN);
DesktopRect.left = 0;
DesktopRect.top = 0;
DesktopRect.right = w;
DesktopRect.bottom = h;
RECT WindowRect;
WindowRect.left = (DesktopRect.left + DesktopRect.right - SplashBmp->getWidth()) / 2;
WindowRect.top = (DesktopRect.top + DesktopRect.bottom - SplashBmp->getHeight()) / 2;
WindowRect.right = WindowRect.left + SplashBmp->getWidth();
WindowRect.bottom = WindowRect.top + SplashBmp->getHeight();
hwndSplash = CreateWindowEx(
WS_EX_TOOLWINDOW | WS_EX_TOPMOST,//dwStyleEx
SPLASH_CLASS, //Class name
nullptr, //Title
DS_SETFONT | DS_FIXEDSYS | WS_POPUP, //dwStyle
WindowRect.left, // x
WindowRect.top, // y
SplashBmp->getWidth(), // Width
SplashBmp->getHeight(), // Height
HWND_DESKTOP, //Parent
nullptr, //menu handle
g_plugin.getInst(), //Instance
nullptr);
RECT rc; GetWindowRect(hwndSplash, &rc);
POINT ptDst = { rc.left, rc.top };
POINT ptSrc = { 0, 0 };
SIZE sz = { rc.right - rc.left, rc.bottom - rc.top };
bool splashWithMarkers = false;
BLENDFUNCTION blend;
blend.BlendOp = AC_SRC_OVER;
blend.BlendFlags = 0;
blend.SourceConstantAlpha = 0;
blend.AlphaFormat = AC_SRC_ALPHA;
if (options.showversion) {
// locate text markers:
int i, x = -1, y = -1;
int splashWidth = SplashBmp->getWidth();
for (i = 0; i < splashWidth; ++i)
if (SplashBmp->getRow(0)[i] & 0xFF000000) {
if (x < 0) {
x = i - 1; // 1 pixel for marker line
splashWithMarkers = true;
}
else {
x = -1;
splashWithMarkers = false;
break;
}
}
int splashHeight = SplashBmp->getHeight();
for (i = 0; splashWithMarkers && (i < splashHeight); ++i)
if (SplashBmp->getRow(i)[0] & 0xFF000000) {
if (y < 0) {
y = i - 1; // 1 pixel for marker line
splashWithMarkers = true;
}
else {
y = -1;
splashWithMarkers = false;
break;
}
}
wchar_t verString[256] = { 0 };
wchar_t *mirandaVerString = mir_a2u(szVersion);
mir_snwprintf(verString, L"%s%s", szPrefix, mirandaVerString);
mir_free(mirandaVerString);
LOGFONT lf = { 0 };
lf.lfHeight = 14;
mir_wstrcpy(lf.lfFaceName, L"Verdana");
SelectObject(SplashBmp->getDC(), CreateFontIndirect(&lf));
if (!splashWithMarkers) {
SIZE v_sz = { 0, 0 };
GetTextExtentPoint32(SplashBmp->getDC(), verString, (int)mir_wstrlen(verString), &v_sz);
x = SplashBmp->getWidth() / 2 - (v_sz.cx / 2);
y = SplashBmp->getHeight() - (SplashBmp->getHeight()*(100 - 90) / 100);
}
SetTextColor(SplashBmp->getDC(), (0xFFFFFFFFUL - SplashBmp->getRow(y)[x]) & 0x00FFFFFFUL);
SetBkMode(SplashBmp->getDC(), TRANSPARENT);
SplashBmp->DrawText(verString, x, y);
}
SetWindowLongPtr(hwndSplash, GWL_EXSTYLE, GetWindowLongPtr(hwndSplash, GWL_EXSTYLE) | WS_EX_LAYERED);
UpdateLayeredWindow(hwndSplash, nullptr, &ptDst, &sz, SplashBmp->getDC(), &ptSrc, 0xffffffff, &blend, LWA_ALPHA);
ShowWindow(hwndSplash, SW_SHOWNORMAL);
if (options.fadein) {
// Fade in
for (int i = 0; i < 255; i += options.fisteps) {
blend.SourceConstantAlpha = i;
UpdateLayeredWindow(hwndSplash, nullptr, &ptDst, &sz, SplashBmp->getDC(), &ptSrc, 0xffffffff, &blend, LWA_ALPHA);
Sleep(1);
}
}
blend.SourceConstantAlpha = 255;
UpdateLayeredWindow(hwndSplash, nullptr, &ptDst, &sz, SplashBmp->getDC(), &ptSrc, 0xffffffff, &blend, LWA_ALPHA);
if (DWORD_PTR(arg) > 0) {
if (SetTimer(hwndSplash, 6, DWORD_PTR(arg), nullptr)) {
#ifdef _DEBUG
logMessage(L"Timer TimeToShow", L"set");
#endif
}
}
else
if (bmodulesloaded) {
if (SetTimer(hwndSplash, 8, 2000, nullptr)) {
#ifdef _DEBUG
logMessage(L"Timer Modules loaded", L"set");
#endif
}
}
// The Message Pump
MSG msg;
while (GetMessage(&msg, nullptr, 0, 0) == TRUE) //NULL means every window in the thread; == TRUE means a safe pump.
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if (options.playsnd) {
pControl->Release();
pGraph->Release();
CoUninitialize();
}
}
BOOL ShowSplash(BOOL bpreview)
{
if (bpreview && bpreviewruns) return 0;
if (bpreview) bpreviewruns = true;
unsigned long timeout = 0;
SplashBmp = new MyBitmap;
#ifdef _DEBUG
logMessage(L"Loading splash file", szSplashFile);
#endif
if (!SplashBmp->loadFromFile(szSplashFile))
return 0;
#ifdef _DEBUG
logMessage(L"Thread", L"start");
#endif
if (bpreview) {
ShowWindow(hwndSplash, SW_HIDE);
DestroyWindow(hwndSplash);
timeout = 2000;
#ifdef _DEBUG
logMessage(L"Preview", L"yes");
#endif
}
else {
timeout = options.showtime;
#ifdef _DEBUG
wchar_t b[40];
mir_snwprintf(b, L"%d", options.showtime);
logMessage(L"Timeout", b);
#endif
}
mir_forkthread(SplashThread, (void*)timeout);
#ifdef _DEBUG
logMessage(L"Thread", L"end");
#endif
return 1;
}
|