ReactOS 0.4.16-dev-336-gb667d82
input.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactX Diagnosis Application
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: base/applications/dxdiag/input.c
5 * PURPOSE: ReactX diagnosis input page
6 * COPYRIGHT: Copyright 2008 Johannes Anderwald
7 *
8 */
9
10#include "precomp.h"
11
12#include <dinput.h>
13
14typedef struct
15{
17 IDirectInput8W * pObj;
22
23
26 LPVOID pvRef
27)
28{
29 HRESULT hResult;
30 WCHAR szText[100];
31 IDirectInputDevice8W * pDev = NULL;
32 //DIPROPGUIDANDPATH GuidPath;
33 //DIPROPSTRING TypeName;
34 DIPROPDWORD VendorID;
35 DIDEVCAPS DevCaps;
36 DWORD dwProductID;
37 DWORD dwManufacturerID;
39 LRESULT lResult;
40
42
43 if (!pContext)
44 return DIENUM_STOP;
45
46 ZeroMemory(&Item, sizeof(LVITEMW));
47 Item.mask = LVIF_TEXT;
48 Item.pszText = (LPWSTR)lpddi->tszProductName;
49 Item.iItem = pContext->Count;
50 /* insert device item */
51 lResult = SendMessageW(pContext->hDevList, LVM_INSERTITEM, 0, (LPARAM)&Item);
52 if (lResult == -1)
53 return DIENUM_CONTINUE;
54
55 /* is the device attached */
56 szText[0] = L'\0';
57 hResult = pContext->pObj->lpVtbl->GetDeviceStatus(pContext->pObj, &lpddi->guidInstance);
58 if (hResult == DI_OK)
59 LoadStringW(hInst, IDS_DEVICE_STATUS_ATTACHED, szText, sizeof(szText) / sizeof(WCHAR));
60 else if (hResult == DI_NOTATTACHED)
61 LoadStringW(hInst, IDS_DEVICE_STATUS_MISSING, szText, sizeof(szText) / sizeof(WCHAR));
62 else
63 LoadStringW(hInst, IDS_DEVICE_STATUS_UNKNOWN, szText, sizeof(szText) / sizeof(WCHAR));
64
65 if (szText[0])
66 {
67 szText[(sizeof(szText) / sizeof(WCHAR))-1] = L'\0';
68 Item.iSubItem = 1;
69 Item.pszText = szText;
70 SendMessageW(pContext->hDevList, LVM_SETITEM, lResult, (LPARAM)&Item);
71 }
72
73 hResult = pContext->pObj->lpVtbl->CreateDevice(pContext->pObj, &lpddi->guidInstance, &pDev, NULL);
74
75 if (hResult != DI_OK)
76 return DIENUM_STOP;
77
78 ZeroMemory(&VendorID, sizeof(DIPROPDWORD));
79 VendorID.diph.dwSize = sizeof(DIPROPDWORD);
80 VendorID.diph.dwHeaderSize = sizeof(DIPROPHEADER);
81
82 hResult = pDev->lpVtbl->GetProperty(pDev, DIPROP_VIDPID, (LPDIPROPHEADER)&VendorID);
83 if (hResult == DI_OK)
84 {
85 /* set manufacturer id */
86 dwManufacturerID = LOWORD(VendorID.dwData);
87 wsprintfW(szText, L"0x%04X", dwManufacturerID);
88 Item.iSubItem = 3;
89 SendMessageW(pContext->hDevList, LVM_SETITEM, lResult, (LPARAM)&Item);
90 /* set product id */
91 dwProductID = HIWORD(VendorID.dwData);
92 wsprintfW(szText, L"0x%04X", dwProductID);
93 Item.iSubItem = 4;
94 SendMessageW(pContext->hDevList, LVM_SETITEM, lResult, (LPARAM)&Item);
95 }
96 else
97 {
98 szText[0] = L'\0';
99 LoadStringW(hInst, IDS_NOT_APPLICABLE, szText, sizeof(szText) / sizeof(WCHAR));
100 szText[(sizeof(szText)/sizeof(WCHAR))-1] = L'\0';
101 /* set manufacturer id */
102 Item.iSubItem = 3;
103 SendMessageW(pContext->hDevList, LVM_SETITEM, lResult, (LPARAM)&Item);
104 /* set product id */
105 Item.iSubItem = 4;
106 SendMessageW(pContext->hDevList, LVM_SETITEM, lResult, (LPARAM)&Item);
107 }
108
109 /* check for force feedback support */
110 DevCaps.dwSize = sizeof(DIDEVCAPS); // use DIDEVCAPS_DX3 for DX3 support
111 hResult = pDev->lpVtbl->GetCapabilities(pDev, &DevCaps);
112 szText[0] = L'\0';
113 if (hResult == DI_OK)
114 {
115 if (DevCaps.dwFlags & DIDC_FORCEFEEDBACK)
116 LoadStringW(hInst, IDS_OPTION_YES, szText, sizeof(szText)/sizeof(WCHAR));
117 else
118 LoadStringW(hInst, IDS_NOT_APPLICABLE, szText, sizeof(szText)/sizeof(WCHAR));
119 }
120 else
121 {
122 LoadStringW(hInst, IDS_NOT_APPLICABLE, szText, sizeof(szText)/sizeof(WCHAR));
123 }
124
125 Item.iSubItem = 5;
126 SendMessageW(pContext->hDevList, LVM_SETITEM, lResult, (LPARAM)&Item);
127
128
129#if 0
130 ZeroMemory(&GuidPath, sizeof(DIPROPGUIDANDPATH));
131 GuidPath.diph.dwSize = sizeof(DIPROPGUIDANDPATH);
132 GuidPath.diph.dwHeaderSize = sizeof(DIPROPHEADER);
133 GuidPath.diph.dwHow = DIPH_DEVICE;
134 hResult = pDev->lpVtbl->GetProperty(pDev, DIPROP_GUIDANDPATH, (LPDIPROPHEADER)&GuidPath);
135
136 ZeroMemory(&TypeName, sizeof(TypeName));
137 TypeName.diph.dwSize = sizeof(TypeName);
138 TypeName.diph.dwHeaderSize = sizeof(DIPROPHEADER);
139 TypeName.diph.dwHow = DIPH_DEVICE;
140 hResult = pDev->lpVtbl->GetProperty(pDev, DIPROP_GETPORTDISPLAYNAME, (LPDIPROPHEADER)&TypeName);
141
142
143#endif
144
145
146 pDev->lpVtbl->Release(pDev);
147 pContext->Count++;
148
149
150 return DIENUM_CONTINUE;
151}
152
153VOID
155{
156 WCHAR szText[256];
157 LVCOLUMNW lvcolumn;
158 INT Index;
159
160
161 pContext->hDevList = GetDlgItem(pContext->hwndDlg, IDC_LIST_DEVICE);
162
163 /* Highlights the entire row instead of just the selected item in the first column.
164 This increases readability on the selected item in the list. */
166
167 ZeroMemory(&lvcolumn, sizeof(LVCOLUMNW));
168 lvcolumn.pszText = szText;
170 lvcolumn.fmt = LVCFMT_LEFT;
171 lvcolumn.cx = 100;
172
173 for(Index = 0; Index < 6; Index++)
174 {
175 szText[0] = L'\0';
176 LoadStringW(hInst, IDS_DEVICE_NAME + Index, szText, sizeof(szText) / sizeof(WCHAR));
177 szText[(sizeof(szText) / sizeof(WCHAR))-1] = L'\0';
178 if (SendMessageW(pContext->hDevList, LVM_INSERTCOLUMNW, Index, (LPARAM)&lvcolumn) == -1)
179 return;
180 }
181}
182
183static
184void
186{
188 HRESULT hResult;
189 IDirectInput8W * pObj;
190
191 hResult = DirectInput8Create(hInst, DIRECTINPUT_VERSION, &IID_IDirectInput8W, (LPVOID*)&pObj, NULL);
192 if (hResult != DI_OK)
193 return;
194
195 ZeroMemory(&Context, sizeof(Context));
196 Context.pObj = pObj;
197 Context.hwndDlg = hwndDlg;
199 pObj->lpVtbl->EnumDevices(pObj, DI8DEVCLASS_ALL, DirectInputEnumDevCb, (PVOID)&Context, DIEDFL_ALLDEVICES);
200
201 pObj->lpVtbl->Release(pObj);
202}
203
204
205
208{
211 switch (message) {
212 case WM_INITDIALOG:
213 {
216 return TRUE;
217 }
218 }
219
220 return FALSE;
221}
INT_PTR CALLBACK InputPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: input.c:207
BOOL CALLBACK DirectInputEnumDevCb(LPCDIDEVICEINSTANCEW lpddi, LPVOID pvRef)
Definition: input.c:24
static void InitializeDirectInputDialog(HWND hwndDlg)
Definition: input.c:185
struct INPUT_DIALOG_CONTEXT * PINPUT_DIALOG_CONTEXT
VOID InputPageInitListViewColumns(PINPUT_DIALOG_CONTEXT pContext)
Definition: input.c:154
#define DIRECTINPUT_VERSION
Definition: precomp.h:4
#define IDS_DEVICE_STATUS_ATTACHED
Definition: resource.h:116
#define IDS_OPTION_YES
Definition: resource.h:126
#define IDC_LIST_DEVICE
Definition: resource.h:90
#define IDS_DEVICE_NAME
Definition: resource.h:119
#define IDS_DEVICE_STATUS_MISSING
Definition: resource.h:117
#define IDS_NOT_APPLICABLE
Definition: resource.h:125
#define IDS_DEVICE_STATUS_UNKNOWN
Definition: resource.h:118
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define DIPROP_GUIDANDPATH
Definition: dinput.h:908
#define DI8DEVCLASS_ALL
Definition: dinput.h:203
#define DIENUM_STOP
Definition: dinput.h:187
#define DIENUM_CONTINUE
Definition: dinput.h:188
#define DIEDFL_ALLDEVICES
Definition: dinput.h:190
#define DIDC_FORCEFEEDBACK
Definition: dinput.h:949
#define DI_NOTATTACHED
Definition: dinput.h:129
#define DI_OK
Definition: dinput.h:128
#define DIPROP_VIDPID
Definition: dinput.h:918
#define DIPH_DEVICE
Definition: dinput.h:835
HRESULT WINAPI DECLSPEC_HOTPATCH DirectInput8Create(HINSTANCE hinst, DWORD version, REFIID iid, void **out, IUnknown *outer)
Definition: dinput_main.c:172
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CALLBACK
Definition: compat.h:35
HINSTANCE hInst
Definition: dxdiag.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
ULONG Release()
unsigned int UINT
Definition: ndis.h:50
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
#define LVM_SETITEM
Definition: commctrl.h:2404
#define LVM_INSERTITEM
Definition: commctrl.h:2411
#define LVCF_WIDTH
Definition: commctrl.h:2592
#define LVS_EX_FULLROWSELECT
Definition: commctrl.h:2739
#define LVM_INSERTCOLUMNW
Definition: commctrl.h:2637
#define LVIF_TEXT
Definition: commctrl.h:2314
#define LVCF_FMT
Definition: commctrl.h:2591
#define LVCF_SUBITEM
Definition: commctrl.h:2594
#define LVCFMT_LEFT
Definition: commctrl.h:2603
#define LVCF_TEXT
Definition: commctrl.h:2593
#define LVM_SETEXTENDEDLISTVIEWSTYLE
Definition: commctrl.h:2729
DWORD dwSize
Definition: dinput.h:932
DWORD dwFlags
Definition: dinput.h:933
WCHAR tszProductName[MAX_PATH]
Definition: dinput.h:430
GUID guidInstance
Definition: dinput.h:426
DIPROPHEADER diph
Definition: dinput.h:843
DWORD dwData
Definition: dinput.h:844
DWORD dwSize
Definition: dinput.h:828
DWORD dwHeaderSize
Definition: dinput.h:829
IDirectInput8W * pObj
Definition: input.c:17
Definition: tftpd.h:60
LPWSTR pszText
Definition: commctrl.h:2572
int32_t INT_PTR
Definition: typedefs.h:64
int32_t INT
Definition: typedefs.h:58
#define HIWORD(l)
Definition: typedefs.h:247
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
#define ZeroMemory
Definition: winbase.h:1737
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define SWP_NOACTIVATE
Definition: winuser.h:1245
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define SWP_NOSIZE
Definition: winuser.h:1248
#define WM_INITDIALOG
Definition: winuser.h:1742
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define SendMessage
Definition: winuser.h:5855
#define SWP_NOOWNERZORDER
Definition: winuser.h:1252
#define SWP_NOZORDER
Definition: winuser.h:1250
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184