src/video/wincommon/SDL_sysevents.c
author Sam Lantinga <slouken@lokigames.com>
Thu, 26 Apr 2001 16:45:43 +0000
changeset 0 74212992fb08
child 1 cf2af46e9e2a
permissions -rw-r--r--
Initial revision
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@0
     3
    Copyright (C) 1997, 1998, 1999  Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@0
     6
    modify it under the terms of the GNU Library General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@0
     8
    version 2 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@0
    13
    Library General Public License for more details.
slouken@0
    14
slouken@0
    15
    You should have received a copy of the GNU Library General Public
slouken@0
    16
    License along with this library; if not, write to the Free
slouken@0
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@0
    20
    slouken@devolution.com
slouken@0
    21
*/
slouken@0
    22
slouken@0
    23
#ifdef SAVE_RCSID
slouken@0
    24
static char rcsid =
slouken@0
    25
 "@(#) $Id$";
slouken@0
    26
#endif
slouken@0
    27
slouken@0
    28
#include <stdlib.h>
slouken@0
    29
#include <stdio.h>
slouken@0
    30
#include <windows.h>
slouken@0
    31
slouken@0
    32
#include "SDL_getenv.h"
slouken@0
    33
#include "SDL_events.h"
slouken@0
    34
#include "SDL_video.h"
slouken@0
    35
#include "SDL_error.h"
slouken@0
    36
#include "SDL_syswm.h"
slouken@0
    37
#include "SDL_sysevents.h"
slouken@0
    38
#include "SDL_events_c.h"
slouken@0
    39
#include "SDL_sysvideo.h"
slouken@0
    40
#include "SDL_lowvideo.h"
slouken@0
    41
#include "SDL_syswm_c.h"
slouken@0
    42
#include "SDL_main.h"
slouken@0
    43
slouken@0
    44
#ifdef WMMSG_DEBUG
slouken@0
    45
#include "wmmsg.h"
slouken@0
    46
#endif
slouken@0
    47
slouken@0
    48
#ifdef _WIN32_WCE
slouken@0
    49
#define NO_GETKEYBOARDSTATE
slouken@0
    50
#endif
slouken@0
    51
slouken@0
    52
/* The window we use for everything... */
slouken@0
    53
const char *SDL_Appname = NULL;
slouken@0
    54
HINSTANCE SDL_Instance = NULL;
slouken@0
    55
HWND SDL_Window = NULL;
slouken@0
    56
RECT SDL_bounds = {0, 0, 0, 0};
slouken@0
    57
int SDL_resizing = 0;
slouken@0
    58
int mouse_relative = 0;
slouken@0
    59
int posted = 0;
slouken@0
    60
slouken@0
    61
slouken@0
    62
/* Functions called by the message processing function */
slouken@0
    63
LONG
slouken@0
    64
(*HandleMessage)(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)=NULL;
slouken@0
    65
void (*WIN_RealizePalette)(_THIS);
slouken@0
    66
void (*WIN_PaletteChanged)(_THIS, HWND window);
slouken@0
    67
void (*WIN_SwapGamma)(_THIS);
slouken@0
    68
void (*WIN_WinPAINT)(_THIS, HDC hdc);
slouken@0
    69
slouken@0
    70
#ifdef WM_MOUSELEAVE
slouken@0
    71
/* 
slouken@0
    72
   Special code to handle mouse leave events - this sucks...
slouken@0
    73
   http://support.microsoft.com/support/kb/articles/q183/1/07.asp
slouken@0
    74
slouken@0
    75
   TrackMouseEvent() is only available on Win98 and WinNT.
slouken@0
    76
   _TrackMouseEvent() is available on Win95, but isn't yet in the mingw32
slouken@0
    77
   development environment, and only works on systems that have had IE 3.0
slouken@0
    78
   or newer installed on them (which is not the case with the base Win95).
slouken@0
    79
   Therefore, we implement our own version of _TrackMouseEvent() which
slouken@0
    80
   uses our own implementation if TrackMouseEvent() is not available.
slouken@0
    81
*/
slouken@0
    82
static BOOL (WINAPI *_TrackMouseEvent)(TRACKMOUSEEVENT *ptme) = NULL;
slouken@0
    83
slouken@0
    84
