source: trunk/gsinstaller/gs16bit.cpp@ 1539

Last change on this file since 1539 was 1539, checked in by sjboddie, 24 years ago

Got compiling on VC++ 4.2

  • Property svn:keywords set to Author Date Id Revision
File size: 10.0 KB
Line 
1#include "Splash.h"
2
3
4
5UINT timer;
6
7HWND splash_window;
8
9BOOL splash_done;
10
11HBITMAP splash_bmp;
12
13int splash_bmpheight;
14
15
16
17void CALLBACK splash_timerproc(HWND Window, UINT Message, UINT id, DWORD time)
18
19{ splash_done = TRUE;
20
21 KillTimer(NULL, 0);
22
23}
24
25
26
27long FAR PASCAL _export splash_windproc(HWND Window, UINT Message, WPARAM wParameter, LPARAM lParameter)
28
29{ switch (Message)
30
31 { case WM_CREATE:
32
33 { timer = SetTimer(NULL, 0, 3000, (TIMERPROC) splash_timerproc);
34
35 }
36
37 break;
38
39
40
41 case WM_TIMER: // valid id; just kill window after timer elapses
42
43 splash_done = TRUE;
44
45 KillTimer(Window, 0);
46
47 break;
48
49
50
51 case WM_DESTROY:
52
53 splash_window = 0;
54
55 break;
56
57
58
59 case WM_PAINT:
60
61 { PAINTSTRUCT PaintInfo;
62
63 HDC dc, bmpDC;
64
65 BITMAP bmpData;
66
67 POINT origin, size;
68
69
70
71 dc = BeginPaint(Window, &PaintInfo);
72
73 bmpDC = CreateCompatibleDC(dc);
74
75 SelectObject(bmpDC, splash_bmp);
76
77
78
79 GetObject(splash_bmp, sizeof(BITMAP), (LPVOID) &bmpData);
80
81
82
83 size.x = bmpData.bmWidth;
84
85 size.y = bmpData.bmHeight;
86
87 DPtoLP(dc, &size, 1);
88
89
90
91 origin.x = 0;
92
93 origin.y = 0;
94
95 DPtoLP(dc, &origin, 1);
96
97
98
99 BitBlt(dc, 0, 0, size.x, size.y,
100
101 bmpDC, origin.x, origin.y, SRCCOPY);
102
103
104
105 DeleteDC(bmpDC);
106
107 EndPaint(Window, &PaintInfo);
108
109 }
110
111 break;
112
113
114
115 case WM_COMMAND:
116
117 break;
118
119
120
121 default:
122
123 return(DefWindowProc(Window, Message, wParameter, lParameter));
124
125 }
126
127 return 0L;
128
129}
130
131
132
133void splash_register(HINSTANCE instance)
134
135{ WNDCLASS Class;
136
137 static bool registered = false;
138
139 if (registered == false)
140
141 { Class.lpszClassName = "Generic:Splash";
142
143 Class.hInstance = instance;
144
145 Class.lpfnWndProc = (WNDPROC) splash_windproc;
146
147 Class.hCursor = LoadCursor(NULL, IDC_ARROW);
148
149 Class.hIcon = NULL;
150
151 Class.lpszMenuName = NULL;
152
153 Class.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
154
155 Class.style = NULL;
156
157 Class.cbClsExtra = 0;
158
159 Class.cbWndExtra = 0;
160
161 RegisterClass(&Class);
162
163 registered = TRUE;
164
165 }
166
167}
168
169
170
171void _export splash_show(HINSTANCE instance, unsigned int time)
172
173{ MSG msg;
174
175 RECT r;
176
177 BITMAP bmpData;
178
179 POINT size;
180
181 int sx, sy;
182
183 HDC dc;
184
185
186
187 splash_register(instance);
188
189
190
191 splash_bmp = LoadBitmap(instance, (LPCSTR) MAKEINTRESOURCE(9007));
192
193 splash_done = FALSE;
194
195
196
197 GetObject(splash_bmp, sizeof(BITMAP), (LPVOID) &bmpData);
198
199 size.x = bmpData.bmWidth;
200
201 size.y = bmpData.bmHeight;
202
203
204
205 r.left = 0;
206
207 r.top = 0;
208
209 r.right = size.x;
210
211 r.bottom = size.y;
212
213 AdjustWindowRect(&r, 0, TRUE);
214
215
216
217 splash_bmpheight = size.y;
218
219 dc = GetDC(GetDesktopWindow());
220
221 sx = GetDeviceCaps(dc, HORZRES);
222
223 sy = GetDeviceCaps(dc, VERTRES);
224
225 ReleaseDC(GetDesktopWindow(), dc);
226
227
228
229 splash_window = CreateWindow("Generic:Splash", "Greenstone Installer",
230
231 WS_DLGFRAME | WS_VISIBLE,
232
233 (sx - r.right + r.left) / 2,
234
235 (sy - r.bottom + r.top) / 2,
236
237 r.right-r.left, r.bottom-r.top,
238
239 0, 0, instance, NULL);
240
241 while (GetMessage(&msg, NULL, NULL, NULL) &&
242
243 splash_done == FALSE)
244
245 { if (msg.message == WM_TIMER)
246
247 { msg.hwnd = splash_window;
248
249 }
250
251 TranslateMessage(&msg);
252
253 DispatchMessage(&msg);
254
255 }
256
257 DestroyWindow(splash_window);
258
259}
260
261
262
263#include <windows.h>
264
265#include <stdlib.h>
266#include <stdio.h>
267
268#include "splash.h"
269#include "bmputil.h"
270
271// define the magic value used in GetWinFlags to show that this application
272// is running on a Windows NT box in 16-bit emulation mode.
273#define WF_WINNT 0x4000
274
275#ifdef _WIN32
276int GetWinFlags()
277{
278 return 0;
279}
280#endif
281
282HWND app_window;
283HINSTANCE app_instance;
284char *app_cmdLine;
285
286typedef void (* splashfn) (HINSTANCE a, unsigned int time);
287typedef HBITMAP (* bmploadfn) (HDC device, LPSTR name);
288
289typedef struct
290{
291 BYTE majorVersion;
292 BYTE minorVersion;
293 WORD buildNumber;
294 BOOL debug;
295} win32sInfo, FAR * lpWin32sInfo;
296
297typedef enum
298{
299 Windows2x, Windows3_0x, Windows3_1x, Windows9x, WindowsNT
300} gs16PlatformId;
301
302typedef struct
303{
304 gs16PlatformId platform;
305 bool win32s;
306} gs16PlatformInfo;
307
308//typedef int FAR PASCAL (* win32sInfoFn)(lpWin32sInfo);
309typedef int (FAR PASCAL * win32sInfoFn)(lpWin32sInfo);
310
311bool GS16bit_checkForWin32s()
312{
313 // HANDLE w32sHandle;
314 HINSTANCE w32sHandle;
315 win32sInfoFn infoFnPtr;
316 win32sInfo w32sInfo;
317 bool reply = false;
318
319 // try to get a handle onto the win32s library
320 w32sHandle = LoadLibrary("W32SYS.DLL");
321
322 // if (w32sHandle > HINSTANCE_ERROR)
323 if (w32sHandle != NULL)
324 {
325 // now get the address of the GetWin32sInfo function
326 infoFnPtr = (win32sInfoFn) GetProcAddress(w32sHandle, "GETWIN32SINFO");
327
328 // if the function exists, we've got win32s1.1 or later
329 if (infoFnPtr != NULL)
330 {
331 if ((*infoFnPtr)((lpWin32sInfo) &w32sInfo) == 0) // no error state
332 {
333 reply = true;
334 }
335 else
336 // error - call didn't work; assume that we have a non-functional
337 // win32s
338 {
339 reply = false;
340 }
341 }
342 // else we've got win32s 1.0. TODO: We need to check if it's actually up and
343 // running;
344 else
345 {
346 reply = true;
347 }
348
349 // we need to free the library before finishing this function
350 FreeLibrary(w32sHandle);
351 }
352 // no win32s at all
353 else
354 {
355 reply = false;
356 }
357
358 return reply;
359}
360
361void GS16bit_getPlatformInfo(gs16PlatformInfo &info)
362{
363 DWORD version = GetVersion();
364
365 /**
366 * NB: Ignore ALL standard information on using GetVersion in the
367 * standard Windows 3.1 SDK and Windows 32-bit SDK documentation;
368 * the latter does not apply, and the former is (slightly but signif-
369 * cantly) misdocumented.
370 *
371 * On 16-bit windows (i.e. this program) take the following comments
372 * as gospel. Also refer to
373 *
374 * http://support.microsoft.com/support/kb/articles/Q131/3/71.asp
375 */
376 BYTE majorVersion = LOBYTE(LOWORD(version));
377 BYTE minorVersion = HIBYTE(LOWORD(version));
378 BYTE dosVersion = HIBYTE(HIWORD(version));
379
380 if (majorVersion < 3)
381 {
382 info.platform = Windows2x;
383 }
384 else if (majorVersion == 3 && minorVersion >= 95)
385 // it's Windows 95 from the
386 // minor version; I guess that
387 // 98 may have minor version == 98,
388 // but I don't know! Hence the
389 // cautious check
390 {
391 info.platform = Windows9x;
392 }
393 else // we're running in "some sort" of Windows 3.x environment
394 {
395 if (minorVersion == 10 && dosVersion == 5)
396 // it could be running under WOW
397 // (16-bit Windows emulation in
398 // Windows NT)
399 {
400 if ((GetWinFlags() & WF_WINNT) == WF_WINNT) // check for NT in emulation mode
401 {
402 info.platform = WindowsNT;
403 }
404 else
405 {
406 info.platform = Windows3_1x;
407 }
408 }
409 else if (minorVersion >= 10) // perhaps Windows 3.11
410 {
411 info.platform = Windows3_1x;
412 }
413 else
414 {
415 info.platform = Windows3_0x;
416 }
417 }
418
419 if (info.platform == Windows3_1x)
420 {
421 info.win32s = GS16bit_checkForWin32s();
422 }
423 else
424 {
425 info.win32s = false;
426 }
427}
428
429void GS16bit_checkWindowsVersion()
430{
431 gs16PlatformInfo platformInfo;
432
433 GS16bit_getPlatformInfo(platformInfo);
434 if (platformInfo.platform == Windows3_0x ||
435 platformInfo.platform == Windows2x)
436 {
437 MessageBox(app_window,
438 "Greenstone cannot be installed on this computer. It requires "
439 "Windows 3.10 or later",
440 "Greenstone Installer",
441 MB_OK);
442 }
443 else if (platformInfo.platform == Windows3_1x &&
444 platformInfo.win32s == false)
445 {
446 MessageBox(app_window,
447 "Greenstone requires 32 bit Windows. Win32s will now be installed "
448 "on your computer to provide this, before continuing with the main "
449 "installation.",
450 "Greenstone Installer",
451 MB_OK);
452 }
453 else
454 {
455 char buffer[20];
456 int result;
457 /* MessageBox(app_window,
458 "Greenstone will now install", "Greenstone Installer", MB_OK);*/
459 result = WinExec("gssetup.exe", SW_SHOWNORMAL);
460 }
461}
462
463long FAR PASCAL GS16bitWindProc(HWND Window,
464 WORD Message,
465 WPARAM wParameter,
466 LPARAM lParameter)
467{
468 long reply = 0;
469
470 switch(Message)
471 {
472 case WM_CREATE:
473 {
474 }
475 break;
476
477 case WM_COMMAND:
478 break;
479
480 case WM_CLOSE:
481 DestroyWindow(Window);
482 return 0L;
483
484 case WM_DESTROY:
485 {
486 PostQuitMessage(0);
487 }
488 break;
489
490 default:
491 return(DefWindowProc(Window, Message, wParameter, lParameter));
492 }
493 return reply;
494}
495
496void GS16bit_init(HINSTANCE instance, int Show)
497{
498 FARPROC showsplash;
499 FARPROC loadbmp;
500 HDC dc;
501 char buffer[20];
502
503 /*
504 dc = GetDC(GetDesktopWindow());
505 bmpUtil loadBitmap(dc, "C:\\gs.bmp");
506 ReleaseDC(GetDesktopWindow(), dc);
507 */
508 // showsplash = MakeProcInstance((FARPROC) splash_show, instance);
509 // (*(splashfn) showsplash)(instance, 3000);
510
511 GS16bit_checkWindowsVersion();
512
513 app_window = CreateWindow("GS16bit:Main", "GreenStone Installer",
514 WS_OVERLAPPEDWINDOW | WS_MINIMIZE | CS_DBLCLKS,
515 CW_USEDEFAULT,
516 0,
517 CW_USEDEFAULT,
518 0,
519 NULL,
520 NULL,
521 app_instance,
522 NULL);
523
524 ShowWindow(app_window, Show);
525
526 PostQuitMessage(0);
527}
528
529void WinClassInit(void)
530{
531 WNDCLASS Class;
532
533 Class.lpszClassName = "GS16bit:Main";
534 Class.hInstance = app_instance;
535 Class.lpfnWndProc = (WNDPROC) GS16bitWindProc;
536 Class.hCursor = LoadCursor(NULL, IDC_ARROW);
537 Class.hIcon = NULL; //LoadIcon(app_instance, "GSInstall");
538 Class.lpszMenuName = NULL;
539 Class.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE+1);
540 // Class.style = NULL;
541 Class.style = 0;
542 Class.cbClsExtra = 0;
543 Class.cbWndExtra = 0;
544 RegisterClass(&Class);
545}
546
547int PASCAL WinMain(HINSTANCE Current,
548 HINSTANCE Previous,
549 LPSTR CmdLine,
550 int CmdShow)
551{
552 MSG msg;
553
554 app_cmdLine = (char *) LocalAlloc(LMEM_FIXED, lstrlen(CmdLine) + 1);
555 lstrcpy(app_cmdLine, CmdLine);
556
557 app_instance = Current;
558 /* -- init application */
559 if (!Previous)
560 {
561 WinClassInit();
562 }
563
564 /* -- init instance */
565 GS16bit_init(Current, CmdShow);
566
567 while (GetMessage(&msg, NULL, 0, 0))
568 {
569 TranslateMessage(&msg);
570 DispatchMessage(&msg);
571 }
572 return (int) msg.wParam;
573}
Note: See TracBrowser for help on using the repository browser.