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.

1084 lines
36 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998.
  5. //
  6. // File: Settings.cpp
  7. //
  8. // Contents: Onestop settings routines
  9. //
  10. // Classes:
  11. //
  12. // Notes:
  13. //
  14. // History: 10-Nov-97 SusiA Created.
  15. //
  16. //--------------------------------------------------------------------------
  17. #include "precomp.h"
  18. extern HINSTANCE g_hmodThisDll; // Handle to this DLL itself.
  19. extern UINT g_cRefThisDll;
  20. extern CRITICAL_SECTION g_DllCriticalSection; // Global Critical Section for this DLL
  21. // items for context sensitive help
  22. // Review -Should be string in resource.
  23. TCHAR szSyncMgrHelp[] = TEXT("mobsync.hlp");
  24. ULONG g_aContextHelpIds[] =
  25. {
  26. IDC_STATIC1, ((DWORD) -1),
  27. IDC_STATIC2, ((DWORD) -1),
  28. IDC_STATIC3, ((DWORD) -1),
  29. IDC_STATIC4, ((DWORD) -1),
  30. IDC_ADVANCEDIDLEOVERVIEWTEXT, ((DWORD) -1),
  31. IDC_ADVANCEDIDLEWAITTEXT, ((DWORD) -1),
  32. IDC_ADVANCEDIDLEMINUTESTEXT1, ((DWORD) -1),
  33. IDC_ADVANCEDIDLEMINUTESTEXT2, ((DWORD) -1),
  34. IDC_SP_SEPARATOR, ((DWORD) -1),
  35. IDS_CONNECTDESCRIPTION, ((DWORD) -1),
  36. IDC_SCHED_NAME, ((DWORD) -1),
  37. IDC_SCHED_STRING, ((DWORD) -1),
  38. IDC_LASTRUN, ((DWORD) -1),
  39. IDC_NEXTRUN, ((DWORD) -1),
  40. IDC_ConnectionText, ((DWORD) -1),
  41. IDC_RUNLOGGEDON, HIDC_RUNLOGGEDON,
  42. IDC_RUNALWAYS, HIDC_RUNALWAYS,
  43. IDC_RUNAS_TEXT, HIDC_RUNAS_TEXT,
  44. IDC_USERNAME, HIDC_USERNAME,
  45. IDC_PASSWORD_TEXT, HIDC_PASSWORD_TEXT,
  46. IDC_PASSWORD, HIDC_PASSWORD,
  47. IDC_CONFIRMPASSWORD_TEXT, HIDC_CONFIRMPASSWORD_TEXT,
  48. IDC_CONFIRMPASSWORD, HIDC_CONFIRMPASSWORD,
  49. IDC_ADVANCEDIDLE, HIDC_ADVANCEDIDLE,
  50. IDC_AUTOCONNECT, HIDC_AUTOCONNECT,
  51. IDC_AUTOLOGOFF, HIDC_AUTOLOGOFF,
  52. IDC_AUTOLOGON, HIDC_AUTOLOGON,
  53. IDC_AUTOPROMPT_ME_FIRST, HIDC_AUTOPROMPT_ME_FIRST,
  54. IDC_AUTOUPDATECOMBO, HIDC_AUTOUPDATECOMBO,
  55. IDC_AUTOUPDATELIST, HIDC_AUTOUPDATELIST,
  56. IDC_CHECKREPEATESYNC, HIDC_CHECKREPEATESYNC,
  57. IDC_CHECKRUNONBATTERIES, HIDC_CHECKRUNONBATTERIES,
  58. IDC_EDITIDLEREPEATMINUTES, HIDC_EDITIDLEREPEATMINUTES,
  59. IDC_EDITIWAITMINUTES, HIDC_EDITIWAITMINUTES,
  60. IDC_SPINIDLEREPEATMINUTES, HIDC_EDITIDLEREPEATMINUTES,
  61. IDC_SPINIDLEWAITMINUTES, HIDC_EDITIWAITMINUTES,
  62. IDC_IDLECHECKBOX, HIDC_IDLECHECKBOX,
  63. IDC_SCHEDADD, HIDC_SCHEDADD,
  64. IDC_SCHEDEDIT, HIDC_SCHEDEDIT,
  65. IDC_SCHEDLIST, HIDC_SCHEDLIST,
  66. IDC_SCHEDREMOVE, HIDC_SCHEDREMOVE,
  67. IDC_SCHEDUPDATECOMBO, HIDC_SCHEDUPDATECOMBO,
  68. IDC_SCHEDUPDATELIST, HIDC_SCHEDUPDATELIST,
  69. IDC_SCHED_NAME_EDITBOX, HIDC_SCHED_NAME_EDITBOX,
  70. 0,0
  71. };
  72. INT_PTR CALLBACK AutoSyncDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam);
  73. INT_PTR CALLBACK SchedSyncDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam);
  74. INT_PTR CALLBACK IdleSyncDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam);
  75. INT_PTR CALLBACK IdleAdvancedSettingsDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam);
  76. int CALLBACK PropSheetProc( HWND hwndDlg, UINT uMsg, LPARAM lParam);
  77. DWORD WINAPI SettingsThread( LPVOID lpArg );
  78. DWORD g_SettingsThreadID = NULL;
  79. HWND g_hwndPropSheet = NULL;
  80. CAutoSyncPage *g_pAutoSyncPage = NULL; // shared by AutoSync and IdleSyncDlg Procs
  81. CSchedSyncPage *g_pSchedSyncPage = NULL;
  82. BOOL g_fInSettingsDialog = FALSE;
  83. //+-------------------------------------------------------------------------------
  84. //
  85. // FUNCTION: IsSchedulingInstalled()
  86. //
  87. // PURPOSE: Determines is there is a task scheduler on the current workstation
  88. //
  89. //
  90. //--------------------------------------------------------------------------------
  91. BOOL IsSchedulingInstalled()
  92. {
  93. BOOL fInstalled = FALSE;
  94. ISchedulingAgent *pSchedAgent = NULL;
  95. // Review if there is a better way to test this.
  96. if (NOERROR == CoCreateInstance(CLSID_CSchedulingAgent,
  97. NULL,
  98. CLSCTX_INPROC_SERVER,
  99. IID_ISchedulingAgent,
  100. (LPVOID*)&pSchedAgent))
  101. {
  102. fInstalled = TRUE;
  103. pSchedAgent->Release();
  104. }
  105. return fInstalled;
  106. }
  107. //+-------------------------------------------------------------------------------
  108. //
  109. // FUNCTION: IsIdleAvailable()
  110. //
  111. // PURPOSE: Determines is this machine supports can Idle
  112. //
  113. //
  114. //--------------------------------------------------------------------------------
  115. BOOL IsIdleAvailable()
  116. {
  117. BOOL fInstalled = FALSE;
  118. ISchedulingAgent *pSchedAgent = NULL;
  119. // Review if there is a better way to test this.
  120. if (NOERROR == CoCreateInstance(CLSID_CSchedulingAgent,
  121. NULL,
  122. CLSCTX_INPROC_SERVER,
  123. IID_ISchedulingAgent,
  124. (LPVOID*)&pSchedAgent) )
  125. {
  126. fInstalled = TRUE;
  127. pSchedAgent->Release();
  128. }
  129. return fInstalled;
  130. }
  131. //+-------------------------------------------------------------------------------
  132. //
  133. // FUNCTION: IsAutoSyncAvailable()
  134. //
  135. // PURPOSE: Determines is this machine supports AutoSync
  136. //
  137. //
  138. //--------------------------------------------------------------------------------
  139. BOOL IsAutoSyncAvailable()
  140. {
  141. return TRUE;
  142. }
  143. //+-------------------------------------------------------------------------------
  144. //
  145. // FUNCTION: DisplayOptions()
  146. //
  147. // PURPOSE: Display the Onestop autosync options
  148. //
  149. //
  150. //--------------------------------------------------------------------------------
  151. STDAPI DisplayOptions(HWND hwndOwner)
  152. {
  153. #define MAXNUMPROPSHEETS 3
  154. int hr = E_FAIL;
  155. DWORD dwError;
  156. // always use ANSI versions since doesn't matter
  157. PROPSHEETPAGE psp [MAXNUMPROPSHEETS];
  158. HPROPSHEETPAGE hpsp [MAXNUMPROPSHEETS];
  159. PROPSHEETHEADER psh;
  160. int nPages = 0;
  161. BOOL fIdleAvailable;
  162. CCriticalSection cCritSect(&g_DllCriticalSection,GetCurrentThreadId());
  163. cCritSect.Enter();
  164. if (g_fInSettingsDialog) // IF ALREADY DISPLAYING A DIALOG BOX, THEN JUST RETURN
  165. {
  166. HWND hwndSettings = g_hwndPropSheet;
  167. cCritSect.Leave();
  168. if (hwndSettings)
  169. {
  170. SetForegroundWindow(hwndSettings);
  171. }
  172. return NOERROR;
  173. }
  174. g_fInSettingsDialog = TRUE;
  175. cCritSect.Leave();
  176. hr = CoInitialize(NULL);
  177. if (SUCCEEDED(hr))
  178. {
  179. RegSetUserDefaults(); // Make Sure the UserDefaults are up to date
  180. ZeroMemory(psp,sizeof(*psp));
  181. ZeroMemory(&psh, sizeof(psh));
  182. if (IsAutoSyncAvailable())
  183. {
  184. psp[nPages].dwSize = sizeof (psp[0]);
  185. psp[nPages].dwFlags = PSP_DEFAULT | PSP_USETITLE;
  186. psp[nPages].hInstance = g_hmodThisDll;
  187. psp[nPages].pszTemplate = MAKEINTRESOURCE(IDD_AUTOSYNC);
  188. psp[nPages].pszIcon = NULL;
  189. psp[nPages].pfnDlgProc = AutoSyncDlgProc;
  190. psp[nPages].pszTitle = MAKEINTRESOURCE(IDS_LOGONLOGOFF_TAB);
  191. psp[nPages].lParam = 0;
  192. hpsp[nPages] = CreatePropertySheetPage(&(psp[nPages]));
  193. ++nPages;
  194. }
  195. if (fIdleAvailable = IsIdleAvailable())
  196. {
  197. psp[nPages].dwSize = sizeof (psp[0]);
  198. psp[nPages].dwFlags = PSP_DEFAULT | PSP_USETITLE;
  199. psp[nPages].hInstance = g_hmodThisDll;
  200. psp[nPages].pszTemplate = MAKEINTRESOURCE(IDD_IDLESETTINGS);
  201. psp[nPages].pszIcon = NULL;
  202. psp[nPages].pfnDlgProc = IdleSyncDlgProc;
  203. psp[nPages].pszTitle = MAKEINTRESOURCE(IDS_ONIDLE_TAB);
  204. psp[nPages].lParam = 0;
  205. hpsp[nPages] = CreatePropertySheetPage(&(psp[nPages]));
  206. ++nPages;
  207. }
  208. // Review - if have idle have schedule, why not collapse
  209. // all these IsxxxAvailable into one call.
  210. if (fIdleAvailable /* IsSchedulingInstalled() */)
  211. {
  212. psp[nPages].dwSize = sizeof (psp[0]);
  213. psp[nPages].dwFlags = PSP_DEFAULT | PSP_USETITLE;
  214. psp[nPages].hInstance = g_hmodThisDll;
  215. psp[nPages].pszTemplate = MAKEINTRESOURCE(IDD_SCHEDSYNC);
  216. psp[nPages].pszIcon = NULL;
  217. psp[nPages].pfnDlgProc = SchedSyncDlgProc;
  218. psp[nPages].pszTitle = MAKEINTRESOURCE(IDS_SCHEDULED_TAB);
  219. psp[nPages].lParam = 0;
  220. hpsp[nPages] = CreatePropertySheetPage(&(psp[nPages]));
  221. ++nPages;
  222. }
  223. Assert(nPages <= MAXNUMPROPSHEETS);
  224. psh.dwSize = sizeof (psh);
  225. psh.dwFlags = PSH_DEFAULT | PSH_USECALLBACK | PSH_USEHICON;
  226. psh.hwndParent = hwndOwner;
  227. psh.hInstance = g_hmodThisDll;
  228. psh.pszIcon = NULL;
  229. psh.hIcon = LoadIcon(g_hmodThisDll, MAKEINTRESOURCE(IDI_SYNCMGR));
  230. psh.pszCaption = MAKEINTRESOURCE(IDS_SCHEDULED_TITLE);
  231. psh.nPages = nPages;
  232. psh.phpage = hpsp;
  233. psh.pfnCallback = PropSheetProc;
  234. psh.nStartPage = 0;
  235. hr = (int)PropertySheet(&psh);
  236. // remove global classes
  237. if (g_pAutoSyncPage)
  238. {
  239. delete g_pAutoSyncPage;
  240. g_pAutoSyncPage = NULL;
  241. }
  242. g_SettingsThreadID = NULL;
  243. if (g_pSchedSyncPage)
  244. {
  245. delete g_pSchedSyncPage;
  246. g_pSchedSyncPage = NULL;
  247. }
  248. g_hwndPropSheet = NULL;
  249. CoFreeUnusedLibraries();
  250. CoUninitialize();
  251. }
  252. if (hr == -1)
  253. {
  254. dwError = GetLastError();
  255. }
  256. cCritSect.Enter();
  257. g_fInSettingsDialog = FALSE; // allow another settings to be created.
  258. cCritSect.Leave();
  259. return hr;
  260. }
  261. //+-------------------------------------------------------------------------------
  262. // FUNCTION: AutoSyncDlgProc(HWND, UINT, WPARAM, LPARAM)
  263. //
  264. // PURPOSE: Callback dialog procedure for the property page
  265. //
  266. // PARAMETERS:
  267. // hDlg - Dialog box window handle
  268. // uMessage - current message
  269. // wParam - depends on message
  270. // lParam - depends on message
  271. //
  272. // RETURN VALUE:
  273. //
  274. // Depends on message. In general, return TRUE if we process it.
  275. //
  276. // COMMENTS:
  277. //
  278. //+-------------------------------------------------------------------------------
  279. INT_PTR CALLBACK AutoSyncDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
  280. {
  281. WORD wNotifyCode = HIWORD(wParam); // notification code
  282. switch (uMessage)
  283. {
  284. case WM_INITDIALOG:
  285. {
  286. if (NULL == g_pAutoSyncPage)
  287. {
  288. g_pAutoSyncPage = new CAutoSyncPage(g_hmodThisDll);
  289. }
  290. if (g_pAutoSyncPage)
  291. {
  292. g_pAutoSyncPage->SetAutoSyncHwnd(hDlg);
  293. g_pAutoSyncPage->InitializeHwnd(hDlg,SYNCTYPE_AUTOSYNC,0);
  294. return TRUE;
  295. }
  296. else
  297. {
  298. return FALSE;
  299. }
  300. }
  301. break;
  302. case WM_DESTROY:
  303. {
  304. if (g_pAutoSyncPage && g_pAutoSyncPage->m_pItemListViewAutoSync)
  305. {
  306. delete g_pAutoSyncPage->m_pItemListViewAutoSync;
  307. g_pAutoSyncPage->m_pItemListViewAutoSync = NULL;
  308. }
  309. }
  310. break;
  311. case WM_COMMAND:
  312. switch (LOWORD(wParam))
  313. {
  314. case IDC_AUTOUPDATECOMBO:
  315. {
  316. if (wNotifyCode == CBN_SELCHANGE)
  317. {
  318. HWND hwndCombo = (HWND) lParam;
  319. if (g_pAutoSyncPage)
  320. {
  321. g_pAutoSyncPage->ShowItemsOnThisConnection
  322. (hDlg,SYNCTYPE_AUTOSYNC,ComboBox_GetCurSel(hwndCombo));
  323. }
  324. }
  325. }
  326. break;
  327. case IDC_AUTOLOGON:
  328. case IDC_AUTOLOGOFF:
  329. case IDC_AUTOPROMPT_ME_FIRST:
  330. {
  331. if (wNotifyCode == BN_CLICKED)
  332. {
  333. PropSheet_Changed(g_hwndPropSheet, hDlg);
  334. HWND hwndCtrl = (HWND) lParam;
  335. g_pAutoSyncPage->SetConnectionCheck(hDlg,SYNCTYPE_AUTOSYNC,LOWORD(wParam),
  336. Button_GetCheck(hwndCtrl));
  337. }
  338. }
  339. break;
  340. default:
  341. break;
  342. }
  343. break;
  344. case WM_HELP:
  345. {
  346. LPHELPINFO lphi = (LPHELPINFO)lParam;
  347. if (lphi->iContextType == HELPINFO_WINDOW)
  348. {
  349. WinHelp ( (HWND) lphi->hItemHandle,
  350. szSyncMgrHelp,
  351. HELP_WM_HELP,
  352. (ULONG_PTR) g_aContextHelpIds);
  353. }
  354. return TRUE;
  355. }
  356. case WM_CONTEXTMENU:
  357. {
  358. WinHelp ((HWND)wParam,
  359. szSyncMgrHelp,
  360. HELP_CONTEXTMENU,
  361. (ULONG_PTR)g_aContextHelpIds);
  362. return TRUE;
  363. }
  364. case WM_NOTIFYLISTVIEWEX:
  365. if (g_pAutoSyncPage)
  366. {
  367. int idCtrl = (int) wParam;
  368. LPNMHDR pnmhdr = (LPNMHDR) lParam;
  369. if ( (IDC_AUTOUPDATELIST != idCtrl) || (NULL == g_pAutoSyncPage->m_pItemListViewAutoSync))
  370. {
  371. Assert(IDC_AUTOUPDATELIST == idCtrl);
  372. Assert(g_pAutoSyncPage->m_pItemListViewAutoSync);
  373. break;
  374. }
  375. switch (pnmhdr->code)
  376. {
  377. case LVNEX_ITEMCHECKCOUNT:
  378. {
  379. LPNMLISTVIEWEXITEMCHECKCOUNT pnmvCheckCount = (LPNMLISTVIEWEXITEMCHECKCOUNT) lParam;
  380. // pass along notification only if listView is done being initialized
  381. // since no need to set the CheckState or mark PSheet as Dirty
  382. if (g_pAutoSyncPage->m_pItemListViewAutoSyncInitialized)
  383. {
  384. g_pAutoSyncPage->SetItemCheckState(hDlg,SYNCTYPE_AUTOSYNC,
  385. pnmvCheckCount->iItemId,pnmvCheckCount->dwItemState
  386. ,pnmvCheckCount->iCheckCount);
  387. PropSheet_Changed(g_hwndPropSheet, hDlg);
  388. }
  389. break;
  390. }
  391. default:
  392. break;
  393. }
  394. }
  395. break;
  396. case WM_NOTIFY:
  397. if (g_pAutoSyncPage)
  398. {
  399. int idCtrl = (int) wParam;
  400. LPNMHDR pnmhdr = (LPNMHDR) lParam;
  401. // if notification for UpdateListPass it on.
  402. if ((IDC_AUTOUPDATELIST == idCtrl) && g_pAutoSyncPage->m_pItemListViewAutoSync)
  403. {
  404. g_pAutoSyncPage->m_pItemListViewAutoSync->OnNotify(pnmhdr);
  405. break;
  406. }
  407. }
  408. switch (((NMHDR FAR *)lParam)->code)
  409. {
  410. case PSN_SETACTIVE:
  411. break;
  412. case PSN_APPLY:
  413. //User has clicked the OK or Apply button so we'll
  414. //Save the current selections
  415. g_pAutoSyncPage->CommitAutoSyncChanges();
  416. break;
  417. default:
  418. break;
  419. }
  420. break;
  421. default:
  422. return FALSE;
  423. }
  424. return FALSE;
  425. }
  426. //+-------------------------------------------------------------------------------
  427. // FUNCTION: IdleSyncDlgProc(HWND, UINT, WPARAM, LPARAM)
  428. //
  429. // PURPOSE: Callback dialog procedure for the iDLE property page
  430. //
  431. // PARAMETERS:
  432. // hDlg - Dialog box window handle
  433. // uMessage - current message
  434. // wParam - depends on message
  435. // lParam - depends on message
  436. //
  437. // RETURN VALUE:
  438. //
  439. // Depends on message. In general, return TRUE if we process it.
  440. //
  441. // COMMENTS:
  442. //
  443. //+-------------------------------------------------------------------------------
  444. INT_PTR CALLBACK IdleSyncDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
  445. {
  446. WORD wNotifyCode = HIWORD(wParam); // notification code
  447. switch (uMessage)
  448. {
  449. case WM_INITDIALOG:
  450. {
  451. /*
  452. RECT rc;
  453. HRESULT hr;
  454. hr = GetWindowRect(hDlg, &rc);
  455. hr = SetWindowPos(hDlg,
  456. NULL,
  457. ((GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2),
  458. ((GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 2),
  459. 0,
  460. 0,
  461. SWP_NOSIZE | SWP_NOACTIVATE); */
  462. if (NULL == g_pAutoSyncPage)
  463. {
  464. g_pAutoSyncPage = new CAutoSyncPage(g_hmodThisDll);
  465. }
  466. if (g_pAutoSyncPage)
  467. {
  468. BOOL fConnectionsAvailable;
  469. g_pAutoSyncPage->SetIdleHwnd(hDlg);
  470. g_pAutoSyncPage->InitializeHwnd(hDlg,SYNCTYPE_IDLE,0);
  471. // there must be at least one connection or we disable
  472. // the advanced button.
  473. fConnectionsAvailable =
  474. g_pAutoSyncPage->GetNumConnections(hDlg,SYNCTYPE_IDLE)
  475. ? TRUE : FALSE;
  476. EnableWindow(GetDlgItem(hDlg,IDC_ADVANCEDIDLE),fConnectionsAvailable);
  477. return TRUE;
  478. }
  479. else
  480. {
  481. return FALSE;
  482. }
  483. }
  484. break;
  485. case WM_DESTROY:
  486. {
  487. if (g_pAutoSyncPage && g_pAutoSyncPage->m_pItemListViewIdle)
  488. {
  489. delete g_pAutoSyncPage->m_pItemListViewIdle;
  490. g_pAutoSyncPage->m_pItemListViewIdle = NULL;
  491. }
  492. // PostQuitMessage(0);
  493. // PostQuitMessage(0);
  494. }
  495. break;
  496. case WM_HELP:
  497. {
  498. LPHELPINFO lphi = (LPHELPINFO)lParam;
  499. if (lphi->iContextType == HELPINFO_WINDOW)
  500. {
  501. WinHelp ( (HWND) lphi->hItemHandle,
  502. szSyncMgrHelp,
  503. HELP_WM_HELP,
  504. (ULONG_PTR) g_aContextHelpIds);
  505. }
  506. return TRUE;
  507. }
  508. case WM_CONTEXTMENU:
  509. {
  510. WinHelp ((HWND)wParam,
  511. szSyncMgrHelp,
  512. HELP_CONTEXTMENU,
  513. (ULONG_PTR)g_aContextHelpIds);
  514. return TRUE;
  515. }
  516. case WM_COMMAND:
  517. switch (LOWORD(wParam))
  518. {
  519. case IDC_AUTOUPDATECOMBO:
  520. {
  521. if (wNotifyCode == CBN_SELCHANGE)
  522. {
  523. HWND hwndCombo = (HWND) lParam;
  524. if (g_pAutoSyncPage)
  525. {
  526. g_pAutoSyncPage->ShowItemsOnThisConnection
  527. (hDlg,SYNCTYPE_IDLE,ComboBox_GetCurSel(hwndCombo));
  528. }
  529. }
  530. }
  531. break;
  532. case IDC_IDLECHECKBOX:
  533. {
  534. if (wNotifyCode == BN_CLICKED)
  535. {
  536. PropSheet_Changed(g_hwndPropSheet, hDlg);
  537. HWND hwndCtrl = (HWND) lParam;
  538. g_pAutoSyncPage->SetConnectionCheck(hDlg,SYNCTYPE_IDLE,LOWORD(wParam),
  539. Button_GetCheck(hwndCtrl));
  540. }
  541. }
  542. break;
  543. case IDC_ADVANCEDIDLE:
  544. {
  545. if (wNotifyCode == BN_CLICKED)
  546. {
  547. // bring up the advanced idle dialog passing in the autoSyncPage class
  548. // as the owning class.
  549. DialogBoxParam(g_hmodThisDll,
  550. MAKEINTRESOURCE(IDD_ADVANCEDIDLESETTINGS),hDlg, IdleAdvancedSettingsDlgProc,
  551. (LPARAM) g_pAutoSyncPage);
  552. }
  553. }
  554. break;
  555. default:
  556. break;
  557. }
  558. break;
  559. case WM_NOTIFYLISTVIEWEX:
  560. if (g_pAutoSyncPage)
  561. {
  562. int idCtrl = (int) wParam;
  563. LPNMHDR pnmhdr = (LPNMHDR) lParam;
  564. if ( (IDC_AUTOUPDATELIST != idCtrl) || (NULL == g_pAutoSyncPage->m_pItemListViewIdle))
  565. {
  566. Assert(IDC_AUTOUPDATELIST == idCtrl);
  567. Assert(g_pAutoSyncPage->m_pItemListViewIdle);
  568. break;
  569. }
  570. switch (pnmhdr->code)
  571. {
  572. case LVNEX_ITEMCHECKCOUNT:
  573. {
  574. LPNMLISTVIEWEXITEMCHECKCOUNT pnmvCheckCount = (LPNMLISTVIEWEXITEMCHECKCOUNT) lParam;
  575. // pass along notification only if listView is done being initialized
  576. // since no need to set the CheckState or mark PSheet as Dirty
  577. if (g_pAutoSyncPage->m_fListViewIdleInitialized)
  578. {
  579. g_pAutoSyncPage->SetItemCheckState(hDlg,SYNCTYPE_IDLE,
  580. pnmvCheckCount->iItemId,pnmvCheckCount->dwItemState
  581. ,pnmvCheckCount->iCheckCount);
  582. PropSheet_Changed(g_hwndPropSheet, hDlg);
  583. }
  584. break;
  585. }
  586. default:
  587. break;
  588. }
  589. }
  590. break;
  591. case WM_NOTIFY:
  592. if (g_pAutoSyncPage)
  593. {
  594. int idCtrl = (int) wParam;
  595. LPNMHDR pnmhdr = (LPNMHDR) lParam;
  596. // if notification for UpdateListPass it on.
  597. if ((IDC_AUTOUPDATELIST == idCtrl) && g_pAutoSyncPage->m_pItemListViewIdle)
  598. {
  599. g_pAutoSyncPage->m_pItemListViewIdle->OnNotify(pnmhdr);
  600. break;
  601. }
  602. switch (((NMHDR FAR *)lParam)->code)
  603. {
  604. case PSN_SETACTIVE:
  605. break;
  606. case PSN_APPLY:
  607. //User has clicked the OK or Apply button so we'll
  608. //Save the current selections
  609. g_pAutoSyncPage->CommitIdleChanges();
  610. break;
  611. default:
  612. break;
  613. }
  614. }
  615. break;
  616. default:
  617. return FALSE;
  618. }
  619. return FALSE;
  620. }
  621. //+-------------------------------------------------------------------------------
  622. // FUNCTION: IdleAdvancedSettingsDlgProc(HWND, UINT, WPARAM, LPARAM)
  623. //
  624. // PURPOSE: Callback dialog procedure for the Advanced Idle Settings.
  625. //
  626. // PARAMETERS:
  627. // hDlg - Dialog box window handle
  628. // uMessage - current message
  629. // wParam - depends on message
  630. // lParam - depends on message
  631. //
  632. // RETURN VALUE:
  633. //
  634. // Depends on message. In general, return TRUE if we process it.
  635. //
  636. // COMMENTS:
  637. //
  638. //+-------------------------------------------------------------------------------
  639. INT_PTR CALLBACK IdleAdvancedSettingsDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
  640. {
  641. switch(uMessage)
  642. {
  643. case WM_INITDIALOG:
  644. {
  645. CONNECTIONSETTINGS ConnectionSettings;
  646. Assert(g_pAutoSyncPage);
  647. if (NULL == g_pAutoSyncPage)
  648. return FALSE;
  649. UpDown_SetRange(GetDlgItem(hDlg,IDC_SPINIDLEWAITMINUTES), SPINDIALWAITMINUTES_MIN, SPINDIALWAITMINUTES_MAX);
  650. Edit_LimitText(GetDlgItem(hDlg,IDC_EDITIWAITMINUTES), 3);
  651. UpDown_SetRange(GetDlgItem(hDlg,IDC_SPINIDLEREPEATMINUTES), SPINDIALREPEATMINUTES_MIN, SPINDIALREPEATMINUTES_MAX);
  652. Edit_LimitText(GetDlgItem(hDlg,IDC_EDITIDLEREPEATMINUTES), 3);
  653. // initialize user specific preferences
  654. // if can't get shouldn't show dialog
  655. // EditText cannot accept DBCS characters on Win9x so disalbe IME for
  656. // Edit Boxes.
  657. ImmAssociateContext(GetDlgItem(hDlg,IDC_EDITIWAITMINUTES), NULL);
  658. ImmAssociateContext(GetDlgItem(hDlg,IDC_EDITIDLEREPEATMINUTES), NULL);
  659. if (NOERROR == g_pAutoSyncPage->GetAdvancedIdleSettings(&ConnectionSettings))
  660. {
  661. UpDown_SetPos(GetDlgItem(hDlg,IDC_SPINIDLEWAITMINUTES), ConnectionSettings.ulIdleWaitMinutes);
  662. UpDown_SetPos(GetDlgItem(hDlg,IDC_SPINIDLEREPEATMINUTES),ConnectionSettings.ulIdleRetryMinutes);
  663. Button_SetCheck(GetDlgItem(hDlg,IDC_CHECKREPEATESYNC),ConnectionSettings.dwRepeatSynchronization);
  664. Button_SetCheck(GetDlgItem(hDlg,IDC_CHECKRUNONBATTERIES),!(ConnectionSettings.dwRunOnBatteries));
  665. // if the repeat check state is selected then enable the edit box associated with it
  666. EnableWindow(GetDlgItem(hDlg,IDC_SPINIDLEREPEATMINUTES),ConnectionSettings.dwRepeatSynchronization);
  667. EnableWindow(GetDlgItem(hDlg,IDC_EDITIDLEREPEATMINUTES),ConnectionSettings.dwRepeatSynchronization);
  668. EnableWindow(GetDlgItem(hDlg,IDC_ADVANCEDIDLEMINUTESTEXT2),ConnectionSettings.dwRepeatSynchronization);
  669. }
  670. ShowWindow(hDlg,SW_SHOW);
  671. return TRUE;
  672. break;
  673. }
  674. case WM_HELP:
  675. {
  676. LPHELPINFO lphi = (LPHELPINFO)lParam;
  677. if (lphi->iContextType == HELPINFO_WINDOW)
  678. {
  679. WinHelp ( (HWND) lphi->hItemHandle,
  680. szSyncMgrHelp,
  681. HELP_WM_HELP,
  682. (ULONG_PTR) g_aContextHelpIds);
  683. }
  684. return TRUE;
  685. }
  686. case WM_CONTEXTMENU:
  687. {
  688. WinHelp ((HWND)wParam,
  689. szSyncMgrHelp,
  690. HELP_CONTEXTMENU,
  691. (ULONG_PTR)g_aContextHelpIds);
  692. return TRUE;
  693. }
  694. case WM_COMMAND:
  695. switch (LOWORD(wParam))
  696. {
  697. case IDCANCEL:
  698. EndDialog(hDlg,FALSE);
  699. break;
  700. case IDOK:
  701. if (g_pAutoSyncPage)
  702. {
  703. CONNECTIONSETTINGS ConnectionSettings;
  704. if (g_pAutoSyncPage)
  705. {
  706. ConnectionSettings.ulIdleWaitMinutes = GetDlgItemInt(hDlg, IDC_EDITIWAITMINUTES, NULL, FALSE);
  707. ConnectionSettings.ulIdleRetryMinutes = GetDlgItemInt(hDlg, IDC_EDITIDLEREPEATMINUTES, NULL, FALSE);
  708. ConnectionSettings.dwRepeatSynchronization = Button_GetCheck(GetDlgItem(hDlg,IDC_CHECKREPEATESYNC));
  709. ConnectionSettings.dwRunOnBatteries = (!Button_GetCheck(GetDlgItem(hDlg,IDC_CHECKRUNONBATTERIES)));
  710. g_pAutoSyncPage->SetAdvancedIdleSettings(&ConnectionSettings);
  711. }
  712. }
  713. EndDialog(hDlg,FALSE);
  714. break;
  715. case IDC_EDITIWAITMINUTES:
  716. {
  717. WORD wNotifyCode = HIWORD(wParam);
  718. INT iNewPos;
  719. //
  720. // If the user just pasted non-numeric text or an illegal numeric
  721. // value, overwrite it and complain.
  722. //
  723. if (EN_KILLFOCUS == wNotifyCode)
  724. {
  725. iNewPos = GetDlgItemInt(hDlg, IDC_EDITIWAITMINUTES, NULL, FALSE);
  726. if (iNewPos < SPINDIALWAITMINUTES_MIN || iNewPos > SPINDIALWAITMINUTES_MAX)
  727. {
  728. HWND hUD = GetDlgItem(hDlg,IDC_SPINIDLEWAITMINUTES);
  729. if (iNewPos < SPINDIALWAITMINUTES_MIN)
  730. {
  731. UpDown_SetPos(hUD, SPINDIALWAITMINUTES_MIN);
  732. }
  733. else
  734. {
  735. UpDown_SetPos(hUD,SPINDIALWAITMINUTES_MAX);
  736. }
  737. }
  738. }
  739. break;
  740. }
  741. case IDC_EDITIDLEREPEATMINUTES:
  742. {
  743. WORD wNotifyCode = HIWORD(wParam);
  744. INT iNewPos;
  745. //
  746. // If the user just pasted non-numeric text or an illegal numeric
  747. // value, overwrite it and complain.
  748. //
  749. // Review, redundant code with other spin control.
  750. if (EN_KILLFOCUS == wNotifyCode)
  751. {
  752. iNewPos = GetDlgItemInt(hDlg, IDC_EDITIDLEREPEATMINUTES, NULL, FALSE);
  753. if (iNewPos < SPINDIALREPEATMINUTES_MIN || iNewPos > SPINDIALREPEATMINUTES_MAX)
  754. {
  755. HWND hUD = GetDlgItem(hDlg,IDC_SPINIDLEREPEATMINUTES);
  756. if (iNewPos < SPINDIALREPEATMINUTES_MIN)
  757. {
  758. UpDown_SetPos(hUD, SPINDIALREPEATMINUTES_MIN);
  759. }
  760. else
  761. {
  762. UpDown_SetPos(hUD,SPINDIALREPEATMINUTES_MAX);
  763. }
  764. }
  765. }
  766. break;
  767. }
  768. case IDC_CHECKREPEATESYNC:
  769. {
  770. WORD wNotifyCode = HIWORD(wParam);
  771. // if use clicked the repeat check box set set state of the other
  772. // items associated with it.
  773. if (BN_CLICKED == wNotifyCode)
  774. {
  775. BOOL fEnableState = Button_GetCheck(GetDlgItem(hDlg,IDC_CHECKREPEATESYNC));
  776. // if the repeat check state is selected then enable the edit box associated with it
  777. EnableWindow(GetDlgItem(hDlg,IDC_SPINIDLEREPEATMINUTES),fEnableState);
  778. EnableWindow(GetDlgItem(hDlg,IDC_EDITIDLEREPEATMINUTES),fEnableState);
  779. EnableWindow(GetDlgItem(hDlg,IDC_ADVANCEDIDLEMINUTESTEXT2),fEnableState);
  780. }
  781. break;
  782. }
  783. default:
  784. break;
  785. }
  786. default:
  787. break;
  788. }
  789. return FALSE;
  790. }
  791. //+-------------------------------------------------------------------------------
  792. // FUNCTION: SchedSyncDlgProc(HWND, UINT, WPARAM, LPARAM)
  793. //
  794. // PURPOSE: Callback dialog procedure for the property page
  795. //
  796. // PARAMETERS:
  797. // hDlg - Dialog box window handle
  798. // uMessage - current message
  799. // wParam - depends on message
  800. // lParam - depends on message
  801. //
  802. // RETURN VALUE:
  803. //
  804. // Depends on message. In general, return TRUE if we process it.
  805. //
  806. // COMMENTS:
  807. //
  808. //--------------------------------------------------------------------------------
  809. INT_PTR CALLBACK SchedSyncDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
  810. {
  811. WORD wNotifyCode = HIWORD(wParam); // notification code
  812. BOOL bResult = FALSE;
  813. switch (uMessage)
  814. {
  815. case WM_INITDIALOG:
  816. {
  817. g_pSchedSyncPage = new CSchedSyncPage(g_hmodThisDll, hDlg);
  818. if (g_pSchedSyncPage)
  819. {
  820. bResult = g_pSchedSyncPage->Initialize();
  821. }
  822. }
  823. break;
  824. case WM_DESTROY:
  825. {
  826. g_pSchedSyncPage->FreeAllSchedules();
  827. }
  828. break;
  829. case WM_HELP:
  830. {
  831. LPHELPINFO lphi = (LPHELPINFO)lParam;
  832. if (lphi->iContextType == HELPINFO_WINDOW)
  833. {
  834. WinHelp ( (HWND) lphi->hItemHandle,
  835. szSyncMgrHelp,
  836. HELP_WM_HELP,
  837. (ULONG_PTR) g_aContextHelpIds);
  838. }
  839. bResult = TRUE;
  840. }
  841. break;
  842. case WM_CONTEXTMENU:
  843. {
  844. WinHelp ((HWND)wParam,
  845. szSyncMgrHelp,
  846. HELP_CONTEXTMENU,
  847. (ULONG_PTR)g_aContextHelpIds);
  848. bResult = TRUE;
  849. }
  850. break;
  851. case WM_NOTIFY:
  852. switch (((NMHDR FAR *)lParam)->code)
  853. {
  854. case PSN_SETACTIVE:
  855. break;
  856. case PSN_APPLY:
  857. //User has clicked the OK or Apply button so we'll
  858. //update the icon information in the .GAK file
  859. break;
  860. default:
  861. bResult = g_pSchedSyncPage->OnNotify(hDlg,(int)wParam,(LPNMHDR)lParam);
  862. break;
  863. }
  864. break;
  865. case WM_COMMAND:
  866. bResult = g_pSchedSyncPage->OnCommand(hDlg, HIWORD(wParam), LOWORD(wParam),
  867. (HWND)lParam);
  868. break;
  869. default:
  870. break;
  871. }
  872. return bResult;
  873. }
  874. //+-------------------------------------------------------------------------------
  875. //
  876. // FUNCTION: CALLBACK PropSheetProc( HWND hwndDlg, UINT uMsg, LPARAM lParam);
  877. //
  878. // PURPOSE: Callback dialog init procedure the settings property dialog
  879. //
  880. // PARAMETERS:
  881. // hwndDlg - Dialog box window handle
  882. // uMsg - current message
  883. // lParam - depends on message
  884. //
  885. //--------------------------------------------------------------------------------
  886. int CALLBACK PropSheetProc( HWND hwndDlg, UINT uMsg, LPARAM lParam)
  887. {
  888. switch(uMsg)
  889. {
  890. case PSCB_INITIALIZED:
  891. g_hwndPropSheet = hwndDlg;
  892. return TRUE;
  893. break;
  894. default:
  895. return TRUE;
  896. }
  897. return TRUE;
  898. }