[PATCH 2/2] joystick.cpl: Added joystick listing

Lucas Fialho Zawacki lfzawacki at gmail.com
Sun Jun 3 23:19:53 CDT 2012


From: Lucas Fialho Zawacki <lfzawacki at gmail.com>

---
 dlls/joystick.cpl/joystick.h  |    5 +++
 dlls/joystick.cpl/joystick.rc |    6 ++++
 dlls/joystick.cpl/list.c      |   24 +++++++++++++
 dlls/joystick.cpl/main.c      |   80 ++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 114 insertions(+), 1 deletion(-)

diff --git a/dlls/joystick.cpl/joystick.h b/dlls/joystick.cpl/joystick.h
index 52f6b72..2c992f9 100644
--- a/dlls/joystick.cpl/joystick.h
+++ b/dlls/joystick.cpl/joystick.h
@@ -60,4 +60,9 @@ struct JoystickData {
 #define IDD_TEST            1001
 #define IDD_FORCEFEEDBACK   1002
 
+#define IDC_JOYSTICKLIST    2000
+#define IDC_BUTTONDISABLE   2001
+#define IDC_BUTTONENABLE    2002
+#define IDC_DISABLEDLIST    2003
+
 #endif
diff --git a/dlls/joystick.cpl/joystick.rc b/dlls/joystick.cpl/joystick.rc
index cce2e30..10977b3 100644
--- a/dlls/joystick.cpl/joystick.rc
+++ b/dlls/joystick.cpl/joystick.rc
@@ -33,6 +33,12 @@ STYLE WS_CAPTION | WS_CHILD | WS_DISABLED
 CAPTION "Joysticks"
 FONT 8, "Ms Shell Dlg"
 {
+    PUSHBUTTON      "Disable", IDC_BUTTONDISABLE, 190, 20, 50, 15
+    PUSHBUTTON      "Enable", IDC_BUTTONENABLE, 190, 95, 50, 15
+    LTEXT           "Connected", IDC_STATIC, 10, 10, 100, 10
+    LISTBOX         IDC_JOYSTICKLIST, 10, 20, 160, 70, WS_TABSTOP | WS_VSCROLL | LBS_NOTIFY
+    LTEXT           "Disabled", IDC_STATIC, 10, 85, 100, 10
+    LISTBOX         IDC_DISABLEDLIST, 10, 95, 160, 50, WS_TABSTOP | WS_VSCROLL | LBS_NOTIFY
 }
 
 IDD_TEST DIALOG 0, 0, 250, 200
diff --git a/dlls/joystick.cpl/list.c b/dlls/joystick.cpl/list.c
index 5883faa..e231f91 100644
--- a/dlls/joystick.cpl/list.c
+++ b/dlls/joystick.cpl/list.c
@@ -42,9 +42,33 @@ INT_PTR CALLBACK list_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
     switch (msg)
     {
         case WM_INITDIALOG:
+        {
+            int i;
+            struct JoystickData *data = (struct JoystickData*) ((PROPSHEETPAGEW*)lparam)->lParam;
+
+            /* Set dialog information */
+            for (i = 0; i < data->num_joysticks; i++)
+            {
+                struct Joystick *joy = &data->joysticks[i];
+                SendDlgItemMessageW(hwnd, IDC_JOYSTICKLIST, LB_ADDSTRING, 0, (LPARAM) joy->instance.tszInstanceName);
+            }
+
             return TRUE;
+        }
 
         case WM_COMMAND:
+
+            switch (LOWORD(wparam))
+            {
+                case IDC_BUTTONDISABLE:
+                    FIXME("Disable selected joystick from being enumerated\n");
+                    break;
+
+                case IDC_BUTTONENABLE:
+                    FIXME("Re-Enable selected joystick\n");
+                    break;
+            }
+
             return TRUE;
 
         case WM_NOTIFY:
diff --git a/dlls/joystick.cpl/main.c b/dlls/joystick.cpl/main.c
index 55e9a4e..60f7c87 100644
--- a/dlls/joystick.cpl/main.c
+++ b/dlls/joystick.cpl/main.c
@@ -66,6 +66,65 @@ HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
     return S_OK;
 }
 
+/***********************************************************************
+ *  enum_callback [internal]
+ *   Enumerates, creates and sets the common data format for all the joystick devices.
+ *   First time it checks if space for the joysticks was already reserved
+ *   and if not, just counts how many there are.
+ */
+static BOOL CALLBACK enum_callback(const DIDEVICEINSTANCEW *instance, void *context)
+{
+    struct JoystickData *data = context;
+    struct Joystick *joystick;
+
+    if (data->joysticks == NULL)
+    {
+        data->num_joysticks += 1;
+        return DIENUM_CONTINUE;
+    }
+
+    joystick = &data->joysticks[data->cur_joystick];
+    data->cur_joystick += 1;
+
+    IDirectInput8_CreateDevice(data->di, &instance->guidInstance, &joystick->device, NULL);
+    IDirectInputDevice8_SetDataFormat(joystick->device, &c_dfDIJoystick);
+
+    joystick->instance = *instance;
+
+    return DIENUM_CONTINUE;
+}
+
+/***********************************************************************
+ *  initialize_joysticks [internal]
+ */
+static void initialize_joysticks(struct JoystickData *data)
+{
+    /* First count how many joysticks are connected */
+    data->num_joysticks = 0;
+    data->cur_joystick = 0;
+    IDirectInput8_EnumDevices(data->di, DI8DEVCLASS_GAMECTRL, enum_callback, data, DIEDFL_ATTACHEDONLY);
+    data->joysticks = HeapAlloc(GetProcessHeap(), 0, sizeof(struct Joystick) * data->num_joysticks);
+
+    /* Get all the joysticks */
+    IDirectInput8_EnumDevices(data->di, DI8DEVCLASS_GAMECTRL, enum_callback, data, DIEDFL_ATTACHEDONLY);
+}
+
+/***********************************************************************
+ *  destroy_joysticks [internal]
+ */
+static void destroy_joysticks(struct JoystickData *data)
+{
+    int i;
+
+    for (i = 0; i < data->num_joysticks; i++)
+    {
+        IDirectInputDevice8_Unacquire(data->joysticks[i].device);
+        IDirectInputDevice8_Release(data->joysticks[i].device);
+    }
+
+    HeapFree(GetProcessHeap(), 0, data->joysticks);
+}
+
 /******************************************************************************
  * propsheet_callback [internal]
  *
@@ -164,8 +223,23 @@ LONG CALLBACK CPlApplet(HWND hwnd, UINT command, LPARAM lParam1, LPARAM lParam2)
     switch (command)
     {
         case CPL_INIT:
-            return TRUE;
+        {
+            HRESULT hr;
+
+            /* Initialize dinput */
+            hr = DirectInput8Create(GetModuleHandleW(NULL), DIRECTINPUT_VERSION, &IID_IDirectInput8W, (void**)&data.di, NULL);
+
+            if (FAILED(hr))
+            {
+                ERR("Failed to initialize DirectInput: 0x%08x\n", hr);
+                return FALSE;
+            }
 
+            /* Then get all the connected joysticks */
+            initialize_joysticks(&data);
+
+            return TRUE;
+        }
         case CPL_GETCOUNT:
             return 1;
 
@@ -184,6 +258,10 @@ LONG CALLBACK CPlApplet(HWND hwnd, UINT command, LPARAM lParam1, LPARAM lParam2)
             break;
 
         case CPL_STOP:
+            destroy_joysticks(&data);
+
+            /* And destroy dinput too */
+            IDirectInput8_Release(data.di);
             break;
     }
 
-- 
1.7.9.5




More information about the wine-patches mailing list