static VOID CALLBACK
slouken@0
    85
TrackMouseTimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime)
slouken@0
    86
{
slouken@0
    87
	RECT rect;
slouken@0
    88
	POINT pt;
slouken@0
    89
slouken@0
    90
	GetClientRect(hWnd, &rect);
slouken@0
    91
	MapWindowPoints(hWnd, NULL, (LPPOINT)&rect, 2);
slouken@0
    92
	GetCursorPos(&pt);
slouken@0
    93
	if ( !PtInRect(&rect, pt) || (WindowFromPoint(pt) != hWnd) ) {
slouken@0
    94
		if ( !KillTimer(hWnd, idEvent) ) {
slouken@0
    95
			/* Error killing the timer! */
slouken@0
    96
		}
slouken@0
    97
		PostMessage(hWnd, WM_MOUSELEAVE, 0, 0);
slouken@0
    98
	}
slouken@0
    99
}
slouken@0
   100
static BOOL WINAPI WIN_TrackMouseEvent(TRACKMOUSEEVENT *ptme)
slouken@0
   101
{
slouken@0
   102
	if ( ptme->dwFlags == TME_LEAVE ) {
slouken@0
   103
		return SetTimer(ptme->hwndTrack, ptme->dwFlags, 100,
slouken@0
   104
		                (TIMERPROC)TrackMouseTimerProc);
slouken@0
   105
	}
slouken@0
   106
	return FALSE;
slouken@0
   107
}
slouken@0
   108
#endif /* WM_MOUSELEAVE */
slouken@0
   109
slouken@0
   110
/* Function to retrieve the current keyboard modifiers */
slouken@0
   111
static void WIN_GetKeyboardState(void)
slouken@0
   112
{
slouken@0
   113
#ifndef NO_GETKEYBOARDSTATE
slouken@0
   114
	SDLMod state;
slouken@0
   115
	BYTE keyboard[256];
slouken@0
   116
slouken@0
   117
	state = KMOD_NONE;
slouken@0
   118
	if ( GetKeyboardState(keyboard) ) {
slouken@0
   119
		if ( keyboard[VK_LSHIFT] & 0x80) {
slouken@0
   120
			state |= KMOD_LSHIFT;
slouken@0
   121
		}
slouken@0
   122
		if ( keyboard[VK_RSHIFT] & 0x80) {
slouken@0
   123
			state |= KMOD_RSHIFT;
slouken@0
   124
		}
slouken@0
   125
		if ( keyboard[VK_LCONTROL] & 0x80) {
slouken@0
   126
			state |= KMOD_LCTRL;
slouken@0
   127
		}
slouken@0
   128
		if ( keyboard[VK_RCONTROL] & 0x80) {
slouken@0
   129
			state |= KMOD_RCTRL;
slouken@0
   130
		}
slouken@0
   131
		if ( keyboard[VK_LMENU] & 0x80) {
slouken@0
   132
			state |= KMOD_LALT;
slouken@0
   133
		}
slouken@0
   134
		if ( keyboard[VK_RMENU] & 0x80) {
slouken@0
   135
			state |= KMOD_RALT;
slouken@0
   136
		}
slouken@0
   137
		if ( keyboard[VK_NUMLOCK] & 0x80) {
slouken@0
   138
			state |= KMOD_NUM;
slouken@0
   139
		}
slouken@0
   140
		if ( keyboard[VK_CAPITAL] & 0x80) {
slouken@0
   141
			state |= KMOD_CAPS;
slouken@0
   142
		}
slouken@0
   143
	}
slouken@0
   144
	SDL_SetModState(state);
slouken@0
   145
#endif /* !NO_GETKEYBOARDSTATE */
slouken@0
   146
}
slouken@0
   147
slouken@0
   148
/* The main Win32 event handler */
slouken@0
   149
