From 9d0b65ce847b838366cb8ac67718c7dbe661e2e4 Mon Sep 17 00:00:00 2001 From: Edgar Simo Date: Mon, 4 Aug 2008 11:22:01 +0000 Subject: [PATCH] Added the concept of the HelperWindow to help with DirectInput. --- src/SDL.c | 14 +++++++++ src/haptic/win32/SDL_syshaptic.c | 8 +++-- src/joystick/win32/SDL_dxjoystick.c | 4 +-- src/video/win32/SDL_win32window.c | 48 +++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 5 deletions(-) diff --git a/src/SDL.c b/src/SDL.c index 968ab75e2..55f826071 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -51,6 +51,10 @@ extern void SDL_StartTicks(void); 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 @@ SDL_Init(Uint32 flags) /* 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 @@ SDL_Quit(void) 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 --git a/src/haptic/win32/SDL_syshaptic.c b/src/haptic/win32/SDL_syshaptic.c index ba2e5723e..291432cfc 100644 --- a/src/haptic/win32/SDL_syshaptic.c +++ b/src/haptic/win32/SDL_syshaptic.c @@ -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 @@ static LPDIRECTINPUT dinput = NULL; * External stuff. */ extern HINSTANCE SDL_Instance; -extern HWND SDL_Window; +extern HWND SDL_HelperWindow; /* @@ -274,7 +276,7 @@ SDL_SYS_HapticOpenFromInstance(SDL_Haptic * haptic, DIDEVICEINSTANCE instance) /* 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 --git a/src/joystick/win32/SDL_dxjoystick.c b/src/joystick/win32/SDL_dxjoystick.c index 563e3a01a..1ed5e1413 100644 --- a/src/joystick/win32/SDL_dxjoystick.c +++ b/src/joystick/win32/SDL_dxjoystick.c @@ -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 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick) * though. */ result = IDirectInputDevice2_SetCooperativeLevel(joystick->hwdata-> - InputDevice, SDL_Window, + InputDevice, SDL_HelperWindow, DISCL_EXCLUSIVE | DISCL_BACKGROUND); if (FAILED(result)) { diff --git a/src/video/win32/SDL_win32window.c b/src/video/win32/SDL_win32window.c index 07dc1a1f2..5be178fd8 100644 --- a/src/video/win32/SDL_win32window.c +++ b/src/video/win32/SDL_win32window.c @@ -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 @@ WIN_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info) } } + +/* + * 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: */