src/video/wincommon/SDL_syswm.c
branchSDL-1.2
changeset 3919 d13618a935a2
parent 3869 b0955ae208f3
child 4088 cbe2f23a1c2b
equal deleted inserted replaced
3918:f16c15f3bc2b 3919:d13618a935a2
   205 	}
   205 	}
   206 	SDL_stack_free(icon_win32);
   206 	SDL_stack_free(icon_win32);
   207 #endif /* DISABLE_ICON_SUPPORT */
   207 #endif /* DISABLE_ICON_SUPPORT */
   208 }
   208 }
   209 
   209 
       
   210 typedef BOOL (WINAPI *PtrSetWindowTextW)(HWND hWnd, LPCWSTR lpString);
       
   211 
   210 void WIN_SetWMCaption(_THIS, const char *title, const char *icon)
   212 void WIN_SetWMCaption(_THIS, const char *title, const char *icon)
   211 {
   213 {
   212 #ifdef _WIN32_WCE
   214 #ifdef _WIN32_WCE
   213 	/* WinCE uses the UNICODE version */
   215 	/* WinCE uses the UNICODE version */
   214 	LPWSTR lpszW = SDL_iconv_utf8_ucs2((char *)title);
   216 	LPWSTR lpszW = SDL_iconv_utf8_ucs2((char *)title);
   215 	SetWindowText(SDL_Window, lpszW);
   217 	SetWindowText(SDL_Window, lpszW);
   216 	SDL_free(lpszW);
   218 	SDL_free(lpszW);
   217 #else
   219 #else
   218 	char *lpsz = SDL_iconv_utf8_latin1((char *)title);
   220 	/*
   219 	SetWindowText(SDL_Window, lpsz);
   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);
       
   230 	if (!tried_loading) {
       
   231 		HMODULE dll = LoadLibrary("user32.dll");
       
   232 		if (dll != NULL) {
       
   233 			swtw = (PtrSetWindowTextW) GetProcAddress(dll, "SetWindowTextW");
       
   234 			if (swtw == NULL) {
       
   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 	}
   220 	SDL_free(lpsz);
   250 	SDL_free(lpsz);
   221 #endif
   251 #endif
   222 }
   252 }
   223 
   253 
   224 int WIN_IconifyWindow(_THIS)
   254 int WIN_IconifyWindow(_THIS)