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.

415 lines
12 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1996.
  5. //
  6. // File: wizsel.cxx
  7. //
  8. // Contents: Task schedule credentials selection property page implementation.
  9. //
  10. // Classes: CCredentialsPage
  11. //
  12. // History: 05-22-1998 SusiA
  13. //
  14. //---------------------------------------------------------------------------
  15. #include "precomp.h"
  16. // temporariy define new mstask flag in case hasn't
  17. // propogated to sdk\inc
  18. //for CS help
  19. #ifdef _CREDENTIALS
  20. extern TCHAR szSyncMgrHelp[];
  21. extern ULONG g_aContextHelpIds[];
  22. CCredentialsPage *g_pCredentialsPage = NULL;
  23. //+-------------------------------------------------------------------------------
  24. // FUNCTION: SchedWizardCredentialsDlgProc(HWND, UINT, WPARAM, LPARAM)
  25. //
  26. // PURPOSE: Callback dialog procedure for the property page
  27. //
  28. // PARAMETERS:
  29. // hDlg - Dialog box window handle
  30. // uMessage - current message
  31. // wParam - depends on message
  32. // lParam - depends on message
  33. //
  34. // RETURN VALUE:
  35. //
  36. // Depends on message. In general, return TRUE if we process it.
  37. //
  38. // COMMENTS:
  39. //
  40. //--------------------------------------------------------------------------------
  41. INT_PTR CALLBACK SchedWizardCredentialsDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
  42. {
  43. WORD wNotifyCode = HIWORD(wParam); // notification code
  44. switch (uMessage)
  45. {
  46. case WM_INITDIALOG:
  47. if (g_pCredentialsPage)
  48. g_pCredentialsPage->Initialize(hDlg);
  49. InitPage(hDlg,lParam);
  50. break;
  51. case WM_HELP:
  52. {
  53. LPHELPINFO lphi = (LPHELPINFO)lParam;
  54. if (lphi->iContextType == HELPINFO_WINDOW)
  55. {
  56. WinHelp ( (HWND) lphi->hItemHandle,
  57. szSyncMgrHelp,
  58. HELP_WM_HELP,
  59. (ULONG_PTR) g_aContextHelpIds);
  60. }
  61. return TRUE;
  62. }
  63. case WM_CONTEXTMENU:
  64. {
  65. WinHelp ((HWND)wParam,
  66. szSyncMgrHelp,
  67. HELP_CONTEXTMENU,
  68. (ULONG_PTR)g_aContextHelpIds);
  69. return TRUE;
  70. }
  71. case WM_PAINT:
  72. WmPaint(hDlg, uMessage, wParam, lParam);
  73. break;
  74. case WM_PALETTECHANGED:
  75. WmPaletteChanged(hDlg, wParam);
  76. break;
  77. case WM_QUERYNEWPALETTE:
  78. return( WmQueryNewPalette(hDlg) );
  79. break;
  80. case WM_ACTIVATE:
  81. return( WmActivate(hDlg, wParam, lParam) );
  82. break;
  83. case WM_COMMAND:
  84. switch (LOWORD(wParam))
  85. {
  86. case IDC_USERNAME:
  87. case IDC_PASSWORD:
  88. case IDC_CONFIRMPASSWORD:
  89. {
  90. if (wNotifyCode == EN_CHANGE)
  91. {
  92. PropSheet_Changed(GetParent(hDlg), hDlg);
  93. g_pCredentialsPage->SetDirty();
  94. }
  95. }
  96. break;
  97. case IDC_RUNLOGGEDON:
  98. {
  99. if (wNotifyCode == BN_CLICKED)
  100. {
  101. PropSheet_Changed(GetParent(hDlg), hDlg);
  102. g_pCredentialsPage->SetDirty();
  103. g_pCredentialsPage->SetEnabled(FALSE);
  104. }
  105. }
  106. break;
  107. case IDC_RUNALWAYS:
  108. {
  109. if (wNotifyCode == BN_CLICKED)
  110. {
  111. PropSheet_Changed(GetParent(hDlg), hDlg);
  112. g_pCredentialsPage->SetDirty();
  113. g_pCredentialsPage->SetEnabled(TRUE);
  114. }
  115. }
  116. break;
  117. default:
  118. break;
  119. }
  120. break;
  121. default:
  122. return FALSE;
  123. }
  124. return TRUE;
  125. }
  126. //+--------------------------------------------------------------------------
  127. //
  128. // Member: CCredentialsPage::CCredentialsPage
  129. //
  130. // Synopsis: ctor
  131. //
  132. // [phPSP] - filled with prop page handle
  133. //
  134. // History: 11-21-1997 SusiA
  135. //
  136. //---------------------------------------------------------------------------
  137. CCredentialsPage::CCredentialsPage(
  138. HINSTANCE hinst,
  139. BOOL *pfSaved,
  140. ISyncSchedule *pISyncSched,
  141. HPROPSHEETPAGE *phPSP)
  142. {
  143. ZeroMemory(&m_psp, sizeof(m_psp));
  144. m_psp.dwSize = sizeof (PROPSHEETPAGE);
  145. m_psp.dwFlags = PSP_DEFAULT;
  146. m_psp.hInstance = hinst;
  147. m_psp.pszTemplate = MAKEINTRESOURCE(IDD_SCHEDPAGE_CREDENTIALS);
  148. m_psp.pszIcon = NULL;
  149. m_psp.pfnDlgProc = SchedWizardCredentialsDlgProc;
  150. m_psp.lParam = 0;
  151. g_pCredentialsPage = this;
  152. m_pISyncSched = pISyncSched;
  153. m_pISyncSched->AddRef();
  154. m_pfSaved = pfSaved;
  155. *m_pfSaved = FALSE;
  156. m_fTaskAccountChange = FALSE;
  157. *phPSP = CreatePropertySheetPage(&m_psp);
  158. }
  159. //+--------------------------------------------------------------------------
  160. //
  161. // Member: CCredentialsPage::Initialize(HWND hwnd)
  162. //
  163. // Synopsis: initialize the credentials page
  164. //
  165. // History: 05-22-1998 SusiA
  166. //
  167. //---------------------------------------------------------------------------
  168. BOOL CCredentialsPage::Initialize(HWND hwnd)
  169. {
  170. m_hwnd = hwnd;
  171. ShowUserName();
  172. //Set the default IDC_ONLY_WHEN_LOGGED_ON check state.
  173. ITask *pITask;
  174. m_pISyncSched->GetITask(&pITask);
  175. DWORD dwFlags;
  176. pITask->GetFlags(&dwFlags);
  177. BOOL fOnlyWhenLoggedOn = dwFlags & TASK_FLAG_RUN_ONLY_IF_LOGGED_ON;
  178. Button_SetCheck(GetDlgItem(m_hwnd,IDC_RUNLOGGEDON), fOnlyWhenLoggedOn);
  179. Button_SetCheck(GetDlgItem(m_hwnd,IDC_RUNALWAYS), !fOnlyWhenLoggedOn);
  180. Edit_LimitText(GetDlgItem(m_hwnd, IDC_PASSWORD), PWLEN);
  181. Edit_LimitText(GetDlgItem(m_hwnd, IDC_CONFIRMPASSWORD), PWLEN);
  182. Edit_LimitText(GetDlgItem(m_hwnd, IDC_USERNAME), MAX_DOMANDANDMACHINENAMESIZE -1);
  183. SetEnabled(!fOnlyWhenLoggedOn);
  184. pITask->Release();
  185. ShowWindow(m_hwnd, /* nCmdShow */ SW_SHOWNORMAL );
  186. UpdateWindow(m_hwnd);
  187. return TRUE;
  188. }
  189. //--------------------------------------------------------------------------------
  190. //
  191. // FUNCTION: CCredentialsPage::SetDirty()
  192. //
  193. // PURPOSE: we have changed the account info
  194. //
  195. // COMMENTS: Only called frm prop sheet; not wizard
  196. //
  197. //--------------------------------------------------------------------------------
  198. void CCredentialsPage::SetDirty()
  199. {
  200. m_fTaskAccountChange = TRUE;
  201. }
  202. //--------------------------------------------------------------------------------
  203. //
  204. // FUNCTION: CSelectItemsPage::ShowUserName()
  205. //
  206. // PURPOSE: change the task's user name
  207. //
  208. // COMMENTS: Only called frm prop sheet; not wizard
  209. //
  210. //--------------------------------------------------------------------------------
  211. BOOL CCredentialsPage::ShowUserName()
  212. {
  213. Assert(m_pISyncSched);
  214. WCHAR wszUserName[MAX_PATH + 1];
  215. DWORD cchUserName = ARRAYSIZE(wszUserName);
  216. HWND hwndEdit = GetDlgItem(m_hwnd, IDC_USERNAME);
  217. HRESULT hr = m_pISyncSched->GetAccountInformation(&cchUserName, wszUserName);
  218. if (FAILED(hr))
  219. {
  220. *wszUserName = L'\0';
  221. }
  222. Edit_SetText(hwndEdit, wszUserName);
  223. //
  224. // Need to set m_fTaskAccountChange here since doing a Edit_SetText causes
  225. // a WM_COMMAND msg with EN_CHANGE to be called for edit boxes.
  226. //
  227. m_fTaskAccountChange = FALSE;
  228. return TRUE;
  229. }
  230. //--------------------------------------------------------------------------------
  231. //
  232. // FUNCTION: CSelectItemsPage::CommitChanges()
  233. //
  234. // PURPOSE: Write all the current Schedule Settings to the registry
  235. //
  236. // COMMENTS: Implemented on main thread.
  237. //
  238. //--------------------------------------------------------------------------------
  239. HRESULT CCredentialsPage::CommitChanges()
  240. {
  241. HRESULT hr = S_OK;
  242. BOOL fAccountChanged = TRUE;
  243. if (m_fTaskAccountChange)
  244. {
  245. BOOL fRunAlways = Button_GetCheck(GetDlgItem(m_hwnd,IDC_RUNALWAYS));
  246. if (fRunAlways)
  247. {
  248. Assert(m_pISyncSched);
  249. WCHAR wcUserBuffMAX_DOMANDANDMACHINENAMESIZE];
  250. WCHAR wcPassword[PWLEN + 1];
  251. WCHAR wcConfirmPassword[PWLEN + 1];
  252. GetDlgItemText(m_hwnd,IDC_USERNAME,wcUserBuff,MAX_DOMANDANDMACHINENAMESIZE);
  253. GetDlgItemText(m_hwnd,IDC_PASSWORD,wcPassword, PWLEN);
  254. GetDlgItemText(m_hwnd,IDC_CONFIRMPASSWORD,wcConfirmPassword, PWLEN);
  255. if (wcscmp(wcPassword, wcConfirmPassword) != 0)
  256. {
  257. // we return this to signal the controlling page not to
  258. // dismiss the dialog.
  259. return(ERROR_INVALID_PASSWORD);
  260. }
  261. ITask *pITask;
  262. if (FAILED(hr = m_pISyncSched->GetITask(&pITask)))
  263. {
  264. return hr;
  265. }
  266. if (FAILED (hr = m_pISyncSched->SetAccountInformation(wcUserBuff,
  267. wcPassword)))
  268. {
  269. AssertSz(0,"ISyncSched->SetAccountInformation failed");
  270. return hr;
  271. }
  272. DWORD dwFlags;
  273. pITask->GetFlags(&dwFlags);
  274. if (FAILED(hr = pITask->SetFlags(dwFlags & (~TASK_FLAG_RUN_ONLY_IF_LOGGED_ON))))
  275. {
  276. AssertSz(0,"ITask->SetFlags failed");
  277. return hr;
  278. }
  279. pITask->Release();
  280. }
  281. else
  282. {
  283. ITask *pITask;
  284. if (FAILED(hr = m_pISyncSched->GetITask(&pITask)))
  285. {
  286. return hr;
  287. }
  288. WCHAR wszDomainAndUser[MAX_DOMANDANDMACHINENAMESIZE];
  289. GetDefaultDomainAndUserName(wszDomainAndUser,TEXT("\\"),ARRAYSIZE(wszDomainAndUser));
  290. if (FAILED(hr = m_pISyncSched->SetAccountInformation(wszDomainAndUser, NULL)))
  291. {
  292. AssertSz(0,"ISyncSched->SetAccountInformation failed");
  293. return hr;
  294. }
  295. DWORD dwFlags;
  296. pITask->GetFlags(&dwFlags);
  297. if (FAILED(hr = pITask->SetFlags(dwFlags | TASK_FLAG_RUN_ONLY_IF_LOGGED_ON)))
  298. {
  299. AssertSz(0,"ITask->SetFlags failed");
  300. return hr;
  301. }
  302. pITask->Release();
  303. }
  304. //Now save the schedule
  305. //NoteNote: optimize by moving the save from wizsel and cred to EditSyncSched
  306. hr = m_pISyncSched->Save();
  307. if (hr == S_OK)
  308. {
  309. *m_pfSaved = TRUE;
  310. }
  311. }
  312. return hr;
  313. }
  314. //+-------------------------------------------------------------------------------
  315. //
  316. // FUNCTION: BOOL CSelectItemsPage::SetEnabled(BOOL fEnabled)
  317. //
  318. // PURPOSE: set the fields enabled according to the RB choice
  319. //
  320. // RETURN VALUE: return TRUE if we process it ok.
  321. //
  322. //+-------------------------------------------------------------------------------
  323. BOOL CCredentialsPage::SetEnabled(BOOL fEnabled)
  324. {
  325. EnableWindow(GetDlgItem(m_hwnd, IDC_USERNAME), fEnabled);
  326. EnableWindow(GetDlgItem(m_hwnd, IDC_PASSWORD), fEnabled);
  327. EnableWindow(GetDlgItem(m_hwnd, IDC_CONFIRMPASSWORD), fEnabled);
  328. EnableWindow(GetDlgItem(m_hwnd, IDC_RUNAS_TEXT), fEnabled);
  329. EnableWindow(GetDlgItem(m_hwnd, IDC_PASSWORD_TEXT), fEnabled);
  330. EnableWindow(GetDlgItem(m_hwnd, IDC_CONFIRMPASSWORD_TEXT), fEnabled);
  331. return TRUE;
  332. }
  333. #endif // #ifdef _CREDENTIALS