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.

373 lines
11 KiB

  1. // RASettingProperty.cpp : Implementation of CRASettingProperty
  2. #include "stdafx.h"
  3. #include "windowsx.h"
  4. #include "RAssistance.h"
  5. #include "RASettingProperty.h"
  6. #include "stdio.h"
  7. #define NO_HELP ((DWORD) -1) // Disables Help for a control.
  8. #define HELP_FILE TEXT("SYSDM.HLP")
  9. DWORD aRAHelpIds[] = {
  10. //IDC_ENABLERA, HIDC_RA_ENABLE,
  11. IDC_ALLOWRC, HIDC_RA_ALLOWRC,
  12. IDC_GROUP1, HIDC_RA_ALLOWRC,
  13. IDC_ALLOWUNSOLICIT, HIDC_RA_ALLOWUNSOLICIT,
  14. IDC_NUMBERCOMBO, HIDC_RA_EXPIRY,
  15. IDC_UNITCOMBO, HIDC_RA_EXPIRY,
  16. IDC_TIMEOUTTXT, HIDC_RA_EXPIRY,
  17. IDC_GROUP2, HIDC_RA_EXPIRY,
  18. IDC_STATIC_TEXT, NO_HELP,
  19. 0, 0
  20. };
  21. extern HINSTANCE g_hInst;
  22. /************************************************
  23. RemoteAssistanceProc: DlgProc of Remote Assistance setup
  24. ************************************************/
  25. INT_PTR
  26. RemoteAssistanceProc( HWND hDlg,
  27. UINT uMsg,
  28. WPARAM wParam,
  29. LPARAM lParam )
  30. {
  31. static CRASettingProperty* pRaSetting = NULL;
  32. switch (uMsg)
  33. {
  34. case WM_INITDIALOG:
  35. {
  36. TCHAR sTmp[32];
  37. int i;
  38. HWND hList;
  39. RA_SETTING *p;
  40. int iFocus = IDC_ALLOWRC;
  41. pRaSetting = (CRASettingProperty*)lParam;
  42. if (pRaSetting->m_bUseNewSetting)
  43. p = &pRaSetting->newSetting;
  44. else
  45. p = &pRaSetting->oldSetting;
  46. /*
  47. if (p->m_bEnableRA)
  48. CheckDlgButton(hDlg,IDC_ENABLERA, BST_CHECKED);
  49. if (p->m_bAllowUnsolicited)
  50. CheckDlgButton(hDlg,IDC_ALLOWUNSOLICIT, BST_CHECKED);
  51. */
  52. CheckDlgButton(hDlg, IDC_ALLOWRC, p->m_bAllowFullControl?BST_CHECKED:BST_UNCHECKED);
  53. iFocus = IDC_ALLOWRC;
  54. // Add Numbers
  55. hList = GetDlgItem(hDlg, IDC_NUMBERCOMBO);
  56. for (i=1; i<100; i++)
  57. {
  58. wsprintf(sTmp, TEXT("%d"), i);
  59. ComboBox_AddString(hList, sTmp);
  60. }
  61. //ComboBox_SetCurSel(hList, p->m_iNumber);
  62. wsprintf(sTmp, TEXT("%d"), p->m_iNumber);
  63. ComboBox_SetText(hList, sTmp);
  64. // Add Units
  65. hList = GetDlgItem(hDlg, IDC_UNITCOMBO);
  66. i=0;
  67. if (LoadString(g_hInst, IDS_UNIT_MINUTE, sTmp, 32))
  68. ComboBox_AddString(hList, sTmp);
  69. if (LoadString(g_hInst, IDS_UNIT_HOUR, sTmp, 32))
  70. ComboBox_AddString(hList, sTmp);
  71. if (LoadString(g_hInst, IDS_UNIT_DAY, sTmp, 32))
  72. ComboBox_AddString(hList, sTmp);
  73. ComboBox_SetCurSel(hList, p->m_iUnit);
  74. SetFocus(GetDlgItem(hDlg, iFocus));
  75. return FALSE;
  76. }
  77. break;
  78. case WM_HELP: // F1
  79. WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  80. HELP_FILE,
  81. HELP_WM_HELP,
  82. (DWORD_PTR)(LPSTR)aRAHelpIds);
  83. break;
  84. case WM_CONTEXTMENU: // right-click help
  85. WinHelp((HWND)wParam,
  86. HELP_FILE,
  87. HELP_CONTEXTMENU,
  88. (DWORD_PTR)(LPSTR)aRAHelpIds);
  89. break;
  90. case WM_COMMAND:
  91. switch (LOWORD(wParam)) {
  92. case IDC_NUMBERCOMBO:
  93. {
  94. if (HIWORD(wParam) == CBN_EDITUPDATE)
  95. {
  96. BOOL bOK;
  97. DWORD nVal;
  98. TCHAR sTmp[MAX_PATH];
  99. if (GetDlgItemText(hDlg,IDC_NUMBERCOMBO,&sTmp[0],MAX_PATH-1))
  100. {
  101. nVal = (DWORD)GetDlgItemInt(hDlg, IDC_NUMBERCOMBO, &bOK, FALSE);
  102. if (!bOK || nVal > 99)
  103. {
  104. CComBSTR bstrErrMsg;
  105. CComBSTR bstrTitle;
  106. if (bstrErrMsg.LoadString(IDS_VALID_NUMBER) && bstrTitle.LoadString(IDS_PROJNAME))
  107. {
  108. MessageBox(hDlg, bstrErrMsg, bstrTitle, MB_OK | MB_ICONERROR);
  109. }
  110. // Set it back to default.
  111. wsprintf(sTmp, TEXT("%d"), pRaSetting->oldSetting.m_iNumber);
  112. ComboBox_SetText(GetDlgItem(hDlg, IDC_NUMBERCOMBO), sTmp);
  113. return TRUE;
  114. }
  115. }
  116. }
  117. break;
  118. }
  119. case IDCANCEL:
  120. pRaSetting->put_IsCancelled(TRUE);
  121. EndDialog(hDlg, 0);
  122. break;
  123. case IDOK:
  124. {
  125. TCHAR sTmp[11];
  126. wsprintf(sTmp, TEXT("0"));
  127. // Map control value to local variables.
  128. // pRaSetting->newSetting.m_bEnableRA = (IsDlgButtonChecked(hDlg,IDC_ENABLERA) == BST_CHECKED);
  129. // pRaSetting->newSetting.m_bAllowUnsolicited = (IsDlgButtonChecked(hDlg,IDC_ALLOWUNSOLICIT)==BST_CHECKED);
  130. pRaSetting->newSetting.m_bAllowFullControl = (IsDlgButtonChecked(hDlg,IDC_ALLOWRC)==BST_CHECKED);
  131. ComboBox_GetText(GetDlgItem(hDlg, IDC_NUMBERCOMBO), sTmp, 10);
  132. DWORD iUnit = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_UNITCOMBO));
  133. //The max allowed value for number of days is 30 if the value selected is above 30 then
  134. //show and error message and break without closing the dialog and set focus to number dropdown.
  135. if ( (iUnit == RA_IDX_DAY) && (_ttoi(sTmp) > RA_MAX_DAYS) )
  136. {
  137. CComBSTR bstrTitle;
  138. CComBSTR bstrErrMsg;
  139. bstrTitle.LoadString(IDS_PROJNAME);
  140. bstrErrMsg.LoadString(IDS_VALID_DAYS);
  141. if (bstrTitle.LoadString(IDS_PROJNAME) && bstrErrMsg.LoadString(IDS_VALID_DAYS))
  142. MessageBoxW(NULL,bstrErrMsg,bstrTitle,MB_OK | MB_ICONERROR);
  143. SetFocus(GetDlgItem(hDlg, IDC_NUMBERCOMBO));
  144. wsprintf(sTmp, TEXT("30")); //RA_MAX_DAYS VALUE
  145. SetDlgItemText(hDlg,IDC_NUMBERCOMBO,sTmp);
  146. break;
  147. }
  148. pRaSetting->newSetting.m_iNumber = _ttoi(sTmp);
  149. pRaSetting->newSetting.m_iUnit = iUnit;
  150. // In case users open the dialog again before APPLY the changes.
  151. pRaSetting->m_bUseNewSetting = TRUE;
  152. EndDialog(hDlg, 0);
  153. }
  154. break;
  155. default: {
  156. // indicat not handled
  157. return FALSE;
  158. }
  159. }
  160. break; // WM_COMMAND
  161. default:
  162. return FALSE;
  163. }
  164. return TRUE;
  165. }
  166. /////////////////////////////////////////////////////////////////////////////
  167. // CRASettingProperty
  168. /******************************
  169. Func:
  170. get_IsCancelled
  171. Abstract:
  172. Is the action get cancelled
  173. *******************************/
  174. STDMETHODIMP CRASettingProperty::get_IsCancelled(BOOL *pVal)
  175. {
  176. *pVal = m_bCancelled;
  177. return S_OK;
  178. }
  179. STDMETHODIMP CRASettingProperty::put_IsCancelled(BOOL newVal)
  180. {
  181. m_bCancelled = newVal;
  182. return S_OK;
  183. }
  184. /*************************************
  185. Func:
  186. IsChanged
  187. Abstract:
  188. Check if the RA setting values have been changed.
  189. Return:
  190. TRUE (changed) else FALSE
  191. **************************************/
  192. STDMETHODIMP CRASettingProperty::get_IsChanged(BOOL *pVal)
  193. {
  194. *pVal = FALSE;
  195. if (!m_bCancelled && !(oldSetting == newSetting))
  196. *pVal = TRUE;
  197. return S_OK;
  198. }
  199. /********************************************
  200. Func:
  201. Init
  202. Abstract:
  203. Initialize this object. Get setting values from Registry.
  204. *********************************************/
  205. STDMETHODIMP CRASettingProperty::Init()
  206. {
  207. HRESULT hr = GetRegSetting();
  208. if (SUCCEEDED(hr))
  209. {
  210. newSetting = oldSetting;
  211. }
  212. return hr;
  213. }
  214. /**************************************************************
  215. Func:
  216. GetRegSetting
  217. Abstract:
  218. Get RA Settnig dialog's Registry values to oldSetting member.
  219. ***************************************************************/
  220. HRESULT CRASettingProperty::GetRegSetting()
  221. {
  222. // If any value is not found, use the default value.
  223. DWORD dwValue;
  224. DWORD dwSize;
  225. HKEY hKey = NULL;
  226. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_KEY_REMOTEASSISTANCE, 0, KEY_READ, &hKey))
  227. {
  228. // Get value
  229. /*
  230. dwSize = sizeof(DWORD);
  231. if (ERROR_SUCCESS == RegQueryValueEx(hKey, RA_CTL_RA_MODE, 0, NULL, (LPBYTE)&dwValue, &dwSize ))
  232. {
  233. oldSetting.m_bEnableRA = !!dwValue;
  234. }
  235. dwSize = sizeof(DWORD);
  236. if (ERROR_SUCCESS == RegQueryValueEx(hKey, RA_CTL_ALLOW_UNSOLICITED, 0, NULL, (LPBYTE)&dwValue, &dwSize))
  237. {
  238. oldSetting.m_bAllowUnsolicited = !!dwValue;
  239. }
  240. */
  241. dwValue=0;
  242. dwSize = sizeof(DWORD);
  243. if (ERROR_SUCCESS == RegQueryValueEx(hKey, RA_CTL_ALLOW_FULLCONTROL, 0, NULL, (LPBYTE)&dwValue, &dwSize ))
  244. {
  245. oldSetting.m_bAllowFullControl = !!dwValue;;
  246. }
  247. dwValue=0;
  248. dwSize = sizeof(DWORD);
  249. if (ERROR_SUCCESS == RegQueryValueEx(hKey, RA_CTL_COMBO_NUMBER, 0, NULL, (LPBYTE)&dwValue, &dwSize ))
  250. {
  251. oldSetting.m_iNumber = dwValue;
  252. }
  253. dwValue=0;
  254. dwSize = sizeof(DWORD);
  255. if (ERROR_SUCCESS == RegQueryValueEx(hKey, RA_CTL_COMBO_UNIT, 0, NULL, (LPBYTE)&dwValue, &dwSize ))
  256. {
  257. oldSetting.m_iUnit = dwValue;
  258. }
  259. RegCloseKey(hKey);
  260. }
  261. return S_OK;
  262. }
  263. /**************************************************************
  264. Func:
  265. SetRegSetting
  266. Abstract:
  267. Set RA setting dialog values to registry.
  268. ***************************************************************/
  269. STDMETHODIMP CRASettingProperty::SetRegSetting()
  270. {
  271. HRESULT hr = E_FAIL;
  272. HKEY hKey;
  273. DWORD dwAwFullControl /*,dwAwUnsolicited */;
  274. //dwAwUnsolicited = newSetting.m_bAllowUnsolicited;
  275. dwAwFullControl = newSetting.m_bAllowFullControl;
  276. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_KEY_REMOTEASSISTANCE, 0, KEY_WRITE, &hKey))
  277. {
  278. if (//ERROR_SUCCESS==RegSetValueEx(hKey,RA_CTL_ALLOW_UNSOLICITED,0,REG_DWORD,(LPBYTE)&dwAwUnsolicited,sizeof(DWORD)) &&
  279. ERROR_SUCCESS==RegSetValueEx(hKey,RA_CTL_ALLOW_FULLCONTROL,0,REG_DWORD,(LPBYTE)&dwAwFullControl,sizeof(DWORD)) &&
  280. ERROR_SUCCESS==RegSetValueEx(hKey,RA_CTL_COMBO_NUMBER,0,REG_DWORD,(LPBYTE)&newSetting.m_iNumber,sizeof(DWORD)) &&
  281. ERROR_SUCCESS==RegSetValueEx(hKey,RA_CTL_COMBO_UNIT,0,REG_DWORD,(LPBYTE)&newSetting.m_iUnit,sizeof(DWORD)))
  282. {
  283. hr = S_OK;
  284. // Sync old and new settings
  285. oldSetting = newSetting;
  286. }
  287. RegCloseKey(hKey);
  288. }
  289. return hr;
  290. }
  291. /**************************************************************
  292. Func:
  293. ShowDialogBox
  294. Abstract:
  295. Display the RA setting dialog
  296. ***************************************************************/
  297. STDMETHODIMP CRASettingProperty::ShowDialogBox(HWND hWndParent)
  298. {
  299. HRESULT hr = S_OK;
  300. m_bCancelled = FALSE;
  301. HMODULE hModule = GetModuleHandle(TEXT("RACPLDlg.dll"));
  302. INT_PTR i;
  303. if (!hModule)
  304. {
  305. hr = HRESULT_FROM_WIN32(GetLastError());
  306. goto done;
  307. }
  308. i = DialogBoxParam(hModule,
  309. (LPTSTR) MAKEINTRESOURCE(IDD_RASETTINGS_DIALOG),
  310. hWndParent,
  311. RemoteAssistanceProc,
  312. (LPARAM)this);
  313. if (i == -1)
  314. {
  315. hr = HRESULT_FROM_WIN32(GetLastError());
  316. }
  317. done:
  318. return hr;
  319. }