src/video/wincommon/SDL_sysevents.c
author Sam Lantinga
Sat, 29 Dec 2007 06:08:17 +0000
branchSDL-1.2
changeset 4113 82dab719502e
parent 4011 f5794774970d
child 4157 baf615f9f2a0
permissions -rw-r--r--
Fixed bug #464
Added X1/X2 button constants
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@0
    23
slouken@1433
    24
#define WIN32_LEAN_AND_MEAN
slouken@1433
    25
#include <windows.h>
slouken@0
    26
icculus@3970
    27
/* Make sure XBUTTON stuff is defined that isn't in older Platform SDKs... */
icculus@3970
    28
#ifndef WM_XBUTTONDOWN
icculus@3970
    29
#define WM_XBUTTONDOWN 0x020B
icculus@3970
    30
#endif
icculus@3970
    31
#ifndef WM_XBUTTONUP
icculus@3970
    32
#define WM_XBUTTONUP 0x020C
icculus@3970
    33
#endif
icculus@3970
    34
#ifndef GET_XBUTTON_WPARAM
icculus@3970
    35
#define GET_XBUTTON_WPARAM(w) (HIWORD(w))
icculus@3970
    36
#endif
icculus@3970
    37
slouken@0
    38
#include "SDL_events.h"
slouken@0
    39
#include "SDL_video.h"
slouken@0
    40
#include "SDL_syswm.h"
slouken@1361
    41
#include "../SDL_sysvideo.h"
slouken@1361
    42
#include "../../events/SDL_sysevents.h"
slouken@1361
    43
#include "../../events/SDL_events_c.h"
slouken@0
    44
#include "SDL_lowvideo.h"
slouken@0
    45
#include "SDL_syswm_c.h"
slouken@0
    46
#include "SDL_main.h"
icculus@1152
    47
#include "SDL_loadso.h"
slouken@0
    48
slouken@0
    49
#ifdef WMMSG_DEBUG
slouken@0
    50
#include "wmmsg.h"
slouken@0
    51
#endif
slouken@0
    52
slouken@0
    53
#ifdef _WIN32_WCE
slouken@1465
    54
#include "../gapi/SDL_gapivideo.h"
slouken@1465
    55
slouken@1465
    56
#define IsZoomed(HWND) 1
slouken@0
    57
#define NO_GETKEYBOARDSTATE
slouken@1465
    58
#if _WIN32_WCE < 420
slouken@453
    59
#define NO_CHANGEDISPLAYSETTINGS
slouken@0
    60
#endif
slouken@1465
    61
#endif
slouken@0
    62
slouken@0
    63
/* The window we use for everything... */
slouken@453
    64
#ifdef _WIN32_WCE
slouken@453
    65
LPWSTR SDL_Appname = NULL;
slouken@453
    66
#else
slouken@453
    67
LPSTR SDL_Appname = NULL;
slouken@453
    68
#endif
slouken@1288
    69
Uint32 SDL_Appstyle = 0;
slouken@0
    70
HINSTANCE SDL_Instance = NULL;
slouken@0
    71
HWND SDL_Window = NULL;
slouken@0
    72
RECT SDL_bounds = {0, 0, 0, 0};
slouken@833
    73
int SDL_windowX = 0;
slouken@833
    74
int SDL_windowY = 0;
slouken@0
    75
int SDL_resizing = 0;
slouken@0
    76
int mouse_relative = 0;
slouken@0
    77
int posted = 0;
slouken@304
    78
#ifndef NO_CHANGEDISPLAYSETTINGS
slouken@1295
    79
DEVMODE SDL_desktop_mode;
slouken@304
    80
DEVMODE SDL_fullscreen_mode;
slouken@304
    81
#endif
slouken@338
    82
WORD *gamma_saved = NULL;
slouken@0
    83
slouken@0
    84
slouken@0
    85
/* Functions called by the message processing function */
icculus@1152
    86
LONG (*HandleMessage)(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)=NULL;
slouken@3992
    87
void (*WIN_Activate)(_THIS, BOOL active, BOOL iconic);
slouken@0
    88
void (*WIN_RealizePalette)(_THIS);
slouken@0
    89
void (*WIN_PaletteChanged)(_THIS, HWND window);
slouken@0
    90
void (*WIN_WinPAINT)(_THIS, HDC hdc);
slouken@338
    91
extern void DIB_SwapGamma(_THIS);
slouken@0
    92
slouken@1272
    93
#ifndef NO_GETKEYBOARDSTATE
slouken@1253
    94
/* Variables and support functions for SDL_ToUnicode() */
slouken@1253
    95
static int codepage;
slouken@1253
    96
static int Is9xME();
slouken@1253
    97
static int GetCodePage();
slouken@1428
    98
static int WINAPI ToUnicode9xME(UINT vkey, UINT scancode, BYTE *keystate, LPWSTR wchars, int wsize, UINT flags);
slouken@1253
    99
slouken@1253
   100
ToUnicodeFN SDL_ToUnicode = ToUnicode9xME;
slouken@1272
   101
#endif /* !NO_GETKEYBOARDSTATE */
slouken@1253
   102
slouken@1253
   103
icculus@1152
   104
#if defined(_WIN32_WCE)
icculus@1152
   105
icculus@1152
   106
// dynamically load aygshell dll because we want SDL to work on HPC and be300
icculus@1152
   107
HINSTANCE aygshell = NULL;
icculus@1152
   108
BOOL (WINAPI *SHFullScreen)(HWND hwndRequester, DWORD dwState) = 0;
icculus@1152
   109
icculus@1152
   110
#define SHFS_SHOWTASKBAR            0x0001
icculus@1152
   111
#define SHFS_HIDETASKBAR            0x0002
icculus@1152
   112
#define SHFS_SHOWSIPBUTTON          0x0004
icculus@1152
   113
#define SHFS_HIDESIPBUTTON          0x0008
icculus@1152
   114
#define SHFS_SHOWSTARTICON          0x0010
icculus@1152
   115
#define SHFS_HIDESTARTICON          0x0020
icculus@1152
   116
icculus@1152
   117
static void LoadAygshell(void)
icculus@1152
   118
{
icculus@1152
   119
	if( !aygshell )
icculus@1152
   120
		 aygshell = SDL_LoadObject("aygshell.dll");
slouken@1497
   121
	if( (aygshell != 0) && (SHFullScreen == 0) )
icculus@1152
   122
	{
icculus@1152
   123
		SHFullScreen = (int (WINAPI *)(struct HWND__ *,unsigned long)) SDL_LoadFunction(aygshell, "SHFullScreen");
icculus@1152
   124
	}
icculus@1152
   125
}
icculus@1152
   126
