comparison src/video/wincommon/SDL_sysevents.c @ 145:29a638dc26db

Applied David MacCormack's patch to fix SDL_WINDOWID on Windows, and added a function to cache the application handle so DirectInput still works properly.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 09 Aug 2001 12:21:32 +0000
parents 994ed1d668e7
children 0e66fd980014
comparison
equal deleted inserted replaced
144:1cfa4282f2eb 145:29a638dc26db
143 } 143 }
144 SDL_SetModState(state); 144 SDL_SetModState(state);
145 #endif /* !NO_GETKEYBOARDSTATE */ 145 #endif /* !NO_GETKEYBOARDSTATE */
146 } 146 }
147 147
148 /* The main Win32 event handler */ 148 /* The main Win32 event handler
149 static LONG CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 149 DJM: This is no longer static as (DX5/DIB)_CreateWindow needs it
150 */
151 LONG CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
150 { 152 {
151 SDL_VideoDevice *this = current_video; 153 SDL_VideoDevice *this = current_video;
152 static int mouse_pressed = 0; 154 static int mouse_pressed = 0;
153 static int in_window = 0; 155 static int in_window = 0;
154 #ifdef WMMSG_DEBUG 156 #ifdef WMMSG_DEBUG
262 case WM_RBUTTONUP: { 264 case WM_RBUTTONUP: {
263 /* Mouse is handled by DirectInput when fullscreen */ 265 /* Mouse is handled by DirectInput when fullscreen */
264 if ( SDL_VideoSurface && ! DINPUT_FULLSCREEN() ) { 266 if ( SDL_VideoSurface && ! DINPUT_FULLSCREEN() ) {
265 Sint16 x, y; 267 Sint16 x, y;
266 Uint8 button, state; 268 Uint8 button, state;
269
270 /* DJM:
271 We want the SDL window to take focus so that
272 it acts like a normal windows "component"
273 (e.g. gains keyboard focus on a mouse click).
274 */
275 SetFocus(SDL_Window);
267 276
268 /* Figure out which button to use */ 277 /* Figure out which button to use */
269 switch (msg) { 278 switch (msg) {
270 case WM_LBUTTONDOWN: 279 case WM_LBUTTONDOWN:
271 button = 1; 280 button = 1;
463 } 472 }
464 EndPaint(SDL_Window, &ps); 473 EndPaint(SDL_Window, &ps);
465 } 474 }
466 return(0); 475 return(0);
467 476
477 /* DJM: Send an expose event in this case */
468 case WM_ERASEBKGND: { 478 case WM_ERASEBKGND: {
469 /* Just do nothing */ ; 479 posted = SDL_PrivateExpose();
470 } 480 }
471 return(1); 481 return(0);
472 482
473 case WM_CLOSE: { 483 case WM_CLOSE: {
474 if ( (posted = SDL_PrivateQuit()) ) 484 if ( (posted = SDL_PrivateQuit()) )
475 PostQuitMessage(0); 485 PostQuitMessage(0);
476 } 486 }
491 break; 501 break;
492 } 502 }
493 return(DefWindowProc(hwnd, msg, wParam, lParam)); 503 return(DefWindowProc(hwnd, msg, wParam, lParam));
494 } 504 }
495 505
506 /* Allow the application handle to be stored and retrieved later */
507 static HMODULE SDL_handle = NULL;
508
509 void SDL_SetModuleHandle(HMODULE handle)
510 {
511 SDL_handle = handle;
512 }
513 HMODULE SDL_GetModuleHandle(void)
514 {
515 void *handle;
516
517 if ( SDL_handle ) {
518 handle = SDL_handle;
519 } else {
520 /* Warning:
521 If SDL is built as a DLL, this will return a handle to
522 the DLL, not the application, and DirectInput may fail
523 to initialize.
524 */
525 handle = GetModuleHandle(NULL);
526 }
527 return(handle);
528 }
529
496 /* This allows the SDL_WINDOWID hack */ 530 /* This allows the SDL_WINDOWID hack */
497 const char *SDL_windowid = NULL; 531 const char *SDL_windowid = NULL;
498 532
499 /* Register the class for this application -- exported for winmain.c */ 533 /* Register the class for this application -- exported for winmain.c */
500 int SDL_RegisterApp(char *name, Uint32 style, void *hInst) 534 int SDL_RegisterApp(char *name, Uint32 style, HMODULE hInst)
501 { 535 {
502 static int initialized = 0; 536 static int initialized = 0;
503 WNDCLASS class; 537 WNDCLASS class;
504 #ifdef WM_MOUSELEAVE 538 #ifdef WM_MOUSELEAVE
505 HMODULE handle; 539 HMODULE handle;
509 if ( initialized ) { 543 if ( initialized ) {
510 return(0); 544 return(0);
511 } 545 }
512 546
513 /* This function needs to be passed the correct process handle 547 /* This function needs to be passed the correct process handle
514 by the application. The following call just returns a handle 548 by the application.
515 to the SDL DLL, which is useless for our purposes and causes
516 DirectInput to fail to initialize.
517 */ 549 */
518 if ( ! hInst ) { 550 if ( ! hInst ) {
519 hInst = GetModuleHandle(NULL); 551 hInst = SDL_GetModuleHandle();
520 } 552 }
521 553
522 /* Register the application class */ 554 /* Register the application class */
523 class.hCursor = NULL; 555 class.hCursor = NULL;
524 #ifdef _WIN32_WCE 556 #ifdef _WIN32_WCE