# HG changeset patch # User Edgar Simo # Date 1217848921 0 # Node ID 64fa227c01cef09c6cdfee6a11280ea3227ff51d # Parent bd2a6c70cb298ac960b13bc92775bcb84c89cc3f Added the concept of the HelperWindow to help with DirectInput. diff -r bd2a6c70cb29 -r 64fa227c01ce src/SDL.c --- a/src/SDL.c Sun Aug 03 10:25:25 2008 +0000 +++ b/src/SDL.c Mon Aug 04 11:22:01 2008 +0000 @@ -51,6 +51,10 @@ extern int SDL_TimerInit(void); extern void SDL_TimerQuit(void); #endif +#if defined(__WIN32__) +extern int SDL_HelperWindowCreate(void); +extern int SDL_HelperWindowDestroy(void); +#endif /* The initialized subsystems */ static Uint32 SDL_initialized = 0; @@ -172,6 +176,12 @@ /* Clear the error message */ SDL_ClearError(); +#if defined(__WIN32__) + if (SDL_HelperWindowCreate() < 0) { + return -1; + } +#endif + /* Initialize the desired subsystems */ if (SDL_InitSubSystem(flags) < 0) { return (-1); @@ -243,6 +253,10 @@ printf("[SDL_Quit] : Enter! Calling QuitSubSystem()\n"); fflush(stdout); #endif + +#if defined(__WIN32__) + SDL_HelperWindowDestroy(); +#endif SDL_QuitSubSystem(SDL_INIT_EVERYTHING); #ifdef CHECK_LEAKS diff -r bd2a6c70cb29 -r 64fa227c01ce src/haptic/win32/SDL_syshaptic.c --- a/src/haptic/win32/SDL_syshaptic.c Sun Aug 03 10:25:25 2008 +0000 +++ b/src/haptic/win32/SDL_syshaptic.c Mon Aug 04 11:22:01 2008 +0000 @@ -36,7 +36,9 @@ #include #include #ifdef _MSC_VER -# pragma comment (lib, "dxerr.lib") +# pragma comment (lib, "dinput8.lib") +# pragma comment (lib, "dxguid.lib") +# pragma comment (lib, "dxerr.lib") #endif /* _MSC_VER */ /* an ISO hack for VisualC++ */ @@ -88,7 +90,7 @@ * External stuff. */ extern HINSTANCE SDL_Instance; -extern HWND SDL_Window; +extern HWND SDL_HelperWindow; /* @@ -274,7 +276,7 @@ /* Grab it exclusively to use force feedback stuff. */ ret =IDirectInputDevice2_SetCooperativeLevel( haptic->hwdata->device, - SDL_Window, + SDL_HelperWindow, DISCL_EXCLUSIVE | DISCL_BACKGROUND ); if (FAILED(ret)) { DI_SetError("Setting cooperative level to exclusive",ret); diff -r bd2a6c70cb29 -r 64fa227c01ce src/joystick/win32/SDL_dxjoystick.c --- a/src/joystick/win32/SDL_dxjoystick.c Sun Aug 03 10:25:25 2008 +0000 +++ b/src/joystick/win32/SDL_dxjoystick.c Mon Aug 04 11:22:01 2008 +0000 @@ -67,7 +67,7 @@ /* external variables referenced. */ extern HINSTANCE SDL_Instance; -extern HWND SDL_Window; +extern HWND SDL_HelperWindow; /* local variables */ @@ -250,7 +250,7 @@ * though. */ result = IDirectInputDevice2_SetCooperativeLevel(joystick->hwdata-> - InputDevice, SDL_Window, + InputDevice, SDL_HelperWindow, DISCL_EXCLUSIVE | DISCL_BACKGROUND); if (FAILED(result)) { diff -r bd2a6c70cb29 -r 64fa227c01ce src/video/win32/SDL_win32window.c --- a/src/video/win32/SDL_win32window.c Sun Aug 03 10:25:25 2008 +0000 +++ b/src/video/win32/SDL_win32window.c Mon Aug 04 11:22:01 2008 +0000 @@ -30,6 +30,10 @@ #include "SDL_syswm.h" +/* Fake window to help with DirectInput events. */ +HWND SDL_HelperWindow = NULL; + + static int SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created) { @@ -409,4 +413,48 @@ } } + +/* + * Creates a HelperWindow used for DirectInput events. + */ +int +SDL_HelperWindowCreate(void) +{ + HINSTANCE hInstance = pGetModuleHandleA(NULL); + const char *class_name = "SDLHelperWindowInputCatcher"; + const char *win_name = "SDLHelperWindowInputMsgWindow"; + WNDCLASSEX wce; + + ZeroMemory(&wce, sizeof (wce)); + wce.cbSize = sizeof(WNDCLASSEX); + wce.lpfnWndProc = RawWndProc; + wce.lpszClassName = class_name; + wce.hInstance = hInstance; + + SDL_HelperWindow = pCreateWindowExA(0, class_name, win_name, WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + CW_USEDEFAULT, HWND_MESSAGE, NULL, hInstance, NULL); + + if (SDL_HelperWindow == NULL) { + SDL_SetError("Unable to create Helper Window."); + return -1; + } + + return 0; +} + + +/* + * Destroys the HelperWindow previously created with SDL_HelperWindowCreate. + */ +void +SDL_HelperWindowDestroy(void) +{ + if (SDL_HelperWindow) { + pDestroyWindow(SDL_HelperWindow); + SDL_HelperWindow = NULL; + } +} + + /* vi: set ts=4 sw=4 expandtab: */