icculus@1251
   127
/* for gapi landscape mode */
icculus@1251
   128
static void GapiTransform(SDL_ScreenOrientation rotate, char hires, Sint16 *x, Sint16 *y) {
icculus@1251
   129
	Sint16 rotatedX;
icculus@1251
   130
	Sint16 rotatedY;
icculus@1251
   131
icculus@1251
   132
	if (hires) {
icculus@1251
   133
		*x = *x * 2;
icculus@1251
   134
		*y = *y * 2;
icculus@1251
   135
	}
icculus@1251
   136
icculus@1251
   137
	switch(rotate) {
icculus@1251
   138
		case SDL_ORIENTATION_UP:
slouken@1465
   139
			{
slouken@1465
   140
/* this code needs testing on a real device!
slouken@1465
   141
   So it will be enabled later */
slouken@1465
   142
/*
slouken@1465
   143
#ifdef _WIN32_WCE
slouken@1465
   144
#if _WIN32_WCE >= 420
slouken@1465
   145
				// test device orientation
slouken@1465
   146
				// FIXME: do not check every mouse message
slouken@1465
   147
				DEVMODE settings;
slouken@1465
   148
				SDL_memset(&settings, 0, sizeof(DEVMODE));
slouken@1465
   149
				settings.dmSize = sizeof(DEVMODE);
slouken@1465
   150
				settings.dmFields = DM_DISPLAYORIENTATION;
slouken@1465
   151
				ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL);
slouken@1465
   152
				if( settings.dmOrientation == DMDO_90 )
slouken@1465
   153
				{
slouken@1465
   154
					rotatedX = SDL_VideoSurface->h - *x;
slouken@1465
   155
					rotatedY = *y;
slouken@1465
   156
					*x = rotatedX;
slouken@1465
   157
					*y = rotatedY;
slouken@1465
   158
				}
slouken@1465
   159
#endif
slouken@1465
   160
#endif */
slouken@1465
   161
			}
icculus@1251
   162
			break;
icculus@1251
   163
		case SDL_ORIENTATION_RIGHT:
icculus@1251
   164
			if (!SDL_VideoSurface)
icculus@1251
   165
				break;
icculus@1251
   166
			rotatedX = SDL_VideoSurface->w - *y;
icculus@1251
   167
			rotatedY = *x;
icculus@1251
   168
			*x = rotatedX;
icculus@1251
   169
			*y = rotatedY;
icculus@1251
   170
			break;
icculus@1251
   171
		case SDL_ORIENTATION_LEFT:
icculus@1251
   172
			if (!SDL_VideoSurface)
icculus@1251
   173
				break;
icculus@1251
   174
			rotatedX = *y;
icculus@1251
   175
			rotatedY = SDL_VideoSurface->h - *x;
icculus@1251
   176
			*x = rotatedX;
icculus@1251
   177
			*y = rotatedY;
icculus@1251
   178
			break;
icculus@1251
   179
	}
icculus@1251
   180
}
icculus@1251
   181
icculus@1152
   182
#endif
icculus@1152
   183
slouken@1523
   184
/* JC 14 Mar 2006
slouken@1523
   185
   This is used all over the place, in the windib driver and in the dx5 driver
slouken@1523
   186
   So we may as well stick it here instead of having multiple copies scattered
slouken@1523
   187
   about
slouken@1523
   188
*/
slouken@1523
   189
void WIN_FlushMessageQueue()
slouken@1523
   190
{
slouken@1523
   191
	MSG  msg;
slouken@1523
   192
	while ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) {
slouken@1523
   193
		if ( msg.message == WM_QUIT ) break;
slouken@1523
   194
		TranslateMessage( &msg );
slouken@1523
   195
		DispatchMessage( &msg );
slouken@1523
   196
	}
slouken@1523
   197
}
slouken@1523
   198
slouken@304
   199
static void SDL_RestoreGameMode(void)
slouken@304
   200
{
slouken@1497
   201
#ifdef _WIN32_WCE
slouken@1497
   202
	SDL_VideoDevice *this = current_video;
slouken@1497
   203
	if(SDL_strcmp(this->name, "gapi") == 0)
slouken@1497
   204
	{
slouken@1497
   205
		if( this->hidden->suspended )
slouken@1497
   206
		{
slouken@1497
   207
			this->hidden->suspended = 0;
slouken@1497
   208
		}
slouken@1497
   209
	}
slouken@1497
   210
#else
slouken@1465
   211
	ShowWindow(SDL_Window, SW_RESTORE);
slouken@1497
   212
#endif
slouken@1497
   213
slouken@304
   214
#ifndef NO_CHANGEDISPLAYSETTINGS
slouken@1465
   215
#ifndef _WIN32_WCE
slouken@304
   216
	ChangeDisplaySettings(&SDL_fullscreen_mode, CDS_FULLSCREEN);
slouken@304
   217
#endif
slouken@1465
   218
#endif /* NO_CHANGEDISPLAYSETTINGS */
slouken@304
   219
}
slouken@304
   220
static void SDL_RestoreDesktopMode(void)
slouken@304
   221
{
slouken@1497
   222
slouken@1497
   223
#ifdef _WIN32_WCE
slouken@1497
   224
	SDL_VideoDevice *this = current_video;
slouken@1497
   225
	if(SDL_strcmp(this->name, "gapi") == 0)
slouken@1497
   226
	{
slouken@1497
   227
		if( !this->hidden->suspended )
slouken@1497
   228
		{
slouken@1497
   229
			this->hidden->suspended = 1;
slouken@1497
   230
		}
slouken@1497
   231
	}
slouken@1497
   232
#else
slouken@1497
   233
	/* WinCE does not have a taskbar, so minimizing is not convenient */
slouken@1465
   234
	ShowWindow(SDL_Window, SW_MINIMIZE);
slouken@1497
   235
#endif
slouken@1497
   236
slouken@304
   237
#ifndef NO_CHANGEDISPLAYSETTINGS
slouken@1465
   238
#ifndef _WIN32_WCE
slouken@304
   239
	ChangeDisplaySettings(NULL, 0);
slouken@304
   240
#endif
slouken@1465
   241
#endif /* NO_CHANGEDISPLAYSETTINGS */
slouken@304
   242
}
slouken@304
   243
