source: trunk/gsinstaller/gs16bit.cpp@ 1538

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

got 16 bit part compiling on VC++ and gcc

  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1#include <windows.h>
2
3#include <stdlib.h>
4#include <stdio.h>
5
6#include "splash.h"
7#include "bmputil.h"
8
9// define the magic value used in GetWinFlags to show that this application
10// is running on a Windows NT box in 16-bit emulation mode.
11#define WF_WINNT 0x4000
12
13#ifdef _WIN32
14int GetWinFlags()
15{
16 return 0;
17}
18#endif
19
20HWND app_window;
21HINSTANCE app_instance;
22char *app_cmdLine;
23
24typedef void (* splashfn) (HINSTANCE a, unsigned int time);
25typedef HBITMAP (* bmploadfn) (HDC device, LPSTR name);
26
27typedef struct
28{
29 BYTE majorVersion;
30 BYTE minorVersion;
31 WORD buildNumber;
32 BOOL debug;
33} win32sInfo, FAR * lpWin32sInfo;
34
35typedef enum
36{
37 Windows2x, Windows3_0x, Windows3_1x, Windows9x, WindowsNT
38} gs16PlatformId;
39
40typedef struct
41{
42 gs16PlatformId platform;
43 bool win32s;
44} gs16PlatformInfo;
45
46//typedef int FAR PASCAL (* win32sInfoFn)(lpWin32sInfo);
47typedef int (FAR PASCAL * win32sInfoFn)(lpWin32sInfo);
48
49bool GS16bit_checkForWin32s()
50{
51 // HANDLE w32sHandle;
52 HINSTANCE w32sHandle;
53 win32sInfoFn infoFnPtr;
54 win32sInfo w32sInfo;
55 bool reply = false;
56
57 // try to get a handle onto the win32s library
58 w32sHandle = LoadLibrary("W32SYS.DLL");
59
60 // if (w32sHandle > HINSTANCE_ERROR)
61 if (w32sHandle != NULL)
62 {
63 // now get the address of the GetWin32sInfo function
64 infoFnPtr = (win32sInfoFn) GetProcAddress(w32sHandle, "GETWIN32SINFO");
65
66 // if the function exists, we've got win32s1.1 or later
67 if (infoFnPtr != NULL)
68 {
69 if ((*infoFnPtr)((lpWin32sInfo) &w32sInfo) == 0) // no error state
70 {
71 reply = true;
72 }
73 else
74 // error - call didn't work; assume that we have a non-functional
75 // win32s
76 {
77 reply = false;
78 }
79 }
80 // else we've got win32s 1.0. TODO: We need to check if it's actually up and
81 // running;
82 else
83 {
84 reply = true;
85 }
86
87 // we need to free the library before finishing this function
88 FreeLibrary(w32sHandle);
89 }
90 // no win32s at all
91 else
92 {
93 reply = false;
94 }
95
96 return reply;
97}
98
99void GS16bit_getPlatformInfo(gs16PlatformInfo &info)
100{
101 DWORD version = GetVersion();
102
103 /**
104 * NB: Ignore ALL standard information on using GetVersion in the
105 * standard Windows 3.1 SDK and Windows 32-bit SDK documentation;
106 * the latter does not apply, and the former is (slightly but signif-
107 * cantly) misdocumented.
108 *
109 * On 16-bit windows (i.e. this program) take the following comments
110 * as gospel. Also refer to
111 *
112 * http://support.microsoft.com/support/kb/articles/Q131/3/71.asp
113 */
114 BYTE majorVersion = LOBYTE(LOWORD(version));
115 BYTE minorVersion = HIBYTE(LOWORD(version));
116 BYTE dosVersion = HIBYTE(HIWORD(version));
117
118 if (majorVersion < 3)
119 {
120 info.platform = Windows2x;
121 }
122 else if (majorVersion == 3 && minorVersion >= 95)
123 // it's Windows 95 from the
124 // minor version; I guess that
125 // 98 may have minor version == 98,
126 // but I don't know! Hence the
127 // cautious check
128 {
129 info.platform = Windows9x;
130 }
131 else // we're running in "some sort" of Windows 3.x environment
132 {
133 if (minorVersion == 10 && dosVersion == 5)
134 // it could be running under WOW
135 // (16-bit Windows emulation in
136 // Windows NT)
137 {
138 if ((GetWinFlags() & WF_WINNT) == WF_WINNT) // check for NT in emulation mode
139 {
140 info.platform = WindowsNT;
141 }
142 else
143 {
144 info.platform = Windows3_1x;
145 }
146 }
147 else if (minorVersion >= 10) // perhaps Windows 3.11
148 {
149 info.platform = Windows3_1x;
150 }
151 else
152 {
153 info.platform = Windows3_0x;
154 }
155 }
156
157 if (info.platform == Windows3_1x)
158 {
159 info.win32s = GS16bit_checkForWin32s();
160 }
161 else
162 {
163 info.win32s = false;
164 }
165}
166
167void GS16bit_checkWindowsVersion()
168{
169 gs16PlatformInfo platformInfo;
170
171 GS16bit_getPlatformInfo(platformInfo);
172 if (platformInfo.platform == Windows3_0x ||
173 platformInfo.platform == Windows2x)
174 {
175 MessageBox(app_window,
176 "Greenstone cannot be installed on this computer. It requires "
177 "Windows 3.10 or later",
178 "Greenstone Installer",
179 MB_OK);
180 }
181 else if (platformInfo.platform == Windows3_1x &&
182 platformInfo.win32s == false)
183 {
184 MessageBox(app_window,
185 "Greenstone requires 32 bit Windows. Win32s will now be installed "
186 "on your computer to provide this, before continuing with the main "
187 "installation.",
188 "Greenstone Installer",
189 MB_OK);
190 }
191 else
192 {
193 char buffer[20];
194 int result;
195 /* MessageBox(app_window,
196 "Greenstone will now install", "Greenstone Installer", MB_OK);*/
197 result = WinExec("gssetup.exe", SW_SHOWNORMAL);
198 }
199}
200
201long FAR PASCAL GS16bitWindProc(HWND Window,
202 WORD Message,
203 WPARAM wParameter,
204 LPARAM lParameter)
205{
206 long reply = 0;
207
208 switch(Message)
209 {
210 case WM_CREATE:
211 {
212 }
213 break;
214
215 case WM_COMMAND:
216 break;
217
218 case WM_CLOSE:
219 DestroyWindow(Window);
220 return 0L;
221
222 case WM_DESTROY:
223 {
224 PostQuitMessage(0);
225 }
226 break;
227
228 default:
229 return(DefWindowProc(Window, Message, wParameter, lParameter));
230 }
231 return reply;
232}
233
234void GS16bit_init(HINSTANCE instance, int Show)
235{
236 FARPROC showsplash;
237 FARPROC loadbmp;
238 HDC dc;
239 char buffer[20];
240
241 /*
242 dc = GetDC(GetDesktopWindow());
243 bmpUtil loadBitmap(dc, "C:\\gs.bmp");
244 ReleaseDC(GetDesktopWindow(), dc);
245 */
246 // showsplash = MakeProcInstance((FARPROC) splash_show, instance);
247 // (*(splashfn) showsplash)(instance, 3000);
248
249 GS16bit_checkWindowsVersion();
250
251 app_window = CreateWindow("GS16bit:Main", "GreenStone Installer",
252 WS_OVERLAPPEDWINDOW | WS_MINIMIZE | CS_DBLCLKS,
253 CW_USEDEFAULT,
254 0,
255 CW_USEDEFAULT,
256 0,
257 NULL,
258 NULL,
259 app_instance,
260 NULL);
261
262 ShowWindow(app_window, Show);
263
264 PostQuitMessage(0);
265}
266
267void WinClassInit(void)
268{
269 WNDCLASS Class;
270
271 Class.lpszClassName = "GS16bit:Main";
272 Class.hInstance = app_instance;
273 Class.lpfnWndProc = (WNDPROC) GS16bitWindProc;
274 Class.hCursor = LoadCursor(NULL, IDC_ARROW);
275 Class.hIcon = NULL; //LoadIcon(app_instance, "GSInstall");
276 Class.lpszMenuName = NULL;
277 Class.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE+1);
278 // Class.style = NULL;
279 Class.style = 0;
280 Class.cbClsExtra = 0;
281 Class.cbWndExtra = 0;
282 RegisterClass(&Class);
283}
284
285int PASCAL WinMain(HINSTANCE Current,
286 HINSTANCE Previous,
287 LPSTR CmdLine,
288 int CmdShow)
289{
290 MSG msg;
291
292 app_cmdLine = (char *) LocalAlloc(LMEM_FIXED, lstrlen(CmdLine) + 1);
293 lstrcpy(app_cmdLine, CmdLine);
294
295 app_instance = Current;
296 /* -- init application */
297 if (!Previous)
298 {
299 WinClassInit();
300 }
301
302 /* -- init instance */
303 GS16bit_init(Current, CmdShow);
304
305 while (GetMessage(&msg, NULL, 0, 0))
306 {
307 TranslateMessage(&msg);
308 DispatchMessage(&msg);
309 }
310 return (int) msg.wParam;
311}
Note: See TracBrowser for help on using the repository browser.