static LONG CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
slouken@0
   150
{
slouken@0
   151
	SDL_VideoDevice *this = current_video;
slouken@0
   152
	static int mouse_pressed = 0;
slouken@0
   153
	static int in_window = 0;
slouken@0
   154
#ifdef WMMSG_DEBUG
slouken@0
   155
	fprintf(stderr, "Received windows message:  ");
slouken@0
   156
	if ( msg > MAX_WMMSG ) {
slouken@0
   157
		fprintf(stderr, "%d", msg);
slouken@0
   158
	} else {
slouken@0
   159
		fprintf(stderr, "%s", wmtab[msg]);
slouken@0
   160
	}
slouken@0
   161
	fprintf(stderr, " -- 0x%X, 0x%X\n", wParam, lParam);
slouken@0
   162
#endif
slouken@0
   163
	switch (msg) {
slouken@0
   164
slouken@0
   165
		case WM_ACTIVATE: {
slouken@0
   166
			SDL_VideoDevice *this = current_video;
slouken@0
   167
			BOOL minimized;
slouken@0
   168
			Uint8 appstate;
slouken@0
   169
slouken@0
   170
			minimized = HIWORD(wParam);
slouken@0
   171
			if ( !minimized && (LOWORD(wParam) != WA_INACTIVE) ) {
slouken@0
   172
				/* Gain the following states */
slouken@0
   173
				appstate = SDL_APPACTIVE|SDL_APPINPUTFOCUS;
slouken@0
   174
				if ( this->input_grab != SDL_GRAB_OFF ) {
slouken@0
   175
					WIN_GrabInput(this, SDL_GRAB_ON);
slouken@0
   176
				}
slouken@0
   177
				if ( !(SDL_GetAppState()&SDL_APPINPUTFOCUS) ) {
slouken@0
   178
					WIN_SwapGamma(this);
slouken@0
   179
				}
slouken@0
   180
				posted = SDL_PrivateAppActive(1, appstate);
slouken@0
   181
				WIN_GetKeyboardState();
slouken@0
   182
			} else {
slouken@0
   183
				/* Lose the following states */
slouken@0
   184
				appstate = SDL_APPINPUTFOCUS;
slouken@0
   185
				if ( minimized ) {
slouken@0
   186
					appstate |= SDL_APPACTIVE;
slouken@0
   187
				}
slouken@0
   188
				if ( this->input_grab != SDL_GRAB_OFF ) {
slouken@0
   189
					WIN_GrabInput(this, SDL_GRAB_OFF);
slouken@0
   190
				}
slouken@0
   191
				if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) {
slouken@0
   192
					WIN_SwapGamma(this);
slouken@0
   193
				}
slouken@0
   194
				posted = SDL_PrivateAppActive(0, appstate);
slouken@0
   195
			}
slouken@0
   196
			return(0);
slouken@0
   197
		}
slouken@0
   198
		break;
slouken@0
   199
slouken@0
   200
		case WM_MOUSEMOVE: {
slouken@0
   201
			
slouken@0
   202
			/* Mouse is handled by DirectInput when fullscreen */
slouken@0
   203
			if ( SDL_VideoSurface && ! DIRECTX_FULLSCREEN() ) {
slouken@0
   204
				Sint16 x, y;
slouken@0
   205
slouken@0
   206
				/* mouse has entered the window */
slouken@0
   207
				if ( ! in_window ) {
slouken@0
   208
#ifdef WM_MOUSELEAVE
slouken@0
   209
					TRACKMOUSEEVENT tme;
slouken@0
   210
slouken@0
   211
					tme.cbSize = sizeof(tme);
slouken@0
   212
					tme.dwFlags = TME_LEAVE;
slouken@0
   213
					tme.hwndTrack = SDL_Window;
slouken@0
   214
					_TrackMouseEvent(&tme);
slouken@0
   215
#endif /* WM_MOUSELEAVE */
slouken@0
   216
					in_window = TRUE;
slouken@0
   217
slouken@0
   218
					posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
slouken@0
   219
				}
slouken@0
   220
slouken@0
   221
				/* mouse has moved within the window */
slouken@0
   222
				x = LOWORD(lParam);
slouken@0
   223
				y = HIWORD(lParam);
slouken@0
   224
				if ( mouse_relative ) {
slouken@0
   225
					POINT center;
slouken@0
   226
					center.x = (SDL_VideoSurface->w/2);
slouken@0
   227
					center.y = (SDL_VideoSurface->h/2);
slouken@0
   228
					x -= (Sint16)center.x;
slouken@0
   229
					y -= (Sint16)center.y;
slouken@0
   230
					if ( x || y ) {
slouken@0
   231
						ClientToScreen(SDL_Window, &center);
slouken@0
   232
						SetCursorPos(center.x, center.y);
slouken@0
   233
						posted = SDL_PrivateMouseMotion(0, 1, x, y);
slouken@0
   234
					}
slouken@0
   235
				} else {
slouken@0
   236
					posted = SDL_PrivateMouseMotion(0, 0, x, y);
slouken@0
   237
				}
slouken@0
   238
			}
slouken@0
   239
		}
slouken@0
   240
		return(0);
slouken@0
   241
slouken@0
   242
#ifdef WM_MOUSELEAVE
slouken@0
   243
		case WM_MOUSELEAVE: {
slouken@0
   244
slouken@0
   245
			/* Mouse is handled by DirectInput when fullscreen */
slouken@0
   246
			if ( SDL_VideoSurface && ! DIRECTX_FULLSCREEN() ) {
slouken@0
   247
				/* mouse has left the window */
slouken@0
   248
				/* or */
slouken@0
   249
				/* Elvis has left the building! */
slouken@0
   250
				in_window = FALSE;
slouken@0
   251
				posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
slouken@0
   252
			}
slouken@0
   253
		}
slouken@0
   254
		return(0);
slouken@0
   255
#endif /* WM_MOUSELEAVE */
slouken@0
   256
slouken@0
   257
		case WM_LBUTTONDOWN:
slouken@0
   258
		case WM_LBUTTONUP:
slouken@0
   259
		case WM_MBUTTONDOWN:
slouken@0
   260
		case WM_MBUTTONUP:
slouken@0
   261
		case WM_RBUTTONDOWN:
slouken@0
   262
		case WM_RBUTTONUP: {
slouken@0
   263
			/* Mouse is handled by DirectInput when fullscreen */
slouken@0
   264
			if ( SDL_VideoSurface && ! DIRECTX_FULLSCREEN() ) {
slouken@0
   265
				Sint16 x, y;
slouken@0
   266
				Uint8 button, state;
slouken@0
   267
slouken@0
   268
				/* Figure out which button to use */
slouken@0
   269
				switch (msg) {
slouken@0
   270
					case WM_LBUTTONDOWN:
slouken@0
   271
						button = 1;
slouken@0
   272
						state = SDL_PRESSED;
slouken@0
   273
						break;
slouken@0
   274
					case WM_LBUTTONUP:
slouken@0
   275
						button = 1;
slouken@0
   276
						state = SDL_RELEASED;
slouken@0
   277
						break;
slouken@0
   278
					case WM_MBUTTONDOWN:
slouken@0
   279
						button = 2;
slouken@0
   280
						state = SDL_PRESSED;
slouken@0
   281
						break;
slouken@0
   282
					case WM_MBUTTONUP:
slouken@0
   283
						button = 2;
slouken@0
   284
						state = SDL_RELEASED;
slouken@0
   285
						break;
slouken@0
   286
					case WM_RBUTTONDOWN:
slouken@0
   287
						button = 3;
slouken@0
   288
						state = SDL_PRESSED;
slouken@0
   289
						break;
slouken@0
   290
					case WM_RBUTTONUP:
slouken@0
   291
						button = 3;
slouken@0
   292
						state = SDL_RELEASED;
slouken@0
   293
						break;
slouken@0
   294
					default:
slouken@0
   295
						/* Eh? Unknown button? */
slouken@0
   296
						return(0);
slouken@0
   297
				}
slouken@0
   298
				if ( state == SDL_PRESSED ) {
slouken@0
   299
					/* Grab mouse so we get up events */
slouken@0
   300
					if ( ++mouse_pressed > 0 ) {
slouken@0
   301
						SetCapture(hwnd);
slouken@0
   302
					}
slouken@0
   303
				} else {
slouken@0
   304
					/* Release mouse after all up events */
slouken@0
   305
					if ( --mouse_pressed <= 0 ) {
slouken@0
   306
						ReleaseCapture();
slouken@0
   307
						mouse_pressed = 0;
slouken@0
   308
					}
slouken@0
   309
				}
slouken@0
   310
				if ( mouse_relative ) {
slouken@0
   311
				/*	RJR: March 28, 2000
slouken@0
   312
					report internal mouse position if in relative mode */
slouken@0
   313
					x = 0; y = 0;
slouken@0
   314
				} else {
slouken@0
   315
					x = (Sint16)LOWORD(lParam);
slouken@0
   316
					y = (Sint16)HIWORD(lParam);
slouken@0
   317
				}
slouken@0
   318
				posted = SDL_PrivateMouseButton(
slouken@0
   319
							state, button, x, y);
slouken@0
   320
			}
slouken@0
   321
		}
slouken@0
   322
		return(0);
slouken@0
   323
slouken@0
   324
#ifdef WM_GETMINMAXINFO
slouken@0
   325
		/* This message is sent as a way for us to "check" the values
slouken@0
   326
		 * of a position change.  If we don't like it, we can adjust
slouken@0
   327
		 * the values before they are changed.
slouken@0
   328
		 */
slouken@0
   329
		case WM_GETMINMAXINFO: {
slouken@0
   330
			MINMAXINFO *info;
slouken@0
   331
			RECT        size;
slouken@0
   332
			int x, y;
slouken@0
   333
			int width;
slouken@0
   334
			int height;
slouken@0
   335
slouken@0
   336
			/* We don't want to clobber an internal resize */
slouken@0
   337
			if ( SDL_resizing )
slouken@0
   338
				return(0);
slouken@0
   339
slouken@0
   340
			/* We allow resizing with the SDL_RESIZABLE flag */
slouken@0
   341
			if ( SDL_PublicSurface &&
slouken@0
   342
				(SDL_PublicSurface->flags & SDL_RESIZABLE) ) {
slouken@0
   343
				return(0);
slouken@0
   344
			}
slouken@0
   345
slouken@0
   346
			/* Get the current position of our window */
slouken@0
   347
			GetWindowRect(SDL_Window, &size);
slouken@0
   348
			x = size.left;
slouken@0
   349
			y = size.top;
slouken@0
   350
slouken@0
   351
			/* Calculate current width and height of our window */
slouken@0
   352
			size.top = 0;
slouken@0
   353
			size.left = 0;
slouken@0
   354
			if ( SDL_PublicSurface != NULL ) {
slouken@0
   355
				size.bottom = SDL_PublicSurface->h;
slouken@0
   356
				size.right = SDL_PublicSurface->w;
slouken@0
   357
			} else {
slouken@0
   358
				size.bottom = 0;
slouken@0
   359
				size.right = 0;
slouken@0
   360
			}
slouken@0
   361
			AdjustWindowRect(&size, GetWindowLong(hwnd, GWL_STYLE),
slouken@0
   362
									FALSE);
slouken@0
   363
			width = size.right - size.left;
slouken@0
   364
			height = size.bottom - size.top;
slouken@0
   365
slouken@0
   366
			/* Fix our size to the current size */
slouken@0
   367
			info = (MINMAXINFO *)lParam;
slouken@0
   368
			info->ptMaxSize.x = width;
slouken@0
   369
			info->ptMaxSize.y = height;
slouken@0
   370
			info->ptMaxPosition.x = x;
slouken@0
   371
			info->ptMaxPosition.y = y;
slouken@0
   372
			info->ptMinTrackSize.x = width;
slouken@0
   373
			info->ptMinTrackSize.y = height;
slouken@0
   374
			info->ptMaxTrackSize.x = width;
slouken@0
   375
			info->ptMaxTrackSize.y = height;
slouken@0
   376
		}
slouken@0
   377
		return(0);
slouken@0
   378
#endif /* WM_GETMINMAXINFO */
slouken@0
   379
slouken@0
   380
		case WM_MOVE: {
slouken@0
   381
			SDL_VideoDevice *this = current_video;
slouken@0
   382
slouken@0
   383
			GetClientRect(SDL_Window, &SDL_bounds);
slouken@0
   384
			ClientToScreen(SDL_Window, (LPPOINT)&SDL_bounds);
slouken@0
   385
			ClientToScreen(SDL_Window, (LPPOINT)&SDL_bounds+1);
slouken@0
   386
			if ( this->input_grab != SDL_GRAB_OFF ) {
slouken@0
   387
				ClipCursor(&SDL_bounds);
slouken@0
   388
			}
slouken@0
   389
		}
slouken@0
   390
		break;
slouken@0
   391
	
slouken@0
   392
		case WM_SIZE: {
slouken@0
   393
			if ( SDL_PublicSurface &&
slouken@0
   394
				(SDL_PublicSurface->flags & SDL_RESIZABLE) ) {
slouken@0
   395
				SDL_PrivateResize(LOWORD(lParam), HIWORD(lParam));
slouken@0
   396
			}
slouken@0
   397
			return(0);
slouken@0
   398
		}
slouken@0
   399
		break;
slouken@0
   400
slouken@0
   401
		/* We need to set the cursor */
slouken@0
   402
		case WM_SETCURSOR: {
slouken@0
   403
			Uint16 hittest;
slouken@0
   404
slouken@0
   405
			hittest = LOWORD(lParam);
slouken@0
   406
			if ( hittest == HTCLIENT ) {
slouken@0
   407
				SetCursor(SDL_hcursor);
slouken@0
   408
				return(TRUE);
slouken@0
   409
			}
slouken@0
   410
		}
slouken@0
   411
		break;
slouken@0
   412
slouken@0
   413
		/* We are about to get palette focus! */
slouken@0
   414
		case WM_QUERYNEWPALETTE: {
slouken@0
   415
			WIN_RealizePalette(current_video);
slouken@0
   416
			return(TRUE);
slouken@0
   417
		}
slouken@0
   418
		break;
slouken@0
   419
slouken@0
   420
		/* Another application changed the palette */
slouken@0
   421
		case WM_PALETTECHANGED: {
slouken@0
   422
			WIN_PaletteChanged(current_video, (HWND)wParam);
slouken@0
   423
		}
slouken@0
   424
		break;
slouken@0
   425
slouken@0
   426
		/* We were occluded, refresh our display */
slouken@0
   427
		case WM_PAINT: {
slouken@0
   428
			HDC hdc;
slouken@0
   429
			PAINTSTRUCT ps;
slouken@0
   430
slouken@0
   431
			hdc = BeginPaint(SDL_Window, &ps);
slouken@0
   432
			if ( current_video->screen &&
slouken@0
   433
			     !(current_video->screen->flags & SDL_OPENGL) ) {
slouken@0
   434
				WIN_WinPAINT(current_video, hdc);
slouken@0
   435
			}
slouken@0
   436
			EndPaint(SDL_Window, &ps);
slouken@0
   437
		}
slouken@0
   438
		return(0);
slouken@0
   439
slouken@0
   440
		case WM_ERASEBKGND: {
slouken@0
   441
			/* Just do nothing */ ;
slouken@0
   442
		}
slouken@0
   443
		return(1);
slouken@0
   444
slouken@0
   445
		case WM_CLOSE: {
slouken@0
   446
			if ( (posted = SDL_PrivateQuit()) )
slouken@0
   447
				PostQuitMessage(0);
slouken@0
   448
		}
slouken@0
   449
		return(0);
slouken@0
   450
slouken@0
   451
		case WM_DESTROY: {
slouken@0
   452
			PostQuitMessage(0);
slouken@0
   453
		}
slouken@0
   454
		return(0);
slouken@0
   455
slouken@0
   456
		default: {
slouken@0
   457
			/* Special handling by the video driver */
slouken@0
   458
			if (HandleMessage) {
slouken@0
   459
				return(HandleMessage(current_video,
slouken@0
   460
			                     hwnd, msg, wParam, lParam));
slouken@0
   461
			}
slouken@0
   462
		}
slouken@0
   463
		break;
slouken@0
   464
	}
