Mercurial > sdl-ios-xcode
annotate src/main/win32/SDL_main.c @ 664:abfdc08eb289
Date: Sun, 3 Aug 2003 22:07:57 +0200
From: Max Horn
Subject: SDL OSX fullscreen FIX
the attached patch fixes the fullscreen problems on SDL/OSX. The cause
was that click events are bounded by winRect. Now, winRect is set to
the size of the video surface. But if you e.g. request a 640x420
surface, you might get a 640x480 "real" surface. Still,
SDL_VideoSurface->h will be set to 420! Thus, the upper 60 pixels in my
example received no mouse down events.
My fix simply disables this clipping when in full screen mode - after
all, all clicks then should be inside the screen surface. Higher SDL
functions ensure that the coordinates then are clipped to 640x420. It
works fine in all my tests here. I don't know if it's the right thing
to do in multi screen scenarios, though.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 04 Aug 2003 01:00:30 +0000 |
parents | 1f6438c8df2c |
children |
rev | line source |
---|---|
0 | 1 /* |
2 SDL_main.c, placed in the public domain by Sam Lantinga 4/13/98 | |
3 | |
575
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
4 The WinMain function -- calls your program's main() function |
0 | 5 */ |
6 | |
7 #include <stdio.h> | |
8 #include <string.h> | |
9 #include <ctype.h> | |
10 #include <stdlib.h> | |
11 | |
12 #include <windows.h> | |
575
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
13 #include <malloc.h> /* For _alloca() */ |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
14 |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
15 #ifdef _WIN32_WCE |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
16 # define DIR_SEPERATOR TEXT("\\") |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
17 # define _getcwd(str,len) wcscpy(str,DIR_SEPERATOR); |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
18 # define setbuf(x) |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
19 # define setvbuf(x) |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
20 # define fopen _wfopen |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
21 # define freopen _wfreopen |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
22 # define remove(x) DeleteFile(x) |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
23 # define strcat wcscat |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
24 #else |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
25 # define DIR_SEPERATOR TEXT("/") |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
26 # include <direct.h> |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
27 #endif |
0 | 28 |
29 /* Include the SDL main definition header */ | |
30 #include "SDL.h" | |
31 #include "SDL_main.h" | |
575
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
32 |
0 | 33 #ifdef main |
575
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
34 # ifndef _WIN32_WCE_EMULATION |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
35 # undef main |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
36 # endif /* _WIN32_WCE_EMULATION */ |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
37 #endif /* main */ |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
38 |
0 | 39 /* The standard output files */ |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
40 #define STDOUT_FILE TEXT("stdout.txt") |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
41 #define STDERR_FILE TEXT("stderr.txt") |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
42 |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
43 #ifndef NO_STDIO_REDIRECT |
575
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
44 # ifdef _WIN32_WCE |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
45 static wchar_t stdoutPath[MAX_PATH]; |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
46 static wchar_t stderrPath[MAX_PATH]; |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
47 # else |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
48 static char stdoutPath[MAX_PATH]; |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
49 static char stderrPath[MAX_PATH]; |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
50 # endif |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
51 #endif |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
52 |
112
9ef74357a5fb
Incorporated slightly modified version of Rainer's WinCE patch
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
53 #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
|
54 /* 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
|
55 #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
|
56 |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
57 /* 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
|
58 char *strrchr(char *str, int c) |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
59 { |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
60 char *p; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
61 |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
62 /* Skip to the end of the string */ |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
63 p=str; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
64 while (*p) |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
65 p++; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
66 |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
67 /* Look for the given character */ |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
68 while ( (p >= str) && (*p != (CHAR)c) ) |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
69 p--; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
70 |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
71 /* Return NULL if character not found */ |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
72 if ( p < str ) { |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
73 p = NULL; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
74 } |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
75 return p; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
76 } |
112
9ef74357a5fb
Incorporated slightly modified version of Rainer's WinCE patch
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
77 #endif /* _WIN32_WCE < 300 */ |
0 | 78 |
79 /* Parse a command line buffer into arguments */ | |
80 static int ParseCommandLine(char *cmdline, char **argv) | |
81 { | |
82 char *bufp; | |
83 int argc; | |
84 | |
85 argc = 0; | |
86 for ( bufp = cmdline; *bufp; ) { | |
87 /* Skip leading whitespace */ | |
88 while ( isspace(*bufp) ) { | |
89 ++bufp; | |
90 } | |
91 /* Skip over argument */ | |
92 if ( *bufp == '"' ) { | |
93 ++bufp; | |
94 if ( *bufp ) { | |
95 if ( argv ) { | |
96 argv[argc] = bufp; | |
97 } | |
98 ++argc; | |
99 } | |
100 /* Skip over word */ | |
101 while ( *bufp && (*bufp != '"') ) { | |
102 ++bufp; | |
103 } | |
104 } else { | |
105 if ( *bufp ) { | |
106 if ( argv ) { | |
107 argv[argc] = bufp; | |
108 } | |
109 ++argc; | |
110 } | |
111 /* Skip over word */ | |
112 while ( *bufp && ! isspace(*bufp) ) { | |
113 ++bufp; | |
114 } | |
115 } | |
116 if ( *bufp ) { | |
117 if ( argv ) { | |
118 *bufp = '\0'; | |
119 } | |
120 ++bufp; | |
121 } | |
122 } | |
123 if ( argv ) { | |
124 argv[argc] = NULL; | |
125 } | |
126 return(argc); | |
127 } | |
128 | |
129 /* Show an error message */ | |
130 static void ShowError(const char *title, const char *message) | |
131 { | |
132 /* If USE_MESSAGEBOX is defined, you need to link with user32.lib */ | |
133 #ifdef USE_MESSAGEBOX | |
134 MessageBox(NULL, message, title, MB_ICONEXCLAMATION|MB_OK); | |
135 #else | |
136 fprintf(stderr, "%s: %s\n", title, message); | |
137 #endif | |
138 } | |
139 | |
140 /* Pop up an out of memory message, returns to Windows */ | |
141 static BOOL OutOfMemory(void) | |
142 { | |
143 ShowError("Fatal Error", "Out of memory - aborting"); | |
144 return FALSE; | |
145 } | |
146 | |
147 /* 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
|
148 static void __cdecl cleanup_output(void) |
0 | 149 { |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
150 #ifndef NO_STDIO_REDIRECT |
0 | 151 FILE *file; |
152 int empty; | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
153 #endif |
0 | 154 |
155 /* Flush the output in case anything is queued */ | |
156 fclose(stdout); | |
157 fclose(stderr); | |
158 | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
159 #ifndef NO_STDIO_REDIRECT |
0 | 160 /* See if the files have any output in them */ |
550
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
161 if ( stdoutPath[0] ) { |
575
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
162 file = fopen(stdoutPath, TEXT("rb")); |
550
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
163 if ( file ) { |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
164 empty = (fgetc(file) == EOF) ? 1 : 0; |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
165 fclose(file); |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
166 if ( empty ) { |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
167 remove(stdoutPath); |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
168 } |
0 | 169 } |
170 } | |
550
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
171 if ( stderrPath[0] ) { |
575
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
172 file = fopen(stderrPath, TEXT("rb")); |
550
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
173 if ( file ) { |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
174 empty = (fgetc(file) == EOF) ? 1 : 0; |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
175 fclose(file); |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
176 if ( empty ) { |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
177 remove(stderrPath); |
0ac20b67c2c7
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
545
diff
changeset
|
178 } |
0 | 179 } |
180 } | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
181 #endif |
0 | 182 } |
183 | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
184 #if defined(_MSC_VER) && !defined(_WIN32_WCE) |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
185 /* The VC++ compiler needs main defined */ |
0 | 186 #define console_main main |
187 #endif | |
188 | |
189 /* This is where execution begins [console apps] */ | |
190 int console_main(int argc, char *argv[]) | |
191 { | |
192 int n; | |
193 char *bufp, *appname; | |
194 | |
195 /* Get the class name from argv[0] */ | |
196 appname = argv[0]; | |
197 if ( (bufp=strrchr(argv[0], '\\')) != NULL ) { | |
198 appname = bufp+1; | |
199 } else | |
200 if ( (bufp=strrchr(argv[0], '/')) != NULL ) { | |
201 appname = bufp+1; | |
202 } | |
203 | |
204 if ( (bufp=strrchr(appname, '.')) == NULL ) | |
205 n = strlen(appname); | |
206 else | |
207 n = (bufp-appname); | |
208 | |
209 bufp = (char *)alloca(n+1); | |
210 if ( bufp == NULL ) { | |
211 return OutOfMemory(); | |
212 } | |
213 strncpy(bufp, appname, n); | |
214 bufp[n] = '\0'; | |
215 appname = bufp; | |
216 | |
217 /* Load SDL dynamic link library */ | |
218 if ( SDL_Init(SDL_INIT_NOPARACHUTE) < 0 ) { | |
219 ShowError("WinMain() error", SDL_GetError()); | |
220 return(FALSE); | |
221 } | |
222 atexit(cleanup_output); | |
223 atexit(SDL_Quit); | |
224 | |
15
ac67f6758d63
Don't try to register the app if video code is disabled
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
225 #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
|
226 #if 0 |
145
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
112
diff
changeset
|
227 /* 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
|
228 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
|
229 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
|
230 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
|
231 safe to comment it out here. |
0 | 232 if ( SDL_RegisterApp(appname, CS_BYTEALIGNCLIENT, |
233 GetModuleHandle(NULL)) < 0 ) { | |
234 ShowError("WinMain() error", SDL_GetError()); | |
235 exit(1); | |
145
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
112
diff
changeset
|
236 }*/ |
149
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
237 #else |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
238 /* Sam: |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
239 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
|
240 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
|
241 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
|
242 */ |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
243 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
|
244 #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
|
245 #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
|
246 |
ac67f6758d63
Don't try to register the app if video code is disabled
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
247 /* Run the application main() code */ |
0 | 248 SDL_main(argc, argv); |
249 | |
250 /* Exit cleanly, calling atexit() functions */ | |
251 exit(0); | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
149
diff
changeset
|
252 |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
149
diff
changeset
|
253 /* Hush little compiler, don't you cry... */ |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
149
diff
changeset
|
254 return(0); |
0 | 255 } |
256 | |
257 /* 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
|
258 #ifdef _WIN32_WCE |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
259 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
|
260 #else |
0 | 261 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
|
262 #endif |
0 | 263 { |
264 HINSTANCE handle; | |
265 char **argv; | |
266 int argc; | |
267 char *cmdline; | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
268 #ifdef _WIN32_WCE |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
269 wchar_t *bufp; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
270 int nLen; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
271 #else |
0 | 272 char *bufp; |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
273 #endif |
0 | 274 #ifndef NO_STDIO_REDIRECT |
275 FILE *newfp; | |
276 #endif | |
277 | |
278 /* Start up DDHELP.EXE before opening any files, so DDHELP doesn't | |
279 keep them open. This is a hack.. hopefully it will be fixed | |
280 someday. DDHELP.EXE starts up the first time DDRAW.DLL is loaded. | |
281 */ | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
282 handle = LoadLibrary(TEXT("DDRAW.DLL")); |
0 | 283 if ( handle != NULL ) { |
284 FreeLibrary(handle); | |
285 } | |
286 | |
287 #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
|
288 _getcwd( stdoutPath, sizeof( stdoutPath ) ); |
575
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
289 strcat( stdoutPath, DIR_SEPERATOR STDOUT_FILE ); |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
290 |
0 | 291 /* Redirect standard input and standard output */ |
575
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
292 newfp = freopen(stdoutPath, TEXT("w"), stdout); |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
293 |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
294 #ifndef _WIN32_WCE |
0 | 295 if ( newfp == NULL ) { /* This happens on NT */ |
296 #if !defined(stdout) | |
575
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
297 stdout = fopen(stdoutPath, TEXT("w")); |
0 | 298 #else |
575
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
299 newfp = fopen(stdoutPath, TEXT("w")); |
0 | 300 if ( newfp ) { |
301 *stdout = *newfp; | |
302 } | |
303 #endif | |
304 } | |
575
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
305 #endif /* _WIN32_WCE */ |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
306 |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
307 _getcwd( stderrPath, sizeof( stderrPath ) ); |
575
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
308 strcat( stderrPath, DIR_SEPERATOR STDERR_FILE ); |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
309 |
575
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
310 newfp = freopen(stderrPath, TEXT("w"), stderr); |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
311 #ifndef _WIN32_WCE |
0 | 312 if ( newfp == NULL ) { /* This happens on NT */ |
313 #if !defined(stderr) | |
575
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
314 stderr = fopen(stderrPath, TEXT("w")); |
0 | 315 #else |
575
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
316 newfp = fopen(stderrPath, TEXT("w")); |
0 | 317 if ( newfp ) { |
318 *stderr = *newfp; | |
319 } | |
320 #endif | |
321 } | |
575
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
322 #endif /* _WIN32_WCE */ |
1f6438c8df2c
Applied Corona688's patch for output redirection on Windows CE
Sam Lantinga <slouken@libsdl.org>
parents:
550
diff
changeset
|
323 |
0 | 324 setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* Line buffered */ |
325 setbuf(stderr, NULL); /* No buffering */ | |
326 #endif /* !NO_STDIO_REDIRECT */ | |
327 | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
328 #ifdef _WIN32_WCE |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
329 nLen = wcslen(szCmdLine)+128+1; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
330 bufp = (wchar_t *)alloca(nLen*2); |
505
6b34c9dcf74c
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
504
diff
changeset
|
331 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
|
332 GetModuleFileName(NULL, bufp+1, 128-3); |
505
6b34c9dcf74c
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
504
diff
changeset
|
333 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
|
334 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
|
335 nLen = wcslen(bufp)+1; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
336 cmdline = (char *)alloca(nLen); |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
337 if ( cmdline == NULL ) { |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
338 return OutOfMemory(); |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
339 } |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
340 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
|
341 #else |
0 | 342 /* Grab the command line (use alloca() on Windows) */ |
343 bufp = GetCommandLine(); | |
344 cmdline = (char *)alloca(strlen(bufp)+1); | |
345 if ( cmdline == NULL ) { | |
346 return OutOfMemory(); | |
347 } | |
348 strcpy(cmdline, bufp); | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
349 #endif |
0 | 350 |
351 /* Parse it into argv and argc */ | |
352 argc = ParseCommandLine(cmdline, NULL); | |
353 argv = (char **)alloca((argc+1)*(sizeof *argv)); | |
354 if ( argv == NULL ) { | |
355 return OutOfMemory(); | |
356 } | |
357 ParseCommandLine(cmdline, argv); | |
358 | |
359 /* Run the main program (after a little SDL initialization) */ | |
360 return(console_main(argc, argv)); | |
361 } |