comparison src/video/wincommon/SDL_syswm.c @ 4088:cbe2f23a1c2b SDL-1.2

Fixed window titles on Windows 95/98/ME
author Sam Lantinga <slouken@libsdl.org>
date Mon, 23 Jul 2007 01:19:56 +0000
parents d13618a935a2
children a1b03ba2fcd0
comparison
equal deleted inserted replaced
4087:4867f7f7dd34 4088:cbe2f23a1c2b
215 /* WinCE uses the UNICODE version */ 215 /* WinCE uses the UNICODE version */
216 LPWSTR lpszW = SDL_iconv_utf8_ucs2((char *)title); 216 LPWSTR lpszW = SDL_iconv_utf8_ucs2((char *)title);
217 SetWindowText(SDL_Window, lpszW); 217 SetWindowText(SDL_Window, lpszW);
218 SDL_free(lpszW); 218 SDL_free(lpszW);
219 #else 219 #else
220 /*
221 * Try loading SetWindowTextW from kernel32.dll first, and if it exists,
222 * pass the UCS-2 string to it. If it doesn't, use
223 * WideCharToMultiByte(CP_ACP) and hope that the codepage can support the
224 * string data in question. This lets us keep binary compatibility with
225 * Win95/98/ME but still use saner Unicode on NT-based Windows.
226 */
227 static int tried_loading = 0;
228 static PtrSetWindowTextW swtw = NULL;
229 Uint16 *lpsz = SDL_iconv_utf8_ucs2(title); 220 Uint16 *lpsz = SDL_iconv_utf8_ucs2(title);
230 if (!tried_loading) { 221 size_t len = WideCharToMultiByte(CP_ACP, 0, lpsz, -1, NULL, 0, NULL, NULL);
231 HMODULE dll = LoadLibrary("user32.dll"); 222 char *cvt = SDL_stack_alloc(char, len + 1);
232 if (dll != NULL) { 223 WideCharToMultiByte(CP_ACP, 0, lpsz, -1, cvt, len, NULL, NULL);
233 swtw = (PtrSetWindowTextW) GetProcAddress(dll, "SetWindowTextW"); 224 SetWindowText(SDL_Window, cvt);
234 if (swtw == NULL) { 225 SDL_stack_free(cvt);
235 FreeLibrary(dll);
236 }
237 }
238 tried_loading = 1;
239 }
240
241 if (swtw != NULL) {
242 swtw(SDL_Window, lpsz);
243 } else {
244 size_t len = WideCharToMultiByte(CP_ACP, 0, lpsz, -1, NULL, 0, NULL, NULL);
245 char *cvt = SDL_malloc(len + 1);
246 WideCharToMultiByte(CP_ACP, 0, lpsz, -1, cvt, len, NULL, NULL);
247 SetWindowText(SDL_Window, cvt);
248 SDL_free(cvt);
249 }
250 SDL_free(lpsz); 226 SDL_free(lpsz);
251 #endif 227 #endif
252 } 228 }
253 229
254 int WIN_IconifyWindow(_THIS) 230 int WIN_IconifyWindow(_THIS)