src/video/wincommon/SDL_sysevents.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 13 Apr 2009 08:38:04 +0000
branchSDL-1.2
changeset 4169 27c0db0fbfad
parent 4167 a6f635e5eaa6
child 4179 d7294b7c732d
permissions -rw-r--r--
Fixed bug #611

Comment #22 From Tim Angus 2009-04-02 08:45:52 (-) [reply] -------

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