slouken@0
   244
#ifdef WM_MOUSELEAVE
slouken@0
   245
/* 
slouken@0
   246
   Special code to handle mouse leave events - this sucks...
slouken@0
   247
   http://support.microsoft.com/support/kb/articles/q183/1/07.asp
slouken@0
   248
slouken@0
   249
   TrackMouseEvent() is only available on Win98 and WinNT.
slouken@0
   250
   _TrackMouseEvent() is available on Win95, but isn't yet in the mingw32
slouken@0
   251
   development environment, and only works on systems that have had IE 3.0
slouken@0
   252
   or newer installed on them (which is not the case with the base Win95).
slouken@0
   253
   Therefore, we implement our own version of _TrackMouseEvent() which
slouken@0
   254
   uses our own implementation if TrackMouseEvent() is not available.
slouken@0
   255
*/
slouken@0
   256
static BOOL (WINAPI *_TrackMouseEvent)(TRACKMOUSEEVENT *ptme) = NULL;
slouken@0
   257
slouken@0
   258
static VOID CALLBACK
slouken@0
   259
TrackMouseTimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime)
slouken@0
   260
{
slouken@0
   261
	RECT rect;
slouken@0
   262
	POINT pt;
slouken@0
   263
slouken@0
   264
	GetClientRect(hWnd, &rect);
slouken@0
   265
	MapWindowPoints(hWnd, NULL, (LPPOINT)&rect, 2);
slouken@0
   266
	GetCursorPos(&pt);
slouken@0
   267
	if ( !PtInRect(&rect, pt) || (WindowFromPoint(pt) != hWnd) ) {
slouken@0
   268
		if ( !KillTimer(hWnd, idEvent) ) {
slouken@0
   269
			/* Error killing the timer! */
slouken@0
   270
		}
slouken@0
   271
		PostMessage(hWnd, WM_MOUSELEAVE, 0, 0);
slouken@0
   272
	}
slouken@0
   273
}
slouken@0
   274
static BOOL WINAPI WIN_TrackMouseEvent(TRACKMOUSEEVENT *ptme)
slouken@0
   275
{
slouken@0
   276
	if ( ptme->dwFlags == TME_LEAVE ) {
slouken@0
   277
		return SetTimer(ptme->hwndTrack, ptme->dwFlags, 100,
slouken@1456
   278
		                (TIMERPROC)TrackMouseTimerProc) != 0;
slouken@0
   279
	}
slouken@0
   280
	return FALSE;
slouken@0
   281
}
slouken@0
   282
#endif /* WM_MOUSELEAVE */
slouken@0
   283
slouken@0
   284
/* Function to retrieve the current keyboard modifiers */
slouken@0
   285
static void WIN_GetKeyboardState(void)
slouken@0
   286
{
slouken@0
   287
#ifndef NO_GETKEYBOARDSTATE
slouken@0
   288
	SDLMod state;
slouken@0
   289
	BYTE keyboard[256];
slouken@327
   290
	Uint8 *kstate = SDL_GetKeyState(NULL);
slouken@0
   291
slouken@0
   292
	state = KMOD_NONE;
slouken@0
   293
	if ( GetKeyboardState(keyboard) ) {
slouken@0
   294
		if ( keyboard[VK_LSHIFT] & 0x80) {
slouken@0
   295
			state |= KMOD_LSHIFT;
slouken@1282
   296
			kstate[SDLK_LSHIFT] = SDL_PRESSED;
slouken@0
   297
		}
slouken@0
   298
		if ( keyboard[VK_RSHIFT] & 0x80) {
slouken@0
   299
			state |= KMOD_RSHIFT;
slouken@1282
   300
			kstate[SDLK_RSHIFT] = SDL_PRESSED;
slouken@0
   301
		}
slouken@0
   302
		if ( keyboard[VK_LCONTROL] & 0x80) {
slouken@0
   303
			state |= KMOD_LCTRL;
slouken@1282
   304
			kstate[SDLK_LCTRL] = SDL_PRESSED;
slouken@0
   305
		}
slouken@0
   306
		if ( keyboard[VK_RCONTROL] & 0x80) {
slouken@0
   307
			state |= KMOD_RCTRL;
slouken@1282
   308
			kstate[SDLK_RCTRL] = SDL_PRESSED;
slouken@0
   309
		}
slouken@0
   310
		if ( keyboard[VK_LMENU] & 0x80) {
slouken@0
   311
			state |= KMOD_LALT;
slouken@1282
   312
			kstate[SDLK_LALT] = SDL_PRESSED;
slouken@0
   313
		}
slouken@0
   314
		if ( keyboard[VK_RMENU] & 0x80) {
slouken@0
   315
			state |= KMOD_RALT;
slouken@1282
   316
			kstate[SDLK_RALT] = SDL_PRESSED;
slouken@0
   317
		}
slouken@1
   318
		if ( keyboard[VK_NUMLOCK] & 0x01) {
slouken@0
   319
			state |= KMOD_NUM;
slouken@327
   320
			kstate[SDLK_NUMLOCK] = SDL_PRESSED;
slouken@0
   321
		}
slouken@1
   322
		if ( keyboard[VK_CAPITAL] & 0x01) {
slouken@0
   323
			state |= KMOD_CAPS;
slouken@327
   324
			kstate[SDLK_CAPSLOCK] = SDL_PRESSED;
slouken@0
   325
		}
slouken@0
   326
	}
slouken@0
   327
	SDL_SetModState(state);
slouken@0
   328
#endif /* !NO_GETKEYBOARDSTATE */
slouken@0
   329
}
slouken@0
   330
slouken@145
   331
/* The main Win32 event handler
slouken@145
   332
DJM: This is no longer static as (DX5/DIB)_CreateWindow needs it
slouken@145
   333
*/
slouken@1456
   334
