Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

878 lines
21 KiB

  1. #include "setupp.h"
  2. #pragma hdrstop
  3. #include <windowsx.h>
  4. //
  5. // PAGE_INFO and related Prototypes
  6. //
  7. typedef struct _PAGE_INFO {
  8. HDEVINFO deviceInfoSet;
  9. PSP_DEVINFO_DATA deviceInfoData;
  10. HKEY hKeyDev;
  11. DWORD enableWheelDetect;
  12. DWORD sampleRate;
  13. DWORD bufferLength;
  14. DWORD mouseInitPolled;
  15. } PAGE_INFO, * PPAGE_INFO;
  16. PPAGE_INFO
  17. PS2Mouse_CreatePageInfo(
  18. IN HDEVINFO DeviceInfoSet,
  19. IN PSP_DEVINFO_DATA DeviceInfoData
  20. );
  21. void
  22. PS2Mouse_DestroyPageInfo(
  23. PPAGE_INFO PageInfo
  24. );
  25. //
  26. // Function Prototypes
  27. //
  28. HPROPSHEETPAGE
  29. PS2Mouse_CreatePropertyPage(
  30. PROPSHEETPAGE * PropSheetPage,
  31. PPAGE_INFO PageInfo
  32. );
  33. UINT CALLBACK
  34. PS2Mouse_PropPageCallback(
  35. HWND Hwnd,
  36. UINT Message,
  37. LPPROPSHEETPAGE PropSheetPage
  38. );
  39. INT_PTR
  40. APIENTRY
  41. PS2Mouse_DlgProc(
  42. IN HWND hDlg,
  43. IN UINT uMessage,
  44. IN WPARAM wParam,
  45. IN LPARAM lParam
  46. );
  47. void
  48. PS2Mouse_InitializeControls(
  49. HWND ParentHwnd,
  50. PPAGE_INFO PageInfo
  51. );
  52. void
  53. PS2Mouse_OnCommand(
  54. HWND ParentHwnd,
  55. int ControlId,
  56. HWND ControlHwnd,
  57. UINT NotifyCode
  58. );
  59. BOOL
  60. PS2Mouse_OnContextMenu(
  61. HWND HwndControl,
  62. WORD Xpos,
  63. WORD Ypos
  64. );
  65. INT_PTR
  66. PS2Mouse_OnCtlColorStatic(
  67. HDC DC,
  68. HWND Hwnd
  69. );
  70. void
  71. PS2Mouse_OnHelp(
  72. HWND ParentHwnd,
  73. LPHELPINFO HelpInfo
  74. );
  75. BOOL
  76. PS2Mouse_OnInitDialog(
  77. HWND ParentHwnd,
  78. HWND FocusHwnd,
  79. LPARAM Lparam
  80. );
  81. BOOL
  82. PS2Mouse_OnNotify(
  83. HWND ParentHwnd,
  84. LPNMHDR NmHdr
  85. );
  86. //
  87. // Message macros for up down controls
  88. //
  89. #define UpDown_SetRange(hwndUD, nLower, nUpper) \
  90. (VOID) SendMessage((hwndUD), UDM_SETRANGE, (WPARAM) 0, \
  91. (LPARAM) MAKELONG((short) (nUpper), (short) (nLower)) )
  92. #define UpDown_GetPos(hwndUD) \
  93. (DWORD) SendMessage((hwndUD), UDM_GETPOS, (WPARAM) 0, (LPARAM) 0)
  94. #define UpDown_SetPos(hwndUD, nPos) \
  95. (short) SendMessage((hwndUD), UDM_SETPOS, (WPARAM) 0, \
  96. (LPARAM) MAKELONG((short) (nPos), 0) )
  97. #define UpDown_SetAccel(hwndUD, nCount, pAccels) \
  98. (BOOL) SendMessage((hwndUD), UDM_SETACCEL, (WPARAM) nCount, \
  99. (LPARAM) pAccels)
  100. //
  101. // Constants and strings
  102. //
  103. #define MOUSE_INIT_POLLED_DEFAULT 0
  104. #define MAX_DETECTION_TYPES 3
  105. #define WHEEL_DETECT_DEFAULT 2 // Default is now 2 for Beta3 /* 1 */
  106. #define DATA_QUEUE_MIN 100
  107. #define DATA_QUEUE_MAX 300
  108. #define DATA_QUEUE_DEFAULT 100
  109. #define SAMPLE_RATE_DEFAULT 100
  110. const DWORD PS2Mouse_SampleRates[] =
  111. {
  112. 20,
  113. 40,
  114. 60,
  115. 80,
  116. 100,
  117. 200
  118. };
  119. #define MAX_SAMPLE_RATES (sizeof(PS2Mouse_SampleRates)/sizeof(PS2Mouse_SampleRates[0]))
  120. #define IDH_DEVMGR_MOUSE_ADVANCED_RATE 2002100
  121. #define IDH_DEVMGR_MOUSE_ADVANCED_DETECT 2002110
  122. #define IDH_DEVMGR_MOUSE_ADVANCED_BUFFER 2002120
  123. #define IDH_DEVMGR_MOUSE_ADVANCED_INIT 2002130
  124. #define IDH_DEVMGR_MOUSE_ADVANCED_DEFAULT 2002140
  125. const DWORD PS2Mouse_HelpIDs[] = {
  126. IDC_SAMPLE_RATE, IDH_DEVMGR_MOUSE_ADVANCED_RATE,
  127. IDC_WHEEL_DETECTION, IDH_DEVMGR_MOUSE_ADVANCED_DETECT,
  128. IDC_BUFFER, IDH_DEVMGR_MOUSE_ADVANCED_BUFFER,
  129. IDC_BUFFER_SPIN, IDH_DEVMGR_MOUSE_ADVANCED_BUFFER,
  130. IDC_FAST_INIT, IDH_DEVMGR_MOUSE_ADVANCED_INIT,
  131. IDC_DEFAULT, IDH_DEVMGR_MOUSE_ADVANCED_DEFAULT,
  132. 0, 0
  133. };
  134. TCHAR szDevMgrHelp[] = L"devmgr.hlp";
  135. TCHAR szMouseDataQueueSize[] = L"MouseDataQueueSize";
  136. TCHAR szSampleRate[] = L"SampleRate";
  137. TCHAR szEnableWheelDetection[] = L"EnableWheelDetection";
  138. TCHAR szMouseInitializePolled[] = L"MouseInitializePolled";
  139. TCHAR szDisablePolledUI[] = L"DisableInitializePolledUI";
  140. PPAGE_INFO
  141. PS2Mouse_CreatePageInfo(
  142. IN HDEVINFO DeviceInfoSet,
  143. IN PSP_DEVINFO_DATA DeviceInfoData)
  144. {
  145. PPAGE_INFO tmp = (PPAGE_INFO) MyMalloc(sizeof(PAGE_INFO));
  146. if (!tmp) {
  147. return NULL;
  148. }
  149. tmp->deviceInfoSet = DeviceInfoSet;
  150. tmp->deviceInfoData = DeviceInfoData;
  151. tmp->hKeyDev =
  152. SetupDiOpenDevRegKey(DeviceInfoSet,
  153. DeviceInfoData,
  154. DICS_FLAG_GLOBAL,
  155. 0,
  156. DIREG_DEV,
  157. KEY_ALL_ACCESS);
  158. return tmp;
  159. }
  160. void
  161. PS2Mouse_DestroyPageInfo(
  162. PPAGE_INFO PageInfo
  163. )
  164. {
  165. if (PageInfo->hKeyDev != (HKEY) INVALID_HANDLE_VALUE) {
  166. RegCloseKey(PageInfo->hKeyDev);
  167. }
  168. MyFree(PageInfo);
  169. }
  170. HPROPSHEETPAGE
  171. PS2Mouse_CreatePropertyPage(
  172. PROPSHEETPAGE * PropSheetPage,
  173. PPAGE_INFO PageInfo
  174. )
  175. {
  176. //
  177. // Add the Port Settings property page
  178. //
  179. PropSheetPage->dwSize = sizeof(PROPSHEETPAGE);
  180. PropSheetPage->dwFlags = PSP_USECALLBACK; // | PSP_HASHELP;
  181. PropSheetPage->hInstance = MyModuleHandle;
  182. PropSheetPage->pszTemplate = MAKEINTRESOURCE(IDD_PROP_PAGE_PS2_MOUSE);
  183. //
  184. // following points to the dlg window proc
  185. //
  186. PropSheetPage->pfnDlgProc = PS2Mouse_DlgProc;
  187. PropSheetPage->lParam = (LPARAM) PageInfo;
  188. //
  189. // Following points to the control callback of the dlg window proc.
  190. // The callback gets called before creation/after destruction of the page
  191. //
  192. PropSheetPage->pfnCallback = PS2Mouse_PropPageCallback;
  193. //
  194. // Allocate the actual page
  195. //
  196. return CreatePropertySheetPage(PropSheetPage);
  197. }
  198. BOOL APIENTRY
  199. PS2MousePropPageProvider(
  200. LPVOID Info,
  201. LPFNADDPROPSHEETPAGE AddFunction,
  202. LPARAM Lparam)
  203. {
  204. PSP_PROPSHEETPAGE_REQUEST ppr;
  205. PROPSHEETPAGE psp;
  206. HPROPSHEETPAGE hpsp;
  207. PPAGE_INFO ppi = NULL;
  208. ULONG devStatus, devProblem;
  209. CONFIGRET cr;
  210. ppr = (PSP_PROPSHEETPAGE_REQUEST) Info;
  211. if (ppr->PageRequested == SPPSR_ENUM_ADV_DEVICE_PROPERTIES) {
  212. ppi = PS2Mouse_CreatePageInfo(ppr->DeviceInfoSet, ppr->DeviceInfoData);
  213. if (!ppi) {
  214. return FALSE;
  215. }
  216. //
  217. // If this fails, it is most likely that the user does not have
  218. // write access to the devices key/subkeys in the registry.
  219. // If you only want to read the settings, then change KEY_ALL_ACCESS
  220. // to KEY_READ in CreatePageInfo.
  221. //
  222. // Administrators usually have access to these reg keys....
  223. //
  224. if (ppi->hKeyDev == (HKEY) INVALID_HANDLE_VALUE) {
  225. PS2Mouse_DestroyPageInfo(ppi);
  226. return FALSE;
  227. }
  228. //
  229. // Retrieve the status of this device instance.
  230. //
  231. cr = CM_Get_DevNode_Status(&devStatus,
  232. &devProblem,
  233. ppr->DeviceInfoData->DevInst,
  234. 0);
  235. if ((cr == CR_SUCCESS) &&
  236. (devStatus & DN_HAS_PROBLEM) &&
  237. (devProblem & CM_PROB_DISABLED_SERVICE)) {
  238. //
  239. // If the controlling service has been disabled, do not show any
  240. // additional property pages.
  241. //
  242. return FALSE;
  243. }
  244. hpsp = PS2Mouse_CreatePropertyPage(&psp, ppi);
  245. if (!hpsp) {
  246. return FALSE;
  247. }
  248. if (!AddFunction(hpsp, Lparam)) {
  249. DestroyPropertySheetPage(hpsp);
  250. return FALSE;
  251. }
  252. }
  253. return TRUE;
  254. }
  255. UINT CALLBACK
  256. PS2Mouse_PropPageCallback(
  257. HWND Hwnd,
  258. UINT Message,
  259. LPPROPSHEETPAGE PropSheetPage
  260. )
  261. {
  262. PPAGE_INFO ppi;
  263. switch (Message) {
  264. case PSPCB_CREATE:
  265. return TRUE; // return TRUE to continue with creation of page
  266. case PSPCB_RELEASE:
  267. ppi = (PPAGE_INFO) PropSheetPage->lParam;
  268. PS2Mouse_DestroyPageInfo(ppi);
  269. return 0; // return value ignored
  270. default:
  271. break;
  272. }
  273. return TRUE;
  274. }
  275. INT_PTR
  276. APIENTRY
  277. PS2Mouse_DlgProc(
  278. IN HWND hDlg,
  279. IN UINT uMessage,
  280. IN WPARAM wParam,
  281. IN LPARAM lParam
  282. )
  283. {
  284. switch(uMessage) {
  285. case WM_COMMAND:
  286. PS2Mouse_OnCommand(hDlg, (int) LOWORD(wParam), (HWND)lParam, (UINT)HIWORD(wParam));
  287. break;
  288. case WM_CONTEXTMENU:
  289. return PS2Mouse_OnContextMenu((HWND)wParam, LOWORD(lParam), HIWORD(lParam));
  290. case WM_HELP:
  291. PS2Mouse_OnHelp(hDlg, (LPHELPINFO) lParam);
  292. break;
  293. case WM_CTLCOLORSTATIC:
  294. return PS2Mouse_OnCtlColorStatic((HDC) wParam, (HWND) lParam);
  295. case WM_INITDIALOG:
  296. return PS2Mouse_OnInitDialog(hDlg, (HWND)wParam, lParam);
  297. case WM_NOTIFY:
  298. return PS2Mouse_OnNotify(hDlg, (NMHDR *)lParam);
  299. }
  300. return FALSE;
  301. }
  302. DWORD
  303. PS2Mouse_GetSampleRateIndex(
  304. DWORD SampleRate
  305. )
  306. {
  307. ULONG i;
  308. for (i = 0; i < MAX_SAMPLE_RATES; i++) {
  309. if (PS2Mouse_SampleRates[i] == SampleRate) {
  310. return i;
  311. }
  312. }
  313. return 0;
  314. }
  315. void
  316. PS2Mouse_OnDefault(
  317. HWND ParentHwnd,
  318. PPAGE_INFO PageInfo
  319. )
  320. {
  321. UpDown_SetPos(GetDlgItem(ParentHwnd, IDC_BUFFER_SPIN), DATA_QUEUE_DEFAULT);
  322. ComboBox_SetCurSel(GetDlgItem(ParentHwnd, IDC_SAMPLE_RATE),
  323. PS2Mouse_GetSampleRateIndex(SAMPLE_RATE_DEFAULT));
  324. ComboBox_SetCurSel(GetDlgItem(ParentHwnd, IDC_WHEEL_DETECTION), WHEEL_DETECT_DEFAULT);
  325. Button_SetCheck(GetDlgItem(ParentHwnd, IDC_FAST_INIT), !MOUSE_INIT_POLLED_DEFAULT);
  326. PropSheet_Changed(GetParent(ParentHwnd), ParentHwnd);
  327. }
  328. void
  329. PS2Mouse_OnCommand(
  330. HWND ParentHwnd,
  331. int ControlId,
  332. HWND ControlHwnd,
  333. UINT NotifyCode
  334. )
  335. {
  336. PPAGE_INFO pageInfo = (PPAGE_INFO) GetWindowLongPtr(ParentHwnd, DWLP_USER);
  337. if (NotifyCode == CBN_SELCHANGE) {
  338. PropSheet_Changed(GetParent(ParentHwnd), ParentHwnd);
  339. }
  340. else {
  341. switch (ControlId) {
  342. case IDC_DEFAULT:
  343. PS2Mouse_OnDefault(ParentHwnd, pageInfo);
  344. break;
  345. case IDC_FAST_INIT:
  346. PropSheet_Changed(GetParent(ParentHwnd), ParentHwnd);
  347. break;
  348. }
  349. }
  350. }
  351. BOOL
  352. PS2Mouse_OnContextMenu(
  353. HWND HwndControl,
  354. WORD Xpos,
  355. WORD Ypos
  356. )
  357. {
  358. WinHelp(HwndControl,
  359. szDevMgrHelp,
  360. HELP_CONTEXTMENU,
  361. (ULONG_PTR) PS2Mouse_HelpIDs);
  362. return FALSE;
  363. }
  364. INT_PTR
  365. PS2Mouse_OnCtlColorStatic(
  366. HDC DC,
  367. HWND HStatic
  368. )
  369. {
  370. UINT id = GetDlgCtrlID(HStatic);
  371. //
  372. // WM_CTLCOLORSTATIC is sent for the edit controls because they are read
  373. // only
  374. //
  375. if (id == IDC_BUFFER) {
  376. SetBkColor(DC, GetSysColor(COLOR_WINDOW));
  377. return (INT_PTR) GetSysColorBrush(COLOR_WINDOW);
  378. }
  379. return FALSE;
  380. }
  381. void
  382. PS2Mouse_OnHelp(
  383. HWND ParentHwnd,
  384. LPHELPINFO HelpInfo
  385. )
  386. {
  387. if (HelpInfo->iContextType == HELPINFO_WINDOW) {
  388. WinHelp((HWND) HelpInfo->hItemHandle,
  389. szDevMgrHelp,
  390. HELP_WM_HELP,
  391. (ULONG_PTR) PS2Mouse_HelpIDs);
  392. }
  393. }
  394. BOOL
  395. PS2Mouse_OnInitDialog(
  396. HWND ParentHwnd,
  397. HWND FocusHwnd,
  398. LPARAM Lparam
  399. )
  400. {
  401. PPAGE_INFO pageInfo = (PPAGE_INFO) GetWindowLongPtr(ParentHwnd, DWLP_USER);
  402. pageInfo = (PPAGE_INFO) ((LPPROPSHEETPAGE)Lparam)->lParam;
  403. SetWindowLongPtr(ParentHwnd, DWLP_USER, (ULONG_PTR) pageInfo);
  404. PS2Mouse_InitializeControls(ParentHwnd, pageInfo);
  405. return TRUE;
  406. }
  407. void
  408. PS2Mouse_OnApply(
  409. HWND ParentHwnd,
  410. PPAGE_INFO PageInfo
  411. )
  412. {
  413. DWORD uiEnableWheelDetect, uiSampleRate, uiBufferLength, uiMouseInitPolled;
  414. int iSel;
  415. BOOL reboot = FALSE;
  416. uiEnableWheelDetect =
  417. ComboBox_GetCurSel(GetDlgItem(ParentHwnd, IDC_WHEEL_DETECTION));
  418. uiBufferLength = UpDown_GetPos(GetDlgItem(ParentHwnd, IDC_BUFFER_SPIN));
  419. uiMouseInitPolled = !Button_GetCheck(GetDlgItem(ParentHwnd, IDC_FAST_INIT));
  420. //
  421. // Must index the array as opposed to getting a real value
  422. //
  423. iSel = ComboBox_GetCurSel(GetDlgItem(ParentHwnd, IDC_SAMPLE_RATE));
  424. if (iSel == CB_ERR) {
  425. uiSampleRate = PageInfo->sampleRate;
  426. }
  427. else {
  428. uiSampleRate = PS2Mouse_SampleRates[iSel];
  429. }
  430. //
  431. // See if anything has changed
  432. //
  433. if (uiEnableWheelDetect != PageInfo->enableWheelDetect) {
  434. RegSetValueEx(PageInfo->hKeyDev,
  435. szEnableWheelDetection,
  436. 0,
  437. REG_DWORD,
  438. (PBYTE) &uiEnableWheelDetect,
  439. sizeof(DWORD));
  440. reboot = TRUE;
  441. }
  442. if (uiSampleRate != PageInfo->sampleRate) {
  443. RegSetValueEx(PageInfo->hKeyDev,
  444. szSampleRate,
  445. 0,
  446. REG_DWORD,
  447. (PBYTE) &uiSampleRate,
  448. sizeof(DWORD));
  449. reboot = TRUE;
  450. }
  451. if (uiBufferLength != PageInfo->bufferLength) {
  452. RegSetValueEx(PageInfo->hKeyDev,
  453. szMouseDataQueueSize,
  454. 0,
  455. REG_DWORD,
  456. (PBYTE) &uiBufferLength,
  457. sizeof(DWORD));
  458. reboot = TRUE;
  459. }
  460. if (uiMouseInitPolled) {
  461. //
  462. // make sure if it is nonzero that it is 1
  463. //
  464. uiMouseInitPolled = 1;
  465. }
  466. if (uiMouseInitPolled != PageInfo->mouseInitPolled) {
  467. RegSetValueEx(PageInfo->hKeyDev,
  468. szMouseInitializePolled,
  469. 0,
  470. REG_DWORD,
  471. (PBYTE) &uiMouseInitPolled,
  472. sizeof(DWORD));
  473. reboot = TRUE;
  474. }
  475. if (reboot) {
  476. SP_DEVINSTALL_PARAMS dip;
  477. ZeroMemory(&dip, sizeof(dip));
  478. dip.cbSize = sizeof(dip);
  479. SetupDiGetDeviceInstallParams(PageInfo->deviceInfoSet,
  480. PageInfo->deviceInfoData,
  481. &dip);
  482. dip.Flags |= DI_NEEDREBOOT;
  483. SetupDiSetDeviceInstallParams(PageInfo->deviceInfoSet,
  484. PageInfo->deviceInfoData,
  485. &dip);
  486. }
  487. }
  488. BOOL
  489. PS2Mouse_OnNotify(
  490. HWND ParentHwnd,
  491. LPNMHDR NmHdr
  492. )
  493. {
  494. PPAGE_INFO pageInfo = (PPAGE_INFO) GetWindowLongPtr(ParentHwnd, DWLP_USER);
  495. switch (NmHdr->code) {
  496. //
  497. // The user is about to change an up down control
  498. //
  499. case UDN_DELTAPOS:
  500. PropSheet_Changed(GetParent(ParentHwnd), ParentHwnd);
  501. return FALSE;
  502. //
  503. // Sent when the user clicks on Apply OR OK !!
  504. //
  505. case PSN_APPLY:
  506. //
  507. // Write out the com port options to the registry
  508. //
  509. PS2Mouse_OnApply(ParentHwnd, pageInfo);
  510. SetWindowLongPtr(ParentHwnd, DWLP_MSGRESULT, PSNRET_NOERROR);
  511. return TRUE;
  512. default:
  513. return FALSE;
  514. }
  515. }
  516. DWORD
  517. PS2Mouse_SetupSpinner(
  518. HKEY Hkey,
  519. HWND SpinnerHwnd,
  520. TCHAR ValueName[],
  521. short MinVal,
  522. short MaxVal,
  523. short DefaultVal,
  524. short IncrementVal
  525. )
  526. {
  527. DWORD dwValue, dwSize;
  528. UDACCEL accel;
  529. UpDown_SetRange(SpinnerHwnd, MinVal, MaxVal);
  530. dwSize = sizeof(DWORD);
  531. if (RegQueryValueEx(Hkey,
  532. ValueName,
  533. 0,
  534. NULL,
  535. (PBYTE) &dwValue,
  536. &dwSize) != ERROR_SUCCESS) {
  537. dwValue = DefaultVal;
  538. }
  539. if (((short) dwValue) < MinVal || ((short) dwValue) > MaxVal) {
  540. dwValue = DefaultVal;
  541. }
  542. if (dwValue % IncrementVal) {
  543. //
  544. // Set the value to a good one and return the one we took out of the
  545. // registry. When the user applies the changes the value in the control
  546. // will be different and we will write the value out
  547. //
  548. UpDown_SetPos(SpinnerHwnd, dwValue - (dwValue % IncrementVal));
  549. }
  550. else {
  551. UpDown_SetPos(SpinnerHwnd, dwValue);
  552. }
  553. accel.nSec = 0;
  554. accel.nInc = IncrementVal;
  555. UpDown_SetAccel(SpinnerHwnd, 1, &accel);
  556. return dwValue;
  557. }
  558. DWORD
  559. PS2Mouse_SetupSampleRate(
  560. HWND ComboBoxHwnd,
  561. HKEY Hkey
  562. )
  563. {
  564. int i;
  565. DWORD dwValue, dwSize;
  566. BOOL badValue = FALSE;
  567. TCHAR szValue[32];
  568. //
  569. // First setup the cb, then find the correct selection
  570. //
  571. for (i = 0; i < MAX_SAMPLE_RATES; i++) {
  572. wsprintf(szValue, TEXT("%d"), PS2Mouse_SampleRates[i]);
  573. ComboBox_AddString(ComboBoxHwnd, szValue);
  574. }
  575. //
  576. // Get the value out of the registry. If it not what we expect or it is not
  577. // there, then make sure when the user clicks OK, the values are written out
  578. //
  579. dwSize = sizeof(DWORD);
  580. if (RegQueryValueEx(Hkey,
  581. szSampleRate,
  582. 0,
  583. NULL,
  584. (PBYTE) &dwValue,
  585. &dwSize) != ERROR_SUCCESS) {
  586. dwValue = SAMPLE_RATE_DEFAULT;
  587. badValue = TRUE;
  588. }
  589. //
  590. // Assume the value is wrong
  591. //
  592. badValue = TRUE;
  593. for (i = 0; i < MAX_SAMPLE_RATES; i++) {
  594. if (PS2Mouse_SampleRates[i] == dwValue) {
  595. badValue = FALSE;
  596. break;
  597. }
  598. }
  599. if (badValue) {
  600. dwValue = SAMPLE_RATE_DEFAULT;
  601. }
  602. ComboBox_SetCurSel(ComboBoxHwnd, PS2Mouse_GetSampleRateIndex(dwValue));
  603. if (badValue) {
  604. return 0xffffffff;
  605. }
  606. else {
  607. return dwValue;
  608. }
  609. }
  610. DWORD
  611. PS2Mouse_SetupWheelDetection(
  612. HWND ComboBoxHwnd,
  613. HKEY Hkey
  614. )
  615. {
  616. int i;
  617. DWORD dwValue, dwSize;
  618. BOOL badValue = FALSE;
  619. TCHAR szDescription[80];
  620. UINT stringIDs[MAX_DETECTION_TYPES] = {
  621. IDS_PS2_DETECTION_DISABLED,
  622. IDS_PS2_DETECTION_LOOK,
  623. IDS_PS2_DETECTION_ASSUME_PRESENT
  624. };
  625. //
  626. // First setup the cb, then find the correct selection
  627. //
  628. for (i = 0; i < MAX_DETECTION_TYPES; i++) {
  629. LoadString(MyModuleHandle,
  630. stringIDs[i],
  631. szDescription,
  632. sizeof(szDescription) / sizeof(TCHAR));
  633. ComboBox_AddString(ComboBoxHwnd, szDescription);
  634. }
  635. //
  636. // Get the value out of the registry. If it not what we expect or it is not
  637. // there, then make sure when the user clicks OK, the values are written out
  638. //
  639. dwSize = sizeof(DWORD);
  640. if (RegQueryValueEx(Hkey,
  641. szEnableWheelDetection,
  642. 0,
  643. NULL,
  644. (PBYTE) &dwValue,
  645. &dwSize) != ERROR_SUCCESS) {
  646. dwValue = WHEEL_DETECT_DEFAULT;
  647. badValue = TRUE;
  648. }
  649. if (dwValue > 2) {
  650. dwValue = WHEEL_DETECT_DEFAULT;
  651. badValue = TRUE;
  652. }
  653. ComboBox_SetCurSel(ComboBoxHwnd, dwValue);
  654. if (badValue) {
  655. return 0xffffffff;
  656. }
  657. else {
  658. return dwValue;
  659. }
  660. }
  661. ULONG
  662. PSMouse_SetupFastInit(
  663. HWND CheckBoxHwnd,
  664. HKEY Hkey
  665. )
  666. {
  667. DWORD dwSize, dwValue, dwDisable = FALSE;
  668. BOOL badValue = FALSE;
  669. //
  670. // Get the value out of the registry. If it not what we expect or it is not
  671. // there, then make sure when the user clicks OK, the values are written out
  672. //
  673. dwSize = sizeof(DWORD);
  674. if (RegQueryValueEx(Hkey,
  675. szMouseInitializePolled,
  676. 0,
  677. NULL,
  678. (PBYTE) &dwValue,
  679. &dwSize) != ERROR_SUCCESS) {
  680. dwValue = MOUSE_INIT_POLLED_DEFAULT;
  681. badValue = TRUE;
  682. }
  683. //
  684. // Make sure the value is 1 or 0. If it is nonzero and not 1, it is assumed
  685. // to be 1
  686. //
  687. if (dwValue != 0 && dwValue != 1) {
  688. dwValue = 1;
  689. badValue = TRUE;
  690. }
  691. //
  692. // This is a bit confusing. The UI has fast initialization, but underneath
  693. // it is represented as initialize polled which is fast when it is false,
  694. // but we must show true to the user
  695. //
  696. Button_SetCheck(CheckBoxHwnd, !dwValue);
  697. dwSize = sizeof(DWORD);
  698. if (RegQueryValueEx(Hkey,
  699. szDisablePolledUI,
  700. 0,
  701. NULL,
  702. (PBYTE) &dwDisable,
  703. &dwSize) == ERROR_SUCCESS &&
  704. dwDisable != FALSE) {
  705. EnableWindow(CheckBoxHwnd, FALSE);
  706. }
  707. if (badValue) {
  708. return -1;
  709. }
  710. else {
  711. return dwValue;
  712. }
  713. }
  714. void
  715. PS2Mouse_InitializeControls(
  716. HWND ParentHwnd,
  717. PPAGE_INFO PageInfo
  718. )
  719. {
  720. HKEY hKey;
  721. HWND hwnd;
  722. DWORD dwValue, dwSize;
  723. int i;
  724. if (PageInfo->hKeyDev == (HKEY) INVALID_HANDLE_VALUE) {
  725. //
  726. // Disable all of the controls
  727. //
  728. return;
  729. }
  730. PageInfo->bufferLength =
  731. PS2Mouse_SetupSpinner(PageInfo->hKeyDev,
  732. GetDlgItem(ParentHwnd, IDC_BUFFER_SPIN),
  733. szMouseDataQueueSize,
  734. DATA_QUEUE_MIN,
  735. DATA_QUEUE_MAX,
  736. DATA_QUEUE_DEFAULT,
  737. 10);
  738. PageInfo->sampleRate =
  739. PS2Mouse_SetupSampleRate(GetDlgItem(ParentHwnd, IDC_SAMPLE_RATE),
  740. PageInfo->hKeyDev);
  741. PageInfo->enableWheelDetect =
  742. PS2Mouse_SetupWheelDetection(GetDlgItem(ParentHwnd, IDC_WHEEL_DETECTION),
  743. PageInfo->hKeyDev);
  744. PageInfo->mouseInitPolled =
  745. PSMouse_SetupFastInit(GetDlgItem(ParentHwnd, IDC_FAST_INIT),
  746. PageInfo->hKeyDev);
  747. }