slouken@0
   465
	return(DefWindowProc(hwnd, msg, wParam, lParam));
slouken@0
   466
}
slouken@0
   467
slouken@0
   468
/* This allows the SDL_WINDOWID hack */
slouken@0
   469
const char *SDL_windowid = NULL;
slouken@0
   470
slouken@0
   471
/* Register the class for this application -- exported for winmain.c */
slouken@0
   472
int SDL_RegisterApp(char *name, Uint32 style, void *hInst)
slouken@0
   473
{
slouken@0
   474
	static int initialized = 0;
slouken@0
   475
	WNDCLASS class;
slouken@0
   476
#ifdef WM_MOUSELEAVE
slouken@0
   477
	HMODULE handle;
slouken@0
   478
#endif
slouken@0
   479
slouken@0
   480
	/* Only do this once... */
slouken@0
   481
	if ( initialized ) {
slouken@0
   482
		return(0);
slouken@0
   483
	}
slouken@0
   484
slouken@0
   485
	/* This function needs to be passed the correct process handle
slouken@0
   486
	   by the application.  The following call just returns a handle
slouken@0
   487
	   to the SDL DLL, which is useless for our purposes and causes
slouken@0
   488
	   DirectInput to fail to initialize.
slouken@0
   489
	 */
slouken@0
   490
	if ( ! hInst ) {
slouken@0
   491
		hInst = GetModuleHandle(NULL);
slouken@0
   492
	}
slouken@0
   493
slouken@0
   494
	/* Register the application class */
slouken@0
   495
	class.hCursor		= NULL;
slouken@0
   496
#ifdef _WIN32_WCE
slouken@0
   497
    {
slouken@0
   498
	/* WinCE uses the UNICODE version */
slouken@0
   499
	int nLen = strlen(name);
slouken@0
   500
	LPWSTR lpszW = alloca((nLen+1)*2);
slouken@0
   501
	MultiByteToWideChar(CP_ACP, 0, name, -1, lpszW, nLen);
slouken@0
   502
	class.hIcon		= LoadImage(hInst, lpszW, IMAGE_ICON,
slouken@0
   503
	                                    0, 0, LR_DEFAULTCOLOR);
slouken@0
   504
	class.lpszMenuName	= lpszW;
slouken@0
   505
	class.lpszClassName	= lpszW;
slouken@0
   506
    }
slouken@0
   507
#else
slouken@0
   508
	class.hIcon		= LoadImage(hInst, name, IMAGE_ICON,
slouken@0
   509
	                                    0, 0, LR_DEFAULTCOLOR);
slouken@0
   510
	class.lpszMenuName	= "(none)";
slouken@0
   511
	class.lpszClassName	= name;
slouken@0
   512
#endif /* _WIN32_WCE */
slouken@0
   513
	class.hbrBackground	= NULL;
slouken@0
   514
	class.hInstance		= hInst ? hInst : GetModuleHandle(0);
slouken@0
   515
	class.style		= style;
slouken@0
   516
#ifdef HAVE_OPENGL
slouken@0
   517
	class.style		|= CS_OWNDC;
slouken@0
   518
#endif
slouken@0
   519
	class.lpfnWndProc	= WinMessage;
slouken@0
   520
	class.cbWndExtra	= 0;
slouken@0
   521
	class.cbClsExtra	= 0;
slouken@0
   522
	if ( ! RegisterClass(&class) ) {
slouken@0
   523
		SDL_SetError("Couldn't register application class");
slouken@0
   524
		return(-1);
slouken@0
   525
	}
slouken@0
   526
	SDL_Appname = name;
slouken@0
   527
	SDL_Instance = hInst;
slouken@0
   528
slouken@0
   529
#ifdef WM_MOUSELEAVE
slouken@0
   530
	/* Get the version of TrackMouseEvent() we use */
slouken@0
   531
	_TrackMouseEvent = NULL;
slouken@0
   532
	handle = GetModuleHandle("USER32.DLL");
slouken@0
   533
	if ( handle ) {
slouken@0
   534
		_TrackMouseEvent = (BOOL (WINAPI *)(TRACKMOUSEEVENT *))GetProcAddress(handle, "TrackMouseEvent");
slouken@0
   535
	}
slouken@0
   536
	if ( _TrackMouseEvent == NULL ) {
slouken@0
   537
		_TrackMouseEvent = WIN_TrackMouseEvent;
slouken@0
   538
	}
slouken@0
   539
#endif /* WM_MOUSELEAVE */
slouken@0
   540
slouken@0
   541
	/* Check for SDL_WINDOWID hack */
slouken@0
   542
	SDL_windowid = getenv("SDL_WINDOWID");
slouken@0
   543
slouken@0
   544
	initialized = 1;
slouken@0
   545
	return(0);
slouken@0
   546
}
slouken@0
   547