LRESULT CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
slouken@0
   335
{
slouken@0
   336
	SDL_VideoDevice *this = current_video;
slouken@0
   337
	static int mouse_pressed = 0;
slouken@0
   338
	static int in_window = 0;
slouken@0
   339
#ifdef WMMSG_DEBUG
slouken@0
   340
	fprintf(stderr, "Received windows message:  ");
slouken@0
   341
	if ( msg > MAX_WMMSG ) {
slouken@0
   342
		fprintf(stderr, "%d", msg);
slouken@0
   343
	} else {
slouken@0
   344
		fprintf(stderr, "%s", wmtab[msg]);
slouken@0
   345
	}
slouken@0
   346
	fprintf(stderr, " -- 0x%X, 0x%X\n", wParam, lParam);
slouken@0
   347
#endif
slouken@0
   348
	switch (msg) {
slouken@0
   349
slouken@0
   350
		case WM_ACTIVATE: {
slouken@0
   351
			SDL_VideoDevice *this = current_video;
slouken@3992
   352
			BOOL active, minimized;
slouken@0
   353
			Uint8 appstate;
slouken@0
   354
slouken@0
   355
			minimized = HIWORD(wParam);
slouken@3992
   356
			active = (LOWORD(wParam) != WA_INACTIVE) && !minimized;
slouken@3992
   357
			if ( active ) {
slouken@0
   358
				/* Gain the following states */
slouken@0
   359
				appstate = SDL_APPACTIVE|SDL_APPINPUTFOCUS;
slouken@0
   360
				if ( this->input_grab != SDL_GRAB_OFF ) {
slouken@0
   361
					WIN_GrabInput(this, SDL_GRAB_ON);
slouken@0
   362
				}
slouken@0
   363
				if ( !(SDL_GetAppState()&SDL_APPINPUTFOCUS) ) {
slouken@338
   364
					if ( ! DDRAW_FULLSCREEN() ) {
slouken@338
   365
						DIB_SwapGamma(this);
slouken@338
   366
					}
slouken@304
   367
					if ( WINDIB_FULLSCREEN() ) {
slouken@304
   368
						SDL_RestoreGameMode();
slouken@304
   369
					}
slouken@0
   370
				}
icculus@1152
   371
#if defined(_WIN32_WCE)
slouken@3992
   372
				if ( WINDIB_FULLSCREEN() ) {
slouken@3992
   373
					LoadAygshell();
slouken@3992
   374
					if( SHFullScreen )
slouken@3992
   375
						SHFullScreen(SDL_Window, SHFS_HIDESTARTICON|SHFS_HIDETASKBAR|SHFS_HIDESIPBUTTON);
slouken@3992
   376
					else
slouken@3992
   377
						ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_HIDE);
slouken@3992
   378
				}
icculus@1152
   379
#endif
slouken@0
   380
				posted = SDL_PrivateAppActive(1, appstate);
slouken@0
   381
				WIN_GetKeyboardState();
slouken@0
   382
			} else {
slouken@0
   383
				/* Lose the following states */
slouken@0
   384
				appstate = SDL_APPINPUTFOCUS;
slouken@0
   385
				if ( minimized ) {
slouken@0
   386
					appstate |= SDL_APPACTIVE;
slouken@0
   387
				}
slouken@0
   388
				if ( this->input_grab != SDL_GRAB_OFF ) {
slouken@0
   389
					WIN_GrabInput(this, SDL_GRAB_OFF);
slouken@0
   390
				}
slouken@0
   391
				if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) {
slouken@338
   392
					if ( ! DDRAW_FULLSCREEN() ) {
slouken@338
   393
						DIB_SwapGamma(this);
slouken@338
   394
					}
slouken@304
   395
					if ( WINDIB_FULLSCREEN() ) {
slouken@304
   396
						SDL_RestoreDesktopMode();
icculus@1152
   397
#if defined(_WIN32_WCE)
icculus@1152
   398
						LoadAygshell();
slouken@1497
   399
						if( SHFullScreen ) 
icculus@1152
   400
							SHFullScreen(SDL_Window, SHFS_SHOWSTARTICON|SHFS_SHOWTASKBAR|SHFS_SHOWSIPBUTTON);
icculus@1152
   401
						else
icculus@1152
   402
							ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_SHOW);
icculus@1152
   403
#endif
slouken@304
   404
					}
slouken@0
   405
				}
slouken@0
   406
				posted = SDL_PrivateAppActive(0, appstate);
slouken@0
   407
			}
slouken@3992
   408
			WIN_Activate(this, active, minimized);
slouken@0
   409
			return(0);
slouken@0
   410
		}
slouken@0
   411
		break;
slouken@0
   412
slouken@0
   413
		case WM_MOUSEMOVE: {
slouken@0
   414
			
slouken@0
   415
			/* Mouse is handled by DirectInput when fullscreen */
slouken@13
   416
			if ( SDL_VideoSurface && ! DINPUT_FULLSCREEN() ) {
slouken@0
   417
				Sint16 x, y;
slouken@0
   418
slouken@0
   419
				/* mouse has entered the window */
slouken@0
   420
				if ( ! in_window ) {
slouken@0
   421
#ifdef WM_MOUSELEAVE
slouken@0
   422
					TRACKMOUSEEVENT tme;
slouken@0
   423
slouken@0
   424
					tme.cbSize = sizeof(tme);
slouken@0
   425
					tme.dwFlags = TME_LEAVE;
slouken@0
   426
					tme.hwndTrack = SDL_Window;
slouken@0
   427
					_TrackMouseEvent(&tme);
slouken@0
   428
#endif /* WM_MOUSELEAVE */
slouken@0
   429
					in_window = TRUE;
slouken@0
   430
slouken@0
   431
					posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
slouken@0
   432
				}
slouken@0
   433
slouken@0
   434
				/* mouse has moved within the window */
slouken@0
   435
				x = LOWORD(lParam);
slouken@0
   436
				y = HIWORD(lParam);
slouken@0
   437
				if ( mouse_relative ) {
slouken@0
   438
					POINT center;
slouken@0
   439
					center.x = (SDL_VideoSurface->w/2);
slouken@0
   440
					center.y = (SDL_VideoSurface->h/2);
slouken@0
   441
					x -= (Sint16)center.x;
slouken@0
   442
					y -= (Sint16)center.y;
slouken@0
   443
					if ( x || y ) {
slouken@0
   444
						ClientToScreen(SDL_Window, &center);
slouken@0
   445
						SetCursorPos(center.x, center.y);
slouken@0
   446
						posted = SDL_PrivateMouseMotion(0, 1, x, y);
slouken@0
   447
					}
slouken@0
   448
				} else {
icculus@1251
   449
#ifdef _WIN32_WCE
icculus@1251
   450
					if (SDL_VideoSurface)
icculus@1251
   451
						GapiTransform(this->hidden->userOrientation, this->hidden->hiresFix, &x, &y);
icculus@1251
   452
#endif
slouken@0
   453
					posted = SDL_PrivateMouseMotion(0, 0, x, y);
slouken@0
   454
				}
slouken@0
   455
			}
slouken@0
   456
		}
