Leaked source code of windows server 2003
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.

323 lines
10 KiB

  1. //===========================================================================
  2. // SETTINGS.CPP
  3. //
  4. // Functions:
  5. // Settings_DlgProc()
  6. // DisplayJoystickState()
  7. //
  8. //===========================================================================
  9. // Uncomment if we decide to calibrate the POV!
  10. #define WE_SUPPORT_CALIBRATING_POVS 1
  11. #include "cplsvr1.h"
  12. #include "dicputil.h"
  13. #include "resource.h"
  14. #include "assert.h"
  15. #include "cal.h"
  16. #include <regstr.h>
  17. // Flag to stop centering of DLG if it's already happend!
  18. // This is needed because of the args that allow any page to be the first!
  19. BOOL bDlgCentered = FALSE;
  20. // This is global because Test.cpp needs it to determine
  21. // if the ranges need to be updated!
  22. BYTE nStatic;
  23. LPMYJOYRANGE lpCurrentRanges = NULL;
  24. extern CDIGameCntrlPropSheet_X *pdiCpl;
  25. //===========================================================================
  26. // FullJoyOemAccess()
  27. //
  28. // Check whether current user has full access to:
  29. // HKLM\SYSTEM\CurrentControlSet\Control\MediaProperties\PrivateProperties\Joystick\OEM
  30. //
  31. // Returns:
  32. // true: has access
  33. // false: no access
  34. //
  35. //===========================================================================
  36. bool FullJoyOemAccess()
  37. {
  38. LONG lRc;
  39. HKEY hk;
  40. bool bRc;
  41. lRc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  42. REGSTR_PATH_JOYOEM,
  43. 0,
  44. KEY_ALL_ACCESS,
  45. &hk);
  46. if( lRc == ERROR_SUCCESS ) {
  47. bRc = true;
  48. RegCloseKey(hk);
  49. } else {
  50. bRc = false;
  51. }
  52. return bRc;
  53. }
  54. //===========================================================================
  55. // Settings_DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  56. //
  57. // Callback proceedure for Settings Page
  58. //
  59. // Parameters:
  60. // HWND hWnd - handle to dialog window
  61. // UINT uMsg - dialog message
  62. // WPARAM wParam - message specific data
  63. // LPARAM lParam - message specific data
  64. //
  65. // Returns: BOOL
  66. //
  67. //===========================================================================
  68. INT_PTR CALLBACK Settings_DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  69. {
  70. // static LPDIJOYCONFIG_DX5 pDIJoyConfig;
  71. switch( uMsg ) {
  72. case WM_LBUTTONDOWN:
  73. // Click Drag service for PropSheets!
  74. PostMessage(GetParent(hWnd), WM_NCLBUTTONDOWN, (WPARAM)HTCAPTION, lParam);
  75. break;
  76. // OnHelp
  77. case WM_HELP:
  78. OnHelp(lParam);
  79. return(TRUE);
  80. // OnContextMenu
  81. case WM_CONTEXTMENU:
  82. OnContextMenu(wParam);
  83. return(TRUE);
  84. // OnDestroy
  85. case WM_DESTROY:
  86. bDlgCentered = FALSE;
  87. // if (pDIJoyConfig)
  88. // delete (pDIJoyConfig);
  89. break;
  90. // OnInitDialog
  91. case WM_INITDIALOG:
  92. // get ptr to our object
  93. if( !pdiCpl )
  94. pdiCpl = (CDIGameCntrlPropSheet_X*)((LPPROPSHEETPAGE)lParam)->lParam;
  95. // initialize DirectInput
  96. if( FAILED(InitDInput(GetParent(hWnd), pdiCpl)) ) {
  97. #ifdef _DEBUG
  98. OutputDebugString(TEXT("GCDEF.DLL: Settings.cpp: WM_INITDIALOG: InitDInput FAILED!\n"));
  99. #endif
  100. Error(hWnd, (short)IDS_INTERNAL_ERROR, (short)IDS_NO_DIJOYCONFIG);
  101. PostMessage(GetParent(hWnd), WM_SYSCOMMAND, SC_CLOSE, 0);
  102. return(FALSE);
  103. }
  104. {
  105. if( !FullJoyOemAccess() ) {
  106. pdiCpl->SetUser(TRUE);
  107. }
  108. // Center the Dialog!
  109. // If it's not been centered!
  110. if( !bDlgCentered ) {
  111. // Set the title bar!
  112. SetTitle(hWnd);
  113. CenterDialog(hWnd);
  114. bDlgCentered = TRUE;
  115. }
  116. // Disable the Calibration button if they don't have any axis!!!
  117. // Leave the Reset to default...
  118. if( pdiCpl->GetStateFlags()->nAxis == 0 )
  119. PostDlgItemEnableWindow(hWnd, IDC_JOYCALIBRATE, FALSE);
  120. }
  121. break;
  122. // OnNotify
  123. case WM_NOTIFY:
  124. // perform any WM_NOTIFY processing, but there is none...
  125. // return TRUE if you handled the notification (and have set
  126. // the result code in SetWindowLong(hWnd, DWL_MSGRESULT, lResult)
  127. // if you want to return a nonzero notify result)
  128. // or FALSE if you want default processing of the notification.
  129. switch( ((NMHDR*)lParam)->code ) {
  130. case PSN_APPLY:
  131. // Kill the memory allocated for the Ranges struct
  132. Sleep(100);
  133. if( lpCurrentRanges ) {
  134. delete (lpCurrentRanges);
  135. lpCurrentRanges = NULL;
  136. }
  137. /* We've removed the rudder stuff... but just in case it comes back...
  138. if (nStatic & RUDDER_HIT)
  139. {
  140. LPDIRECTINPUTJOYCONFIG pdiJoyConfig;
  141. pdiCpl->GetJoyConfig(&pdiJoyConfig);
  142. // get the status of the Rudder checkbox and assign it!
  143. // THEN Add the rudder to the Axis mask!
  144. if (pDIJoyConfig->hwc.dwUsageSettings & JOY_US_HASRUDDER)
  145. {
  146. pDIJoyConfig->hwc.dwUsageSettings &= ~JOY_US_HASRUDDER;
  147. pdiCpl->GetStateFlags()->nAxis &= ~HAS_RX;
  148. }
  149. else
  150. {
  151. pDIJoyConfig->hwc.dwUsageSettings |= JOY_US_HASRUDDER;
  152. pdiCpl->GetStateFlags()->nAxis |= HAS_RX;
  153. }
  154. if (FAILED(pdiJoyConfig->Acquire()))
  155. {
  156. #ifdef _DEBUG
  157. OutputDebugString(TEXT("GCDEF.DLL: Settings.cpp: Settings_DlgProc: PSN_APPLY: Acquire FAILED!\n"));
  158. #endif
  159. break;
  160. }
  161. // Set the GUID to NULL to ask DINPUT to recreate!
  162. pDIJoyConfig->guidInstance = NULL_GUID;
  163. if (FAILED(pdiJoyConfig->SetConfig(pdiCpl->GetID(), (LPDIJOYCONFIG)pDIJoyConfig, DIJC_REGHWCONFIGTYPE)))
  164. {
  165. #ifdef _DEBUG
  166. OutputDebugString(TEXT("GCDEF.DLL: Settings.cpp: Settings_DlgProc: PSN_APPLY: SetConfig FAILED!\n"));
  167. #endif
  168. break;
  169. }
  170. // Remove the mask from nStatic
  171. nStatic &= ~RUDDER_HIT;
  172. if (FAILED(pdiJoyConfig->SendNotify()))
  173. {
  174. #ifdef _DEBUG
  175. OutputDebugString(TEXT("GCDEF.DLL: Settings.cpp: Settings_DlgProc: PSN_APPLY: SendNotify FAILED!\n"));
  176. #endif
  177. }
  178. pdiJoyConfig->Unacquire();
  179. }
  180. */
  181. break;
  182. case PSN_RESET:
  183. // if the user has changed the calibration... Set it back!
  184. if( lpCurrentRanges ) {
  185. LPDIRECTINPUTDEVICE2 pdiDevice2;
  186. pdiCpl->GetDevice(&pdiDevice2);
  187. SetMyRanges(pdiDevice2, lpCurrentRanges, pdiCpl->GetStateFlags()->nAxis);
  188. // Set POV possitions!
  189. //if (pdiCpl->GetStateFlags()->nPOVs)
  190. // SetMyPOVRanges(pdiDevice2, lpCurrentRanges->dwPOV);
  191. LPDIRECTINPUTJOYCONFIG pdiJoyConfig;
  192. pdiCpl->GetJoyConfig(&pdiJoyConfig);
  193. pdiJoyConfig->Acquire();
  194. pdiJoyConfig->SendNotify();
  195. delete (lpCurrentRanges);
  196. lpCurrentRanges = NULL;
  197. }
  198. break;
  199. default:
  200. break;
  201. }
  202. return(FALSE);
  203. // OnCommand
  204. case WM_COMMAND:
  205. switch( LOWORD(wParam) ) {
  206. // Set to Default button!!!
  207. case IDC_RESETCALIBRATION:
  208. if( pdiCpl->GetUser() ) {
  209. Error(hWnd, (short)IDS_USER_MODE_TITLE, (short)IDS_USER_MODE);
  210. } else
  211. {
  212. MYJOYRANGE ResetRanges;
  213. ZeroMemory(&ResetRanges, sizeof(MYJOYRANGE));
  214. LPDIRECTINPUTDEVICE2 pdiDevice2;
  215. pdiCpl->GetDevice(&pdiDevice2);
  216. SetMyRanges(pdiDevice2, &ResetRanges, pdiCpl->GetStateFlags()->nAxis);
  217. LPDIRECTINPUTJOYCONFIG pdiJoyConfig;
  218. pdiCpl->GetJoyConfig(&pdiJoyConfig);
  219. pdiJoyConfig->Acquire();
  220. pdiJoyConfig->SendNotify();
  221. }
  222. break;
  223. case IDC_JOYCALIBRATE:
  224. if( pdiCpl->GetUser() ) {
  225. Error(hWnd, (short)IDS_USER_MODE_TITLE, (short)IDS_USER_MODE);
  226. } else
  227. {
  228. nStatic |= CALIBRATING;
  229. if( !lpCurrentRanges ) {
  230. lpCurrentRanges = new (MYJOYRANGE);
  231. assert (lpCurrentRanges);
  232. ZeroMemory (lpCurrentRanges, sizeof(MYJOYRANGE));
  233. LPDIRECTINPUTDEVICE2 pdiDevice2;
  234. pdiCpl->GetDevice(&pdiDevice2);
  235. // Get Current Ranges!
  236. GetMyRanges(pdiDevice2, lpCurrentRanges, pdiCpl->GetStateFlags()->nAxis);
  237. }
  238. if( CreateWizard(hWnd, (LPARAM)pdiCpl) ) {
  239. // Set the flags
  240. nStatic |= CAL_HIT;
  241. HWND hSheet = GetParent(hWnd);
  242. // take care of the Apply Now Button...
  243. ::SendMessage(hSheet, PSM_CHANGED, (WPARAM)hWnd, 0L);
  244. // Bug #179010 NT - Move to Test sheet after calibration!
  245. ::PostMessage(hSheet, PSM_SETCURSELID, 0, (LPARAM)IDD_TEST);
  246. } else {
  247. // if you canceled and it's your first time Kill the struct...
  248. // then Reset the flag
  249. if( !(nStatic & CAL_HIT) ) {
  250. // Kill the memory allocated for the Ranges struct
  251. if( lpCurrentRanges ) {
  252. delete (lpCurrentRanges);
  253. lpCurrentRanges = NULL;
  254. }
  255. }
  256. }
  257. nStatic &= ~CALIBRATING;
  258. }
  259. break;
  260. }
  261. }
  262. return(FALSE);
  263. } //*** end Settings_DlgProc()