Mercurial > sdl-ios-xcode
annotate src/main/win32/SDL_main.c @ 563:04dcaf3da918
Massive Quartz input enhancements from Darrell Walisser. His email:
Enclosed is a patch that addresses the following:
--Various minor cleanups.
Removed dead/obsolete code, made some style cleanups
--Mouse Events
Now keep track of what button(s) were pressed so we know when to send
the mouse up event. This fixes the case where the mouse is dragged
outside of the game window and released (in which case we want to send
the mouse up event even though the mouse is outside the game window).
--Input Grabbing
Here is my take on the grabbing situation, which is the basis for the
new implementation.
There are 3 grab states, ungrabbed (UG), visible (VG), and invisible
(IG). Both VG and IG keep the mouse constrained to the window and
produce relative motion events. In VG the cursor is visible (duh), in
IG it is not. In VG, absolute motion events also work.
There are 6 actions that can affect grabbing:
1. Set Fullscreen/Window (F/W). In fullscreen, a visible grab should do
nothing. However, a fullscreen visible grab can be treated just like a
windowed visible grab, which is what I have done to help simplify
things.
2. Cursor hide/show (H/S). If the cursor is hidden when grabbing, the
grab is an invisible grab. If the cursor is visible, the grab should
just constrain the mouse to the window.
3. Input grab/ungrab(G/U). If grabbed, the cursor should be confined to
the window as should the keyboard input. On Mac OS X, the keyboard
input is implicitly grabbed by confining the cursor, except for
command-tab which can switch away from the application. Should the
window come to the foreground if the application is deactivated and
grab input is called? This isn't necessary in this implementation
because the grab state will be asserted upon activation.
Using my notation, these are all the cases that need to be handled
(state + action = new state).
UG+U = UG
UG+G = VG or IG, if cursor is visible or not
UG+H = UG
UG+S = UG
VG+U = UG
VG+G = VG
VG+H = IG
VG+S = VG
IG+U = UG
IG+G = IG
IG+H = IG
IG+S = VG
The cases that result in the same state can be ignored in the code,
which cuts it down to just 5 cases.
Another issue is what happens when the app loses/gains input focus from
deactivate/activate or iconify/deiconify. I think that if input focus
is ever lost (outside of SDL's control), the grab state should be
suspended and the cursor should become visible and active again. When
regained, the cursor should reappear in its original location and/or
grab state. This way, when reactivating the cursor is still in the same
position as before so apps shouldn't get confused when the next motion
event comes in. This is what I've done in this patch.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Fri, 27 Dec 2002 20:52:41 +0000 |
parents | 0ac20b67c2c7 |
children | 1f6438c8df2c |
rev | line source |
---|---|
0 | 1 /* |
2 SDL_main.c, placed in the public domain by Sam Lantinga 4/13/98 | |
3 | |
4 The WinMain function -- calls your program's main() function | |
5 */ | |
6 | |
7 #include <stdio.h> | |
8 #include <string.h> | |
9 #include <ctype.h> | |
10 #include <stdlib.h> | |
11 | |
12 #include <windows.h> | |
13 #include <malloc.h> /* For _alloca() */ | |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
14 #include <io.h> /* For _getcwd() */ |
0 | 15 |
16 /* Include the SDL main definition header */ | |
17 #include "SDL.h" | |
18 #include "SDL_main.h" | |
19 #ifdef main | |
112
9ef74357a5fb
Incorporated slightly modified version of Rainer's WinCE patch
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
20 #ifndef _WIN32_WCE_EMULATION |
0 | 21 #undef main |
22 #endif | |
112
9ef74357a5fb
Incorporated slightly modified version of Rainer's WinCE patch
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
23 #endif |
0 | 24 |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
25 /* Do we really not want stdio redirection with Windows CE? */ |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
26 #ifdef _WIN32_WCE |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
27 #define NO_STDIO_REDIRECT |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
28 #endif |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
29 |
0 | 30 /* The standard output files */ |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
31 #define STDOUT_FILE TEXT("stdout.txt") |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
32 #define STDERR_FILE TEXT("stderr.txt") |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
33 |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
34 #ifndef NO_STDIO_REDIRECT |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
35 static char stdoutPath[MAX_PATH]; |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
36 static char stderrPath[MAX_PATH]; |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
37 #endif |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
38 |
112
9ef74357a5fb
Incorporated slightly modified version of Rainer's WinCE patch
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
39 #if defined(_WIN32_WCE) && _WIN32_WCE < 300 |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
40 /* seems to be undefined in Win CE although in online help */ |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
41 #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t')) |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
42 |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
43 /* seems to be undefined in Win CE although in online help */ |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
44 char *strrchr(char *str, int c) |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
45 { |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
46 char *p; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
47 |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
48 /* Skip to the end of the string */ |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
49 p=str; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
50 while (*p) |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
51 p++; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
52 |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
53 /* Look for the given character */ |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
54 while ( (p >= str) && (*p != (CHAR)c) ) |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
55 p--; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
56 |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
57 /* Return NULL if character not found */ |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
58 if ( p < str ) { |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
59 p = NULL; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
60 } |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
61 return p; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
62 } |
112
9ef74357a5fb
Incorporated slightly modified version of Rainer's WinCE patch
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
63 #endif /* _WIN32_WCE < 300 */ |
0 | 64 |
65 /* Parse a command line buffer into arguments */ | |
66 static int ParseCommandLine(char *cmdline, char **argv) | |
67 { | |
68 char *bufp; | |
69 int argc; | |
70 | |
71 argc = 0; | |
72 for ( bufp = cmdline; *bufp; ) { | |
73 /* Skip leading whitespace */ | |
74 while ( isspace(*bufp) ) { | |
75 ++bufp; | |
76 } | |
77 /* Skip over argument */ | |
78 if ( *bufp == '"' ) { | |
79 ++bufp; | |
80 if ( *bufp ) { | |
81 if ( argv ) { | |
82 argv[argc] = bufp; | |
83 } | |
84 ++argc; | |
85 } | |
86 /* Skip over word */ | |
87 while ( *bufp && (*bufp != '"') ) { | |
88 ++bufp; | |
89 } | |
90 } else { | |
91 if ( *bufp ) { | |
92 if ( argv ) { | |
93 argv[argc] = bufp; | |
94 } | |
95 ++argc; | |
96 } | |
97 /* Skip over word */ | |
98 while ( *bufp && ! isspace(*bufp) ) { | |
99 ++bufp; | |
100 } | |
101 } | |
102 if ( *bufp ) { | |
103 if ( argv ) { | |
104 *bufp = '\0'; | |
105 } | |
106 ++bufp; | |
107 } | |
108 } | |
109 if ( argv ) { | |
110 argv[argc] = NULL; | |
111 } | |
112 return(argc); | |
113 } | |
114 | |
115 /* Show an error message */ | |
116 static void ShowError(const char *title, const char *message) | |
117 { | |
118 /* If USE_MESSAGEBOX is defined, you need to link with user32.lib */ | |
119 #ifdef USE_MESSAGEBOX | |
120 MessageBox(NULL, message, title, MB_ICONEXCLAMATION|MB_OK); | |
121 #else | |
122 fprintf(stderr, "%s: %s\n", title, message); | |
123 #endif | |
124 } | |
125 | |
126 /* Pop up an out of memory message, returns to Windows */ | |
127 static BOOL OutOfMemory(void) | |
128 { | |
129 ShowError("Fatal Error", "Out of memory - aborting"); | |
130 return FALSE; | |
131 } | |
132 | |
133 /* Remove the output files if there was no output written */ | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
134 static void __cdecl cleanup_output(void) |
0 | 135 { |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
136 #ifndef NO_STDIO_REDIRECT |
0 | 137 FILE *file; |
138 int empty; | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
139 #endif |
0 | 140 |
141 /* Flush the output in case anything is queued */ | |
142 fclose(stdout); | |
143 fclose(stderr); | |
144 | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
145 #ifndef NO_STDIO_REDIRECT |
0 | 146 /* See if the files have any output in them */ |
550
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
147 if ( stdoutPath[0] ) { |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
148 file = fopen(stdoutPath, "rb"); |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
149 if ( file ) { |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
150 empty = (fgetc(file) == EOF) ? 1 : 0; |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
151 fclose(file); |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
152 if ( empty ) { |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
153 remove(stdoutPath); |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
154 } |
0 | 155 } |
156 } | |
550
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
157 if ( stderrPath[0] ) { |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
158 file = fopen(stderrPath, "rb"); |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
159 if ( file ) { |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
160 empty = (fgetc(file) == EOF) ? 1 : 0; |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
161 fclose(file); |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
162 if ( empty ) { |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
163 remove(stderrPath); |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
164 } |
0 | 165 } |
166 } | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
167 #endif |
0 | 168 } |
169 | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
170 #if defined(_MSC_VER) && !defined(_WIN32_WCE) |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
171 /* The VC++ compiler needs main defined */ |
0 | 172 #define console_main main |
173 #endif | |
174 | |
175 /* This is where execution begins [console apps] */ | |
176 int console_main(int argc, char *argv[]) | |
177 { | |
178 int n; | |
179 char *bufp, *appname; | |
180 | |
181 /* Get the class name from argv[0] */ | |
182 appname = argv[0]; | |
183 if ( (bufp=strrchr(argv[0], '\\')) != NULL ) { | |
184 appname = bufp+1; | |
185 } else | |
186 if ( (bufp=strrchr(argv[0], '/')) != NULL ) { | |
187 appname = bufp+1; | |
188 } | |
189 | |
190 if ( (bufp=strrchr(appname, '.')) == NULL ) | |
191 n = strlen(appname); | |
192 else | |
193 n = (bufp-appname); | |
194 | |
195 bufp = (char *)alloca(n+1); | |
196 if ( bufp == NULL ) { | |
197 return OutOfMemory(); | |
198 } | |
199 strncpy(bufp, appname, n); | |
200 bufp[n] = '\0'; | |
201 appname = bufp; | |
202 | |
203 /* Load SDL dynamic link library */ | |
204 if ( SDL_Init(SDL_INIT_NOPARACHUTE) < 0 ) { | |
205 ShowError("WinMain() error", SDL_GetError()); | |
206 return(FALSE); | |
207 } | |
208 atexit(cleanup_output); | |
209 atexit(SDL_Quit); | |
210 | |
15
ac67f6758d63
Don't try to register the app if video code is disabled
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
211 #ifndef DISABLE_VIDEO |
149
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
212 #if 0 |
145
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
112
diff
changeset
|
213 /* Create and register our class * |
149
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
214 DJM: If we do this here, the user nevers gets a chance to |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
215 putenv(SDL_WINDOWID). This is already called later by |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
216 the (DIB|DX5)_CreateWindow function, so it should be |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
217 safe to comment it out here. |
0 | 218 if ( SDL_RegisterApp(appname, CS_BYTEALIGNCLIENT, |
219 GetModuleHandle(NULL)) < 0 ) { | |
220 ShowError("WinMain() error", SDL_GetError()); | |
221 exit(1); | |
145
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
112
diff
changeset
|
222 }*/ |
149
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
223 #else |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
224 /* Sam: |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
225 We still need to pass in the application handle so that |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
226 DirectInput will initialize properly when SDL_RegisterApp() |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
227 is called later in the video initialization. |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
228 */ |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
229 SDL_SetModuleHandle(GetModuleHandle(NULL)); |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
230 #endif /* 0 */ |
15
ac67f6758d63
Don't try to register the app if video code is disabled
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
231 #endif /* !DISABLE_VIDEO */ |
ac67f6758d63
Don't try to register the app if video code is disabled
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
232 |
ac67f6758d63
Don't try to register the app if video code is disabled
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
233 /* Run the application main() code */ |
0 | 234 SDL_main(argc, argv); |
235 | |
236 /* Exit cleanly, calling atexit() functions */ | |
237 exit(0); | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
149
diff
changeset
|
238 |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
149
diff
changeset
|
239 /* Hush little compiler, don't you cry... */ |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
149
diff
changeset
|
240 return(0); |
0 | 241 } |
242 | |
243 /* This is where execution begins [windowed apps] */ | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
244 #ifdef _WIN32_WCE |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
245 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR szCmdLine, int sw) |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
246 #else |
0 | 247 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
248 #endif |
0 | 249 { |
250 HINSTANCE handle; | |
251 char **argv; | |
252 int argc; | |
253 char *cmdline; | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
254 #ifdef _WIN32_WCE |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
255 wchar_t *bufp; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
256 int nLen; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
257 #else |
0 | 258 char *bufp; |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
259 #endif |
0 | 260 #ifndef NO_STDIO_REDIRECT |
261 FILE *newfp; | |
262 #endif | |
263 | |
264 /* Start up DDHELP.EXE before opening any files, so DDHELP doesn't | |
265 keep them open. This is a hack.. hopefully it will be fixed | |
266 someday. DDHELP.EXE starts up the first time DDRAW.DLL is loaded. | |
267 */ | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
268 handle = LoadLibrary(TEXT("DDRAW.DLL")); |
0 | 269 if ( handle != NULL ) { |
270 FreeLibrary(handle); | |
271 } | |
272 | |
273 #ifndef NO_STDIO_REDIRECT | |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
274 _getcwd( stdoutPath, sizeof( stdoutPath ) ); |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
275 strcat( stdoutPath, "/" STDOUT_FILE ); |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
276 |
0 | 277 /* Redirect standard input and standard output */ |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
278 newfp = freopen(stdoutPath, "w", stdout); |
0 | 279 if ( newfp == NULL ) { /* This happens on NT */ |
280 #if !defined(stdout) | |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
281 stdout = fopen(stdoutPath, "w"); |
0 | 282 #else |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
283 newfp = fopen(stdoutPath, "w"); |
0 | 284 if ( newfp ) { |
285 *stdout = *newfp; | |
286 } | |
287 #endif | |
288 } | |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
289 |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
290 _getcwd( stderrPath, sizeof( stderrPath ) ); |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
291 strcat( stderrPath, "/" STDERR_FILE ); |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
292 |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
293 newfp = freopen(stderrPath, "w", stderr); |
0 | 294 if ( newfp == NULL ) { /* This happens on NT */ |
295 #if !defined(stderr) | |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
296 stderr = fopen(stderrPath, "w"); |
0 | 297 #else |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
298 newfp = fopen(stderrPath, "w"); |
0 | 299 if ( newfp ) { |
300 *stderr = *newfp; | |
301 } | |
302 #endif | |
303 } | |
304 setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* Line buffered */ | |
305 setbuf(stderr, NULL); /* No buffering */ | |
306 #endif /* !NO_STDIO_REDIRECT */ | |
307 | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
308 #ifdef _WIN32_WCE |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
309 nLen = wcslen(szCmdLine)+128+1; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
310 bufp = (wchar_t *)alloca(nLen*2); |
505
6b34c9dcf74c
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
504
diff
changeset
|
311 wcscpy (bufp, TEXT("\"")); |
504
8c4a35e3c507
Fixed SDL_main.c on Windows CE with applications containing spaces in their names.
Sam Lantinga <slouken@libsdl.org>
parents:
453
diff
changeset
|
312 GetModuleFileName(NULL, bufp+1, 128-3); |
505
6b34c9dcf74c
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
504
diff
changeset
|
313 wcscpy (bufp+wcslen(bufp), TEXT("\" ")); |
112
9ef74357a5fb
Incorporated slightly modified version of Rainer's WinCE patch
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
314 wcsncpy(bufp+wcslen(bufp), szCmdLine,nLen-wcslen(bufp)); |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
315 nLen = wcslen(bufp)+1; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
316 cmdline = (char *)alloca(nLen); |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
317 if ( cmdline == NULL ) { |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
318 return OutOfMemory(); |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
319 } |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
320 WideCharToMultiByte(CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL); |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
321 #else |
0 | 322 /* Grab the command line (use alloca() on Windows) */ |
323 bufp = GetCommandLine(); | |
324 cmdline = (char *)alloca(strlen(bufp)+1); | |
325 if ( cmdline == NULL ) { | |
326 return OutOfMemory(); | |
327 } | |
328 strcpy(cmdline, bufp); | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
329 #endif |
0 | 330 |
331 /* Parse it into argv and argc */ | |
332 argc = ParseCommandLine(cmdline, NULL); | |
333 argv = (char **)alloca((argc+1)*(sizeof *argv)); | |
334 if ( argv == NULL ) { | |
335 return OutOfMemory(); | |
336 } | |
337 ParseCommandLine(cmdline, argv); | |
338 | |
339 /* Run the main program (after a little SDL initialization) */ | |
340 return(console_main(argc, argv)); | |
341 } |