slouken@0
   457
		return(0);
slouken@0
   458
slouken@0
   459
#ifdef WM_MOUSELEAVE
slouken@0
   460
		case WM_MOUSELEAVE: {
slouken@0
   461
slouken@0
   462
			/* Mouse is handled by DirectInput when fullscreen */
slouken@13
   463
			if ( SDL_VideoSurface && ! DINPUT_FULLSCREEN() ) {
slouken@0
   464
				/* mouse has left the window */
slouken@0
   465
				/* or */
slouken@0
   466
				/* Elvis has left the building! */
slouken@0
   467
				posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
slouken@0
   468
			}
slouken@829
   469
			in_window = FALSE;
slouken@0
   470
		}
slouken@0
   471
		return(0);
slouken@0
   472
#endif /* WM_MOUSELEAVE */
slouken@0
   473
slouken@0
   474
		case WM_LBUTTONDOWN:
slouken@0
   475
		case WM_LBUTTONUP:
slouken@0
   476
		case WM_MBUTTONDOWN:
slouken@0
   477
		case WM_MBUTTONUP:
slouken@0
   478
		case WM_RBUTTONDOWN:
icculus@3970
   479
		case WM_RBUTTONUP:
icculus@3970
   480
		case WM_XBUTTONDOWN:
icculus@3970
   481
		case WM_XBUTTONUP: {
slouken@0
   482
			/* Mouse is handled by DirectInput when fullscreen */
slouken@13
   483
			if ( SDL_VideoSurface && ! DINPUT_FULLSCREEN() ) {
icculus@3970
   484
				WORD xbuttonval = 0;
slouken@0
   485
				Sint16 x, y;
slouken@0
   486
				Uint8 button, state;
slouken@0
   487
slouken@145
   488
				/* DJM:
slouken@145
   489
				   We want the SDL window to take focus so that
slouken@145
   490
				   it acts like a normal windows "component"
slouken@145
   491
				   (e.g. gains keyboard focus on a mouse click).
slouken@145
   492
				 */
slouken@145
   493
				SetFocus(SDL_Window);
slouken@145
   494
slouken@0
   495
				/* Figure out which button to use */
slouken@0
   496
				switch (msg) {
slouken@0
   497
					case WM_LBUTTONDOWN:
slouken@457
   498
						button = SDL_BUTTON_LEFT;
slouken@0
   499
						state = SDL_PRESSED;
slouken@0
   500
						break;
slouken@0
   501
					case WM_LBUTTONUP:
slouken@457
   502
						button = SDL_BUTTON_LEFT;
slouken@0
   503
						state = SDL_RELEASED;
slouken@0
   504
						break;
slouken@0
   505
					case WM_MBUTTONDOWN:
slouken@457
   506
						button = SDL_BUTTON_MIDDLE;
slouken@0
   507
						state = SDL_PRESSED;
slouken@0
   508
						break;
slouken@0
   509
					case WM_MBUTTONUP:
slouken@457
   510
						button = SDL_BUTTON_MIDDLE;
slouken@0
   511
						state = SDL_RELEASED;
slouken@0
   512
						break;
slouken@0
   513
					case WM_RBUTTONDOWN:
slouken@457
   514
						button = SDL_BUTTON_RIGHT;
slouken@0
   515
						state = SDL_PRESSED;
slouken@0
   516
						break;
slouken@0
   517
					case WM_RBUTTONUP:
slouken@457
   518
						button = SDL_BUTTON_RIGHT;
slouken@0
   519
						state = SDL_RELEASED;
slouken@0
   520
						break;
icculus@3970
   521
					case WM_XBUTTONDOWN:
icculus@3970
   522
						xbuttonval = GET_XBUTTON_WPARAM(wParam);
slouken@4113
   523
						button = SDL_BUTTON_X1 + xbuttonval - 1;
icculus@3970
   524
						state = SDL_PRESSED;
icculus@3970
   525
						break;
icculus@3970
   526
					case WM_XBUTTONUP:
icculus@3970
   527
						xbuttonval = GET_XBUTTON_WPARAM(wParam);
slouken@4113
   528
						button = SDL_BUTTON_X1 + xbuttonval - 1;
icculus@3970
   529
						state = SDL_RELEASED;
icculus@3970
   530
						break;
slouken@0
   531
					default:
slouken@0
   532
						/* Eh? Unknown button? */
slouken@0
   533
						return(0);
slouken@0
   534
				}
slouken@0
   535
				if ( state == SDL_PRESSED ) {
slouken@0
   536
					/* Grab mouse so we get up events */
slouken@0
   537
					if ( ++mouse_pressed > 0 ) {
slouken@0
   538
						SetCapture(hwnd);
slouken@0
   539
					}
slouken@0
   540
				} else {
slouken@0
   541
					/* Release mouse after all up events */
slouken@0
   542
					if ( --mouse_pressed <= 0 ) {
slouken@0
   543
						ReleaseCapture();
slouken@0
   544
						mouse_pressed = 0;
slouken@0
   545
					}
slouken@0
   546
				}
slouken@0
   547
				if ( mouse_relative ) {
slouken@0
   548
				/*	RJR: March 28, 2000
slouken@0
   549
					report internal mouse position if in relative mode */
slouken@0
   550
					x = 0; y = 0;
slouken@0
   551
				} else {
slouken@0
   552
					x = (Sint16)LOWORD(lParam);
slouken@0
   553
					y = (Sint16)HIWORD(lParam);
icculus@1251
   554
#ifdef _WIN32_WCE
icculus@1251
   555
					if (SDL_VideoSurface)
icculus@1251
   556
						GapiTransform(this->hidden->userOrientation, this->hidden->hiresFix, &x, &y);
icculus@1251
   557
#endif
slouken@0
   558
				}
slouken@0
   559
				posted = SDL_PrivateMouseButton(
slouken@0
   560
							state, button, x, y);
icculus@3970
   561
icculus@3970
   562
				/*
icculus@3970
   563
				 * MSDN says:
icculus@3970
   564
				 *  "Unlike the WM_LBUTTONUP, WM_MBUTTONUP, and WM_RBUTTONUP
icculus@3970
   565
				 *   messages, an application should return TRUE from [an 
icculus@3970
   566
				 *   XBUTTON message] if it processes it. Doing so will allow
icculus@3970
   567
				 *   software that simulates this message on Microsoft Windows
icculus@3970
   568
				 *   systems earlier than Windows 2000 to determine whether
icculus@3970
   569
				 *   the window procedure processed the message or called
icculus@3970
   570
				 *   DefWindowProc to process it.
icculus@3970
   571
				 */
icculus@3970
   572
				if (xbuttonval > 0)
icculus@3970
   573
					return(TRUE);
slouken@0
   574
			}
slouken@0
   575
		}
