Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added the concept of the HelperWindow to help with DirectInput.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbens committed Aug 4, 2008
1 parent 029bf23 commit 9d0b65c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
14 changes: 14 additions & 0 deletions src/SDL.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/haptic/win32/SDL_syshaptic.c
Expand Up @@ -36,7 +36,9 @@
#include <dinput.h>
#include <dxerr.h>
#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++ */
Expand Down Expand Up @@ -88,7 +90,7 @@ static LPDIRECTINPUT dinput = NULL;
* External stuff.
*/
extern HINSTANCE SDL_Instance;
extern HWND SDL_Window;
extern HWND SDL_HelperWindow;


/*
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/joystick/win32/SDL_dxjoystick.c
Expand Up @@ -67,7 +67,7 @@

/* external variables referenced. */
extern HINSTANCE SDL_Instance;
extern HWND SDL_Window;
extern HWND SDL_HelperWindow;


/* local variables */
Expand Down Expand Up @@ -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)) {
Expand Down
48 changes: 48 additions & 0 deletions src/video/win32/SDL_win32window.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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: */

0 comments on commit 9d0b65c

Please sign in to comment.