diff src/video/win32/SDL_win32window.c @ 2713:0906692aa6a4

Final merge of Google Summer of Code 2008 work... Force Feedback for SDL by Edgar Simo, mentored by Ryan C. Gordon
author Sam Lantinga <slouken@libsdl.org>
date Mon, 25 Aug 2008 09:55:03 +0000
parents 44e49d3fa6cf
children 1d1be6137875
line wrap: on
line diff
--- a/src/video/win32/SDL_win32window.c	Mon Aug 25 08:50:37 2008 +0000
+++ b/src/video/win32/SDL_win32window.c	Mon Aug 25 09:55:03 2008 +0000
@@ -47,6 +47,12 @@
 extern HCTX *g_hCtx;            /* the table of tablet event contexts, each windows has to have it's own tablet context */
 int highestId = 0;              /* the highest id of the tablet context */
 
+/* Fake window to help with DirectInput events. */
+HWND SDL_HelperWindow = NULL;
+static const char *SDL_HelperWindowClassName = "SDLHelperWindowInputCatcher";
+static const char *SDL_HelperWindowName = "SDLHelperWindowInputMsgWindow";
+static ATOM SDL_HelperWindowClass = 0;
+
 static int
 SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
 {
@@ -470,4 +476,66 @@
     }
 }
 
+
+/*
+ * Creates a HelperWindow used for DirectInput events.
+ */
+int
+SDL_HelperWindowCreate(void)
+{
+    HINSTANCE hInstance = GetModuleHandleA(NULL);
+    WNDCLASSEX wce;
+
+    /* Create the class. */
+    SDL_memset(&wce, 0, sizeof(wce));
+    wce.cbSize = sizeof(WNDCLASSEX);
+    wce.lpfnWndProc = DefWindowProcA;
+    wce.lpszClassName = (LPCWSTR) SDL_HelperWindowClassName;
+    wce.hInstance = hInstance;
+
+    /* Register the class. */
+    SDL_HelperWindowClass = RegisterClassExA(&wce);
+    if (SDL_HelperWindowClass == 0) {
+        SDL_SetError("Unable to create Helper Window Class: error %d.",
+                     GetLastError());
+        return -1;
+    }
+
+    /* Create the window. */
+    SDL_HelperWindow = CreateWindowExA(0, SDL_HelperWindowClassName,
+                                       SDL_HelperWindowName,
+                                       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: error %d.",
+                     GetLastError());
+        return -1;
+    }
+
+    return 0;
+}
+
+
+/*
+ * Destroys the HelperWindow previously created with SDL_HelperWindowCreate.
+ */
+void
+SDL_HelperWindowDestroy(void)
+{
+    /* Destroy the window. */
+    if (SDL_HelperWindow) {
+        DestroyWindow(SDL_HelperWindow);
+        SDL_HelperWindow = NULL;
+    }
+
+    /* Unregister the class. */
+    if (SDL_HelperWindowClass) {
+        UnregisterClassA(SDL_HelperWindowClassName, GetModuleHandleA(NULL));
+        SDL_HelperWindowClass = 0;
+    }
+}
+
+
 /* vi: set ts=4 sw=4 expandtab: */