slouken@0
   576
		return(0);
slouken@0
   577
slouken@61
   578
slouken@61
   579
#if (_WIN32_WINNT >= 0x0400) || (_WIN32_WINDOWS > 0x0400)
slouken@61
   580
		case WM_MOUSEWHEEL: 
slouken@61
   581
			if ( SDL_VideoSurface && ! DINPUT_FULLSCREEN() ) {
slouken@61
   582
				int move = (short)HIWORD(wParam);
slouken@162
   583
				if ( move ) {
slouken@162
   584
					Uint8 button;
slouken@162
   585
					if ( move > 0 )
slouken@451
   586
						button = SDL_BUTTON_WHEELUP;
slouken@162
   587
					else
slouken@451
   588
						button = SDL_BUTTON_WHEELDOWN;
slouken@61
   589
					posted = SDL_PrivateMouseButton(
slouken@162
   590
						SDL_PRESSED, button, 0, 0);
slouken@332
   591
					posted |= SDL_PrivateMouseButton(
slouken@332
   592
						SDL_RELEASED, button, 0, 0);
slouken@61
   593
				}
slouken@61
   594
			}
slouken@61
   595
			return(0);
slouken@61
   596
#endif
slouken@61
   597
slouken@0
   598
#ifdef WM_GETMINMAXINFO
slouken@0
   599
		/* This message is sent as a way for us to "check" the values
slouken@0
   600
		 * of a position change.  If we don't like it, we can adjust
slouken@0
   601
		 * the values before they are changed.
slouken@0
   602
		 */
slouken@0
   603
		case WM_GETMINMAXINFO: {
slouken@0
   604
			MINMAXINFO *info;
slouken@0
   605
			RECT        size;
slouken@0
   606
			int x, y;
slouken@565
   607
			int style;
slouken@0
   608
			int width;
slouken@0
   609
			int height;
slouken@0
   610
slouken@0
   611
			/* We don't want to clobber an internal resize */
slouken@0
   612
			if ( SDL_resizing )
slouken@0
   613
				return(0);
slouken@0
   614
slouken@0
   615
			/* We allow resizing with the SDL_RESIZABLE flag */
slouken@0
   616
			if ( SDL_PublicSurface &&
slouken@0
   617
				(SDL_PublicSurface->flags & SDL_RESIZABLE) ) {
slouken@0
   618
				return(0);
slouken@0
   619
			}
slouken@0
   620
slouken@0
   621
			/* Get the current position of our window */
slouken@0
   622
			GetWindowRect(SDL_Window, &size);
slouken@0
   623
			x = size.left;
slouken@0
   624
			y = size.top;
slouken@0
   625
slouken@0
   626
			/* Calculate current width and height of our window */
slouken@0
   627
			size.top = 0;
slouken@0
   628
			size.left = 0;
slouken@0
   629
			if ( SDL_PublicSurface != NULL ) {
slouken@0
   630
				size.bottom = SDL_PublicSurface->h;
slouken@0
   631
				size.right = SDL_PublicSurface->w;
slouken@0
   632
			} else {
slouken@0
   633
				size.bottom = 0;
slouken@0
   634
				size.right = 0;
slouken@0
   635
			}
slouken@565
   636
slouken@565
   637
			/* DJM - according to the docs for GetMenu(), the
slouken@565
   638
			   return value is undefined if hwnd is a child window.
slouken@565
   639
			   Aparently it's too difficult for MS to check
slouken@565
   640
			   inside their function, so I have to do it here.
slouken@565
   641
          		 */
slouken@1480
   642
         		style = GetWindowLong(hwnd, GWL_STYLE);
slouken@565
   643
         		AdjustWindowRect(
slouken@565
   644
				&size,
slouken@565
   645
				style,
slouken@565
   646
            			style & WS_CHILDWINDOW ? FALSE
slouken@565
   647
						       : GetMenu(hwnd) != NULL);
slouken@565
   648
slouken@0
   649
			width = size.right - size.left;
slouken@0
   650
			height = size.bottom - size.top;
slouken@0
   651
slouken@0
   652
			/* Fix our size to the current size */
slouken@0
   653
			info = (MINMAXINFO *)lParam;
slouken@0
   654
			info->ptMaxSize.x = width;
slouken@0
   655
			info->ptMaxSize.y = height;
slouken@0
   656
			info->ptMaxPosition.x = x;
slouken@0
   657
			info->ptMaxPosition.y = y;
slouken@0
   658
			info->ptMinTrackSize.x = width;
slouken@0
   659
			info->ptMinTrackSize.y = height;
slouken@0
   660
			info->ptMaxTrackSize.x = width;
slouken@0
   661
			info->ptMaxTrackSize.y = height;
slouken@0
   662
		}
slouken@0
   663
		return(0);
slouken@0
   664
#endif /* WM_GETMINMAXINFO */
slouken@0
   665
slouken@447
   666
		case WM_WINDOWPOSCHANGED: {
slouken@0
   667
			SDL_VideoDevice *this = current_video;
slouken@447
   668
			int w, h;
slouken@0
   669
slouken@0
   670
			GetClientRect(SDL_Window, &SDL_bounds);
slouken@1290
   671
			ClientToScreen(SDL_Window, (LPPOINT)&SDL_bounds);
slouken@1290
   672
			ClientToScreen(SDL_Window, (LPPOINT)&SDL_bounds+1);
slouken@1291
   673
			if ( !SDL_resizing && !IsZoomed(SDL_Window) &&
slouken@1291
   674
			     SDL_PublicSurface &&
slouken@1291
   675
				!(SDL_PublicSurface->flags & SDL_FULLSCREEN) ) {
slouken@1291
   676
				SDL_windowX = SDL_bounds.left;
slouken@1291
   677
				SDL_windowY = SDL_bounds.top;
slouken@1291
   678
			}
slouken@447
   679
			w = SDL_bounds.right-SDL_bounds.left;
slouken@447
   680
			h = SDL_bounds.bottom-SDL_bounds.top;
slouken@0
   681
			if ( this->input_grab != SDL_GRAB_OFF ) {
slouken@0
   682
				ClipCursor(&SDL_bounds);
slouken@0
   683
			}
slouken@447
   684
			if ( SDL_PublicSurface && 
slouken@0
   685
				(SDL_PublicSurface->flags & SDL_RESIZABLE) ) {
slouken@447
   686
				SDL_PrivateResize(w, h);
slouken@0
   687
			}
slouken@0
   688
		}
