Debian Codegraph @

Contrib/Splash/splash.c

raw
1 #include <windows.h>
2 #include <nsis/pluginapi.h> // nsis plugin
3
4 HINSTANCE g_hInstance;
5
6 HBITMAP g_hbm;
7 int sleep_val;
8 int g_rv=-1;
9
10 static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
11 {
12 if (uMsg == WM_CREATE)
13 {
14 BITMAP bm;
15 RECT vp;
16 GetObject(g_hbm, sizeof(bm), &bm);
17 SystemParametersInfo(SPI_GETWORKAREA, 0, &vp, 0);
18 SetWindowLongPtr(hwnd,GWL_STYLE,0);
19 SetWindowPos(hwnd,NULL,
20 vp.left+(vp.right-vp.left-bm.bmWidth)/2,
21 vp.top+(vp.bottom-vp.top-bm.bmHeight)/2,
22 bm.bmWidth,bm.bmHeight,
23 SWP_NOZORDER);
24 ShowWindow(hwnd,SW_SHOW);
25 SetTimer(hwnd,1,sleep_val,NULL);
26 return 0;
27 }
28 if (uMsg == WM_PAINT)
29 {
30 PAINTSTRUCT ps;
31 RECT r;
32 HDC curdc=BeginPaint(hwnd,&ps);
33 HDC hdc=CreateCompatibleDC(curdc);
34 HBITMAP oldbm;
35 GetClientRect(hwnd,&r);
36 oldbm=(HBITMAP)SelectObject(hdc,g_hbm);
37 BitBlt(curdc,r.left,r.top,r.right-r.left,r.bottom-r.top,hdc,0,0,SRCCOPY);
38 SelectObject(hdc,oldbm);
39 DeleteDC(hdc);
40 EndPaint(hwnd,&ps);
41 return 0;
42 }
43 if (uMsg == WM_CLOSE) return 0;
44 if (uMsg == WM_TIMER || uMsg == WM_LBUTTONDOWN)
45 {
46 g_rv=(uMsg == WM_LBUTTONDOWN);
47 DestroyWindow(hwnd);
48 }
49 return DefWindowProc(hwnd,uMsg,wParam,lParam);
50 }
51
52 BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
53 {
54 g_hInstance=hInst;
55 return TRUE;
56 }
57
58 void __declspec(dllexport) show(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop)
59 {
60 TCHAR fn[MAX_PATH];
61 TCHAR temp[64];
62 TCHAR *sleep=temp;
63
64
65 EXDLL_INIT();
66
67 popstring(sleep);
68 popstring(fn);
69
70 sleep_val=0;
71 while (*sleep >= _T('0') && *sleep <= _T('9'))
72 {
73 sleep_val*=10;
74 sleep_val+=*sleep++-_T('0');
75 }
76
77 if (fn[0] && sleep_val>0)
78 {
79 MSG msg;
80 TCHAR classname[4]=_T("_sp");
81 static WNDCLASS wc;
82 wc.lpfnWndProc = WndProc;
83 wc.hInstance = g_hInstance;
84 wc.hCursor = LoadCursor(NULL,IDC_ARROW);
85 wc.lpszClassName = classname;
86 if (RegisterClass(&wc))
87 {
88 TCHAR fn2[MAX_PATH];
89 lstrcpy(fn2,fn);
90 lstrcat(fn,_T(".bmp"));
91 lstrcat(fn2,_T(".wav"));
92 g_hbm=LoadImage(NULL,fn,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE);
93 if (g_hbm)
94 {
95 HWND myWnd;
96
97 PlaySound(fn2,NULL,SND_ASYNC|SND_FILENAME|SND_NODEFAULT);
98
99 myWnd = CreateWindowEx(WS_EX_TOOLWINDOW,classname,classname,
100 0,0,0,0,0,(HWND)hwndParent,NULL,g_hInstance,NULL);
101
102 while (IsWindow(myWnd) && GetMessage(&msg,myWnd,0,0))
103 {
104 DispatchMessage(&msg);
105 }
106
107 // Stop currently playing wave, we want to exit
108 PlaySound(0,0,0);
109
110 DeleteObject(g_hbm);
111
112 UnregisterClass(classname, g_hInstance);
113
114 }
115 }
116 }
117 wsprintf(temp,_T("%d"),g_rv);
118 pushstring(temp);
119 }