Added the concept of the HelperWindow to help with DirectInput. gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Mon, 04 Aug 2008 11:22:01 +0000
branchgsoc2008_force_feedback
changeset 258064fa227c01ce
parent 2579 bd2a6c70cb29
child 2581 a1c00531ee00
Added the concept of the HelperWindow to help with DirectInput.
src/SDL.c
src/haptic/win32/SDL_syshaptic.c
src/joystick/win32/SDL_dxjoystick.c
src/video/win32/SDL_win32window.c
     1.1 --- a/src/SDL.c	Sun Aug 03 10:25:25 2008 +0000
     1.2 +++ b/src/SDL.c	Mon Aug 04 11:22:01 2008 +0000
     1.3 @@ -51,6 +51,10 @@
     1.4  extern int SDL_TimerInit(void);
     1.5  extern void SDL_TimerQuit(void);
     1.6  #endif
     1.7 +#if defined(__WIN32__)
     1.8 +extern int SDL_HelperWindowCreate(void);
     1.9 +extern int SDL_HelperWindowDestroy(void);
    1.10 +#endif
    1.11  
    1.12  /* The initialized subsystems */
    1.13  static Uint32 SDL_initialized = 0;
    1.14 @@ -172,6 +176,12 @@
    1.15      /* Clear the error message */
    1.16      SDL_ClearError();
    1.17  
    1.18 +#if defined(__WIN32__)
    1.19 +    if (SDL_HelperWindowCreate() < 0) {
    1.20 +        return -1;
    1.21 +    }
    1.22 +#endif
    1.23 +
    1.24      /* Initialize the desired subsystems */
    1.25      if (SDL_InitSubSystem(flags) < 0) {
    1.26          return (-1);
    1.27 @@ -243,6 +253,10 @@
    1.28      printf("[SDL_Quit] : Enter! Calling QuitSubSystem()\n");
    1.29      fflush(stdout);
    1.30  #endif
    1.31 +
    1.32 +#if defined(__WIN32__)
    1.33 +    SDL_HelperWindowDestroy();
    1.34 +#endif
    1.35      SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
    1.36  
    1.37  #ifdef CHECK_LEAKS
     2.1 --- a/src/haptic/win32/SDL_syshaptic.c	Sun Aug 03 10:25:25 2008 +0000
     2.2 +++ b/src/haptic/win32/SDL_syshaptic.c	Mon Aug 04 11:22:01 2008 +0000
     2.3 @@ -36,7 +36,9 @@
     2.4  #include <dinput.h>
     2.5  #include <dxerr.h>
     2.6  #ifdef _MSC_VER
     2.7 -#   pragma comment (lib, "dxerr.lib")
     2.8 +#  pragma comment (lib, "dinput8.lib")
     2.9 +#  pragma comment (lib, "dxguid.lib")
    2.10 +#  pragma comment (lib, "dxerr.lib")
    2.11  #endif /* _MSC_VER */
    2.12  
    2.13      /* an ISO hack for VisualC++ */
    2.14 @@ -88,7 +90,7 @@
    2.15   * External stuff.
    2.16   */
    2.17  extern HINSTANCE SDL_Instance;
    2.18 -extern HWND SDL_Window;
    2.19 +extern HWND SDL_HelperWindow;
    2.20  
    2.21  
    2.22  /*
    2.23 @@ -274,7 +276,7 @@
    2.24  
    2.25     /* Grab it exclusively to use force feedback stuff. */
    2.26     ret =IDirectInputDevice2_SetCooperativeLevel( haptic->hwdata->device,
    2.27 -                                                 SDL_Window,
    2.28 +                                                 SDL_HelperWindow,
    2.29                                                   DISCL_EXCLUSIVE | DISCL_BACKGROUND );
    2.30     if (FAILED(ret)) {
    2.31        DI_SetError("Setting cooperative level to exclusive",ret);
     3.1 --- a/src/joystick/win32/SDL_dxjoystick.c	Sun Aug 03 10:25:25 2008 +0000
     3.2 +++ b/src/joystick/win32/SDL_dxjoystick.c	Mon Aug 04 11:22:01 2008 +0000
     3.3 @@ -67,7 +67,7 @@
     3.4  
     3.5  /* external variables referenced. */
     3.6  extern HINSTANCE SDL_Instance;
     3.7 -extern HWND SDL_Window;
     3.8 +extern HWND SDL_HelperWindow;
     3.9  
    3.10  
    3.11  /* local variables */
    3.12 @@ -250,7 +250,7 @@
    3.13       * though. */
    3.14      result =
    3.15          IDirectInputDevice2_SetCooperativeLevel(joystick->hwdata->
    3.16 -                                                InputDevice, SDL_Window,
    3.17 +                                                InputDevice, SDL_HelperWindow,
    3.18                                                  DISCL_EXCLUSIVE |
    3.19                                                  DISCL_BACKGROUND);
    3.20      if (FAILED(result)) {
     4.1 --- a/src/video/win32/SDL_win32window.c	Sun Aug 03 10:25:25 2008 +0000
     4.2 +++ b/src/video/win32/SDL_win32window.c	Mon Aug 04 11:22:01 2008 +0000
     4.3 @@ -30,6 +30,10 @@
     4.4  #include "SDL_syswm.h"
     4.5  
     4.6  
     4.7 +/* Fake window to help with DirectInput events. */
     4.8 +HWND SDL_HelperWindow = NULL;
     4.9 +
    4.10 +
    4.11  static int
    4.12  SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
    4.13  {
    4.14 @@ -409,4 +413,48 @@
    4.15      }
    4.16  }
    4.17  
    4.18 +
    4.19 +/*
    4.20 + * Creates a HelperWindow used for DirectInput events.
    4.21 + */
    4.22 +int
    4.23 +SDL_HelperWindowCreate(void)
    4.24 +{
    4.25 +   HINSTANCE hInstance = pGetModuleHandleA(NULL);
    4.26 +   const char *class_name = "SDLHelperWindowInputCatcher";
    4.27 +   const char *win_name = "SDLHelperWindowInputMsgWindow";
    4.28 +   WNDCLASSEX wce;
    4.29 +
    4.30 +   ZeroMemory(&wce, sizeof (wce));
    4.31 +   wce.cbSize = sizeof(WNDCLASSEX);
    4.32 +   wce.lpfnWndProc = RawWndProc;
    4.33 +   wce.lpszClassName = class_name;
    4.34 +   wce.hInstance = hInstance;
    4.35 +
    4.36 +   SDL_HelperWindow = pCreateWindowExA(0, class_name, win_name, WS_OVERLAPPEDWINDOW,
    4.37 +         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
    4.38 +         CW_USEDEFAULT, HWND_MESSAGE, NULL, hInstance, NULL);
    4.39 +
    4.40 +   if (SDL_HelperWindow == NULL) {
    4.41 +      SDL_SetError("Unable to create Helper Window.");
    4.42 +      return -1;
    4.43 +   }
    4.44 +
    4.45 +   return 0;
    4.46 +}
    4.47 +
    4.48 +
    4.49 +/*
    4.50 + * Destroys the HelperWindow previously created with SDL_HelperWindowCreate.
    4.51 + */
    4.52 +void
    4.53 +SDL_HelperWindowDestroy(void)
    4.54 +{
    4.55 +   if (SDL_HelperWindow) {
    4.56 +      pDestroyWindow(SDL_HelperWindow);
    4.57 +      SDL_HelperWindow = NULL;
    4.58 +   }
    4.59 +}
    4.60 +
    4.61 +
    4.62  /* vi: set ts=4 sw=4 expandtab: */