slouken@0
   689
		break;
slouken@0
   690
slouken@0
   691
		/* We need to set the cursor */
slouken@0
   692
		case WM_SETCURSOR: {
slouken@0
   693
			Uint16 hittest;
slouken@0
   694
slouken@0
   695
			hittest = LOWORD(lParam);
slouken@0
   696
			if ( hittest == HTCLIENT ) {
slouken@0
   697
				SetCursor(SDL_hcursor);
slouken@0
   698
				return(TRUE);
slouken@0
   699
			}
slouken@0
   700
		}
slouken@0
   701
		break;
slouken@0
   702
slouken@0
   703
		/* We are about to get palette focus! */
slouken@0
   704
		case WM_QUERYNEWPALETTE: {
slouken@0
   705
			WIN_RealizePalette(current_video);
slouken@0
   706
			return(TRUE);
slouken@0
   707
		}
slouken@0
   708
		break;
slouken@0
   709
slouken@0
   710
		/* Another application changed the palette */
slouken@0
   711
		case WM_PALETTECHANGED: {
slouken@0
   712
			WIN_PaletteChanged(current_video, (HWND)wParam);
slouken@0
   713
		}
slouken@0
   714
		break;
slouken@0
   715
slouken@0
   716
		/* We were occluded, refresh our display */
slouken@0
   717
		case WM_PAINT: {
slouken@0
   718
			HDC hdc;
slouken@0
   719
			PAINTSTRUCT ps;
slouken@0
   720
slouken@0
   721
			hdc = BeginPaint(SDL_Window, &ps);
slouken@0
   722
			if ( current_video->screen &&
slouken@0
   723
			     !(current_video->screen->flags & SDL_OPENGL) ) {
slouken@0
   724
				WIN_WinPAINT(current_video, hdc);
slouken@0
   725
			}
slouken@0
   726
			EndPaint(SDL_Window, &ps);
slouken@0
   727
		}
slouken@0
   728
		return(0);
slouken@0
   729
slouken@145
   730
		/* DJM: Send an expose event in this case */
slouken@0
   731
		case WM_ERASEBKGND: {
slouken@145
   732
			posted = SDL_PrivateExpose();
slouken@0
   733
		}
slouken@145
   734
		return(0);
slouken@0
   735
slouken@0
   736
		case WM_CLOSE: {
slouken@0
   737
			if ( (posted = SDL_PrivateQuit()) )
slouken@0
   738
				PostQuitMessage(0);
slouken@0
   739
		}
slouken@0
   740
		return(0);
slouken@0
   741
slouken@0
   742
		case WM_DESTROY: {
slouken@0
   743
			PostQuitMessage(0);
slouken@0
   744
		}
slouken@0
   745
		return(0);
slouken@0
   746
slouken@1272
   747
#ifndef NO_GETKEYBOARDSTATE
slouken@1253
   748
		case WM_INPUTLANGCHANGE: {
slouken@1253
   749
			codepage = GetCodePage();
slouken@1253
   750
		}
slouken@1253
   751
		return(TRUE);
slouken@1272
   752
#endif
slouken@1253
   753
slouken@0
   754
		default: {
slouken@0
   755
			/* Special handling by the video driver */
slouken@0
   756
			if (HandleMessage) {
slouken@0
   757
				return(HandleMessage(current_video,
slouken@0
   758
			                     hwnd, msg, wParam, lParam));
slouken@0
   759
			}
slouken@0
   760
		}
slouken@0
   761
		break;
slouken@0
   762
	}
slouken@0
   763
	return(DefWindowProc(hwnd, msg, wParam, lParam));
slouken@0
   764
}
slouken@0
   765
slouken@145
   766
/* Allow the application handle to be stored and retrieved later */
slouken@149
   767
static void *SDL_handle = NULL;
slouken@145
   768
slouken@149
   769
void SDL_SetModuleHandle(void *handle)
slouken@145
   770
{
slouken@145
   771
	SDL_handle = handle;
slouken@145
   772
}
slouken@149
   773
void *SDL_GetModuleHandle(void)
slouken@145
   774
{
slouken@145
   775
	void *handle;
slouken@145
   776
slouken@145
   777
	if ( SDL_handle ) {
slouken@145
   778
		handle = SDL_handle;
slouken@145
   779
	} else {
slouken@145
   780
		handle = GetModuleHandle(NULL);
slouken@145
   781
	}
slouken@145
   782
	return(handle);
slouken@145
   783
}
slouken@145
   784
slouken@0
   785
/* This allows the SDL_WINDOWID hack */
slouken@1280
   786
BOOL SDL_windowid = FALSE;
slouken@0
   787
icculus@1145
   788
static int app_registered = 0;
icculus@1145
   789
slouken@0
   790
/* Register the class for this application -- exported for winmain.c */
slouken@149
   791
int SDL_RegisterApp(char *name, Uint32 style, void *hInst)
slouken@0
   792
{
slouken@0
   793
	WNDCLASS class;
slouken@0
   794
#ifdef WM_MOUSELEAVE
slouken@0
   795
	HMODULE handle;
slouken@0
   796
#endif
slouken@0
   797
slouken@0
   798
	/* Only do this once... */
icculus@1145
   799
	if ( app_registered ) {
slouken@1498
   800
		++app_registered;
slouken@0
   801
		return(0);
slouken@0
   802
	}
slouken@0
   803
slouken@1288
   804
#ifndef CS_BYTEALIGNCLIENT
slouken@1288
   805
#define CS_BYTEALIGNCLIENT	0
slouken@1288
   806
#endif
slouken@1288
   807
	if ( ! name && ! SDL_Appname ) {
slouken@1288
   808
		name = "SDL_app";
slouken@1288
   809
		SDL_Appstyle = CS_BYTEALIGNCLIENT;
slouken@1288
   810
		SDL_Instance = hInst ? hInst : SDL_GetModuleHandle();
slouken@0
   811
	}
slouken@0
   812
slouken@1288
   813
	if ( name ) {
slouken@0
   814
#ifdef _WIN32_WCE
slouken@453
   815
		/* WinCE uses the UNICODE version */
slouken@1505
   816
		SDL_Appname = SDL_iconv_utf8_ucs2(name);
slouken@453
   817
#else
slouken@4007
   818
		SDL_Appname = SDL_iconv_utf8_locale(name);
slouken@1288
   819
#endif /* _WIN32_WCE */
slouken@1288
   820
		SDL_Appstyle = style;
slouken@1288
   821
		SDL_Instance = hInst ? hInst : SDL_GetModuleHandle();
slouken@453
   822
	}
slouken@1288
   823
slouken@1288
   824
	/* Register the application class */
slouken@1288
   825
	class.hCursor		= NULL;
slouken@1288
   826
	class.hIcon		= LoadImage(SDL_Instance, SDL_Appname,
slouken@1288
   827
				            IMAGE_ICON,
slouken@0
   828
	                                    0, 0, LR_DEFAULTCOLOR);
slouken@36
   829
	class.lpszMenuName	= NULL;
slouken@453
   830
	class.lpszClassName	= SDL_Appname;
slouken@0
   831
	class.hbrBackground	= NULL;
slouken@1288
   832
	class.hInstance		= SDL_Instance;
slouken@1288
   833
	class.style		= SDL_Appstyle;
slouken@1361
   834
#if SDL_VIDEO_OPENGL
slouken@0
   835
	class.style		|= CS_OWNDC;
slouken@0
   836
#endif
slouken@0
   837
	class.lpfnWndProc	= WinMessage;
slouken@0
   838
	class.cbWndExtra	= 0;
slouken@0
   839
	class.cbClsExtra	= 0;
slouken@0
   840
	if ( ! RegisterClass(&class) ) {
slouken@0
   841
		SDL_SetError("Couldn't register application class");
slouken@0
   842
		return(-1);
slouken@0
   843
	}
slouken@0
   844
slouken@0
   845
#ifdef WM_MOUSELEAVE
slouken@0
   846
	/* Get the version of TrackMouseEvent() we use */
slouken@0
   847
	_TrackMouseEvent = NULL;
slouken@0
   848
	handle = GetModuleHandle("USER32.DLL");
slouken@0
   849
	if ( handle ) {
slouken@0
   850
		_TrackMouseEvent = (BOOL (WINAPI *)(TRACKMOUSEEVENT *))GetProcAddress(handle, "TrackMouseEvent");
slouken@0
   851
	}
slouken@0
   852
	if ( _TrackMouseEvent == NULL ) {
slouken@0
   853
		_TrackMouseEvent = WIN_TrackMouseEvent;
slouken@0
   854
	}
slouken@0
   855
#endif /* WM_MOUSELEAVE */
slouken@0
   856
slouken@1272
   857
#ifndef NO_GETKEYBOARDSTATE
slouken@1253
   858
	/* Initialise variables for SDL_ToUnicode() */
slouken@1253
   859
	codepage = GetCodePage();
slouken@1253
   860
	SDL_ToUnicode = Is9xME() ? ToUnicode9xME : ToUnicode;
slouken@1272
   861
#endif
slouken@1253
   862
icculus@1145
   863
	app_registered = 1;
slouken@0
   864
	return(0);
slouken@0
   865
}
slouken@0
   866
slouken@1288
   867
/* Unregisters the windowclass registered in SDL_RegisterApp above. */
icculus@1150
   868
void SDL_UnregisterApp()
icculus@1145
   869
{
icculus@1145
   870
	WNDCLASS class;
icculus@1145
   871
icculus@1145
   872
	/* SDL_RegisterApp might not have been called before */
slouken@1498
   873
	if ( !app_registered ) {
slouken@1498
   874
		return;
slouken@1498
   875
	}
slouken@1498
   876
	--app_registered;
slouken@1498
   877
	if ( app_registered == 0 ) {
slouken@1288
   878
		/* Check for any registered window classes. */
slouken@1288
   879
		if ( GetClassInfo(SDL_Instance, SDL_Appname, &class) ) {
icculus@1145
   880
			UnregisterClass(SDL_Appname, SDL_Instance);
icculus@1145
   881
		}
slouken@1498
   882
		SDL_free(SDL_Appname);
slouken@1498
   883
		SDL_Appname = NULL;
icculus@1145
   884
	}
icculus@1145
   885
}
icculus@1145
   886
slouken@1272
   887
#ifndef NO_GETKEYBOARDSTATE
slouken@1253
   888
/* JFP: Implementation of ToUnicode() that works on 9x/ME/2K/XP */
slouken@1253
   889
slouken@1253
   890
static int Is9xME()
slouken@1253
   891
{
slouken@1253
   892
	OSVERSIONINFO   info;
slouken@1253
   893
slouken@1336
   894
	SDL_memset(&info, 0, sizeof(info));
slouken@1253
   895
	info.dwOSVersionInfoSize = sizeof(info);
slouken@1253
   896
	if (!GetVersionEx(&info)) {
slouken@1253
   897
		return 0;
slouken@1253
   898
	}
slouken@1253
   899
	return (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS);
slouken@1253
   900
}
slouken@1253
   901
slouken@1253
   902
static int GetCodePage()
slouken@1253
   903
{
slouken@1253
   904
	char	buff[8];
slouken@1253
   905
	int	lcid = MAKELCID(LOWORD(GetKeyboardLayout(0)), SORT_DEFAULT);
slouken@1253
   906
	int	cp = GetACP();
slouken@1253
   907
slouken@1253
   908
	if (GetLocaleInfo(lcid, LOCALE_IDEFAULTANSICODEPAGE, buff, sizeof(buff))) {
slouken@1341
   909
		cp = SDL_atoi(buff);
slouken@1253
   910
	}
slouken@1253
   911
	return cp;
slouken@1253
   912
}
slouken@1253
   913
slouken@1253
   914
static int WINAPI ToUnicode9xME(UINT vkey, UINT scancode, PBYTE keystate, LPWSTR wchars, int wsize, UINT flags)
slouken@1253
   915
{
slouken@1253
   916
	BYTE	chars[2];
slouken@1253
   917
slouken@1253
   918
	if (ToAsciiEx(vkey, scancode, keystate, (WORD*)chars, 0, GetKeyboardLayout(0)) == 1) {
slouken@1253
   919
		return MultiByteToWideChar(codepage, 0, chars, 1, wchars, wsize);
slouken@1253
   920
	}
slouken@1253
   921
	return 0;
slouken@1253
   922
}
slouken@1253
   923
slouken@1272
   924
#endif /* !NO_GETKEYBOARDSTATE */