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.

671 lines
21 KiB

  1. //+---------------------------------------------------------------------------
  2. /////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 1997-2002.
  6. //
  7. // File: log.cpp
  8. //
  9. // Contents: Definition of CLogOnHoursDlg
  10. // Dialog displaying the weekly logging hours for a particular user.
  11. //
  12. // HISTORY
  13. // 17-Jul-97 t-danm Creation.
  14. /////////////////////////////////////////////////////////////////////
  15. #include "stdafx.h"
  16. #include "resource.h"
  17. #include "Log.h"
  18. #include "resource.h"
  19. #include "log_gmt.h" // NetpRotateLogonHours ()
  20. #define CB_LOGON_ARRAY_LENGTH (7 * 24) // Number of bytes in logon array.
  21. /////////////////////////////////////////////////////////////////////////////
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CLogOnHoursDlg dialog
  24. CLogOnHoursDlg::CLogOnHoursDlg ( UINT nIDTemplate, CWnd* pParentWnd, bool fInputAsGMT, bool bAddDaylightBias)
  25. : CScheduleBaseDlg (nIDTemplate, bAddDaylightBias, pParentWnd),
  26. m_fInputAsGMT (fInputAsGMT)
  27. {
  28. Init();
  29. }
  30. CLogOnHoursDlg::CLogOnHoursDlg (CWnd* pParent, bool fInputAsGMT) :
  31. CScheduleBaseDlg (CLogOnHoursDlg::IDD, false, pParent),
  32. m_fInputAsGMT (fInputAsGMT)
  33. {
  34. Init();
  35. }
  36. void CLogOnHoursDlg::Init()
  37. {
  38. //{{AFX_DATA_INIT (CLogOnHoursDlg)
  39. // NOTE: the ClassWizard will add member initialization here
  40. //}}AFX_DATA_INIT
  41. m_prgbData21 = NULL;
  42. }
  43. void CLogOnHoursDlg::DoDataExchange (CDataExchange* pDX)
  44. {
  45. CScheduleBaseDlg::DoDataExchange (pDX);
  46. //{{AFX_DATA_MAP(CLogOnHoursDlg)
  47. DDX_Control ( pDX, IDC_BUTTON_ADD_HOURS, m_buttonAdd );
  48. DDX_Control ( pDX, IDC_BUTTON_REMOVE_HOURS, m_buttonRemove );
  49. // NOTE: the ClassWizard will add DDX and DDV calls here
  50. //}}AFX_DATA_MAP
  51. }
  52. BEGIN_MESSAGE_MAP (CLogOnHoursDlg, CScheduleBaseDlg)
  53. //{{AFX_MSG_MAP(CLogOnHoursDlg)
  54. ON_BN_CLICKED (IDC_BUTTON_ADD_HOURS, OnButtonAddHours)
  55. ON_BN_CLICKED (IDC_BUTTON_REMOVE_HOURS, OnButtonRemoveHours)
  56. //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP ()
  58. BOOL CLogOnHoursDlg::OnInitDialog ()
  59. {
  60. CScheduleBaseDlg::OnInitDialog ();
  61. // Set up the "on" legend
  62. m_legendOn.Init ( this, IDC_STATIC_LEGEND_ON, &m_schedulematrix, 100);
  63. // Set up the "off" legend
  64. m_legendOff.Init ( this, IDC_STATIC_LEGEND_OFF, &m_schedulematrix, 0);
  65. if ( GetFlags () & SCHED_FLAG_READ_ONLY )
  66. {
  67. // Disable the add and remove buttons
  68. m_buttonAdd.EnableWindow (FALSE);
  69. m_buttonRemove.EnableWindow (FALSE);
  70. }
  71. return TRUE;
  72. } // CLogOnHoursDlg::OnInitDialog ()
  73. void CLogOnHoursDlg::OnOK ()
  74. {
  75. if (m_prgbData21 != NULL)
  76. {
  77. BYTE rgbDataT[CB_LOGON_ARRAY_LENGTH];
  78. GetByteArray (OUT rgbDataT, sizeof (rgbDataT));
  79. ShrinkByteArrayToBitArray (IN rgbDataT, sizeof (rgbDataT), OUT m_prgbData21, CB_SCHEDULE_ARRAY_LENGTH);
  80. // Convert back the hours to GMT time.
  81. if ( m_fInputAsGMT )
  82. ConvertLogonHoursToGMT (INOUT m_prgbData21, m_bAddDaylightBias);
  83. }
  84. CScheduleBaseDlg::OnOK ();
  85. }
  86. void CLogOnHoursDlg::UpdateButtons ()
  87. {
  88. UINT nHour = 0;
  89. UINT nDay = 0;
  90. UINT nNumHours = 0;
  91. UINT nNumDays = 0;
  92. m_schedulematrix.GetSel (OUT nHour, OUT nDay, OUT nNumHours, OUT nNumDays);
  93. bool fAllSet = false; // fAllSet && fAllClear will be changed to true only if something is selected
  94. bool fAllClear = false;
  95. if (nNumHours > 0)
  96. {
  97. fAllSet = true;
  98. fAllClear = true;
  99. for (UINT iDayOfWeek = nDay; iDayOfWeek < nDay+nNumDays; iDayOfWeek++)
  100. {
  101. for (UINT iHour = nHour; iHour < nHour+nNumHours; iHour++)
  102. {
  103. if (100 == m_schedulematrix.GetPercentage (iHour, iDayOfWeek))
  104. {
  105. fAllClear = false;
  106. }
  107. else
  108. {
  109. fAllSet = false;
  110. }
  111. } // for
  112. } // for
  113. }
  114. ASSERT (! (fAllSet && fAllClear)); // these can't both be true!
  115. m_buttonAdd.SetCheck (fAllSet ? 1 : 0);
  116. m_buttonRemove.SetCheck (fAllClear ? 1 : 0);
  117. }
  118. void CLogOnHoursDlg::OnButtonAddHours ()
  119. {
  120. UINT nHour = 0;
  121. UINT nDay = 0;
  122. UINT nNumHours = 0;
  123. UINT nNumDays = 0;
  124. m_schedulematrix.GetSel (OUT nHour, OUT nDay, OUT nNumHours, OUT nNumDays);
  125. if (nNumHours <= 0)
  126. return; // Nothing selected
  127. m_schedulematrix.SetPercentage (100, nHour, nDay, nNumHours, nNumDays);
  128. UpdateButtons ();
  129. }
  130. void CLogOnHoursDlg::OnButtonRemoveHours ()
  131. {
  132. UINT nHour = 0;
  133. UINT nDay = 0;
  134. UINT nNumHours = 0;
  135. UINT nNumDays = 0;
  136. m_schedulematrix.GetSel (OUT nHour, OUT nDay, OUT nNumHours, OUT nNumDays);
  137. if (nNumHours <= 0)
  138. return; // Nothing selected
  139. m_schedulematrix.SetPercentage (0, nHour, nDay, nNumHours, nNumDays);
  140. UpdateButtons ();
  141. }
  142. /////////////////////////////////////////////////////////////////////
  143. // SetLogonBitArray ()
  144. //
  145. // Set the bit array representing the logon hours for a user.
  146. //
  147. // The parameter rgbData is used as both an input and output parameter.
  148. //
  149. void CLogOnHoursDlg::SetLogonBitArray (INOUT BYTE rgbData[CB_SCHEDULE_ARRAY_LENGTH])
  150. {
  151. // Catch development errors early. The code that dereferences m_prgbData21
  152. // is robust so the check here is not necessary for release build.
  153. ASSERT (rgbData);
  154. m_prgbData21 = rgbData;
  155. } // SetLogonBitArray ()
  156. /////////////////////////////////////////////////////////////////////
  157. // ShrinkByteArrayToBitArray ()
  158. //
  159. // Convert an array of bytes into an array of bits. Each
  160. // byte will be stored as one bit in the array of bits.
  161. //
  162. // INTERFACE NOTES
  163. // The first bit of the array of bits is the boolean
  164. // value of the first byte of the array of bytes.
  165. //
  166. HRESULT
  167. ShrinkByteArrayToBitArray (
  168. const BYTE rgbDataIn[], // IN: Array of bytes
  169. int cbDataIn, // IN: Number of bytes in rgbDataIn
  170. BYTE rgbDataOut[], // OUT: Array of bits (stored as an array of bytes)
  171. int cbDataOut) // IN: Number of bytes in output buffer
  172. {
  173. // NOTICE-NTRAID#NTBUG9-547746-2002/03/12-artm Need to check not NULL in release code.
  174. // Both rbgDataIn and rgbDataOut need to be checked for NULL before using.
  175. // In array must be 8 times the size of out array
  176. ASSERT (cbDataIn == cbDataOut*8);
  177. if ( cbDataIn != cbDataOut*8 )
  178. return E_INVALIDARG;
  179. ASSERT (rgbDataIn);
  180. ASSERT (rgbDataOut);
  181. if ( !rgbDataIn || !rgbDataOut )
  182. return E_POINTER;
  183. // NOTICE-NTRAID#NTBUG9-547718 Size of rgbDataOut verified above.
  184. //
  185. // Use cbDataOut to check that rgbDataOut is CB_SCHEDULE_ARRAY_LENGTH in size. If not
  186. // use a return value to indicate failure.
  187. const BYTE * pbSrc = rgbDataIn;
  188. BYTE * pbDst = rgbDataOut;
  189. while (cbDataIn > 0 && cbDataOut > 0)
  190. {
  191. BYTE b = 0;
  192. for (int i = 8; i > 0; i--)
  193. {
  194. // NOTICE-NTRAID#NTBUG-547746-2002/02/18-artm Assert should be supplemented with release code.
  195. //
  196. // The logic in this assert is part of the algorithm, and should be in
  197. // the release code as part of the for loop's conditional check.
  198. // We are guaranteed to never get here as long as the check above for
  199. // "cbDataIn != cbDataOut*8" is in the code. Thus, the below ASSERT() should
  200. // never fire.
  201. ASSERT (cbDataIn > 0);
  202. cbDataIn--;
  203. b >>= 1;
  204. if ( *pbSrc )
  205. b |= 0x80; // bit 0 is on the right, as in: 7 6 5 4 3 2 1 0
  206. pbSrc++;
  207. }
  208. *pbDst++ = b;
  209. cbDataOut--;
  210. } // while
  211. return S_OK;
  212. } // ShrinkByteArrayToBitArray ()
  213. /////////////////////////////////////////////////////////////////////
  214. HRESULT
  215. ExpandBitArrayToByteArray (
  216. const BYTE rgbDataIn[], // IN: Array of bits (stored as an array of bytes)
  217. int cbDataIn, // IN: Number of bytes in rgbDataIn
  218. BYTE rgbDataOut[], // OUT: Array of bytes
  219. int cbDataOut) // IN: Number of bytes in output buffer
  220. {
  221. // NOTICE-NTRAID#NTBUG9-547746-2002/03/12-artm Need to check not NULL in release code.
  222. // Both rbgDataIn and rgbDataOut need to be checked for NULL before using.
  223. // Out array must be 8 times the size of in array
  224. ASSERT (cbDataOut == cbDataIn*8);
  225. if ( cbDataOut != cbDataIn*8 )
  226. return E_INVALIDARG;
  227. ASSERT (rgbDataIn);
  228. ASSERT (rgbDataOut);
  229. if ( !rgbDataIn || !rgbDataOut )
  230. return E_POINTER;
  231. // NOTICE-NTRAID#NTBUG9-547718 Size of rgbDataOut verified.
  232. //
  233. // Use cbDataOut to check that rgbDataOut is large enough.
  234. const BYTE * pbSrc = rgbDataIn;
  235. BYTE * pbDst = rgbDataOut;
  236. while (cbDataIn > 0)
  237. {
  238. // NOTICE-NTRAID#NTBUG-547746-2002/02/18-artm Assert should be supplemented with release code.
  239. //
  240. // The logic in this assert is part of the algorithm, and should be in
  241. // the release code as part of the for loop's conditional check.
  242. ASSERT (cbDataIn > 0);
  243. cbDataIn--;
  244. BYTE b = *pbSrc;
  245. pbSrc++;
  246. for (int i = 8; i > 0 && cbDataOut > 0; i--, cbDataOut--)
  247. {
  248. *pbDst = (BYTE) ((b & 0x01) ? 1 : 0); // bit 0 is on the right of each bit
  249. pbDst++;
  250. b >>= 1;
  251. }
  252. } // while
  253. return S_OK;
  254. } // ExpandBitArrayToByteArray ()
  255. /////////////////////////////////////////////////////////////////////
  256. // Converts the logon hours from local time to GMT.
  257. void
  258. ConvertLogonHoursToGMT (
  259. INOUT BYTE rgbData[CB_SCHEDULE_ARRAY_LENGTH],
  260. IN bool bAddDaylightBias)
  261. {
  262. VERIFY ( ::NetpRotateLogonHours (rgbData, CB_SCHEDULE_ARRAY_LENGTH * 8, TRUE, bAddDaylightBias) );
  263. }
  264. /////////////////////////////////////////////////////////////////////
  265. // Converts the logon hours from GMT to local time.
  266. void
  267. ConvertLogonHoursFromGMT (
  268. INOUT BYTE rgbData[CB_SCHEDULE_ARRAY_LENGTH],
  269. IN bool bAddDaylightBias)
  270. {
  271. VERIFY ( ::NetpRotateLogonHours (rgbData, CB_SCHEDULE_ARRAY_LENGTH * 8, FALSE, bAddDaylightBias) );
  272. }
  273. /////////////////////////////////////////////////////////////////////
  274. // LogonScheduleDialog ()
  275. //
  276. // Invoke a dialog to set/modify a schedule, for example
  277. // -- the logon hours for a particular user
  278. // -- the schedule for a connection
  279. //
  280. // RETURNS
  281. // Return S_OK if the user clicked on the OK button.
  282. // Return S_FALSE if the user clicked on the Cancel button.
  283. // Return E_OUTOFMEMORY if there is not enough memory.
  284. /// Return E_UNEXPECTED if an expected error occured (eg: bad parameter)
  285. //
  286. // INTERFACE NOTES
  287. // Each bit in the array represents one hour. As a result, the
  288. // expected length of the array should be (24 / 8) * 7 = 21 bytes.
  289. // For convenience, the first day of the week is Sunday and
  290. // the last day is Saturday.
  291. // Consequently, the first bit of the array represents the schedule
  292. // for Sunday during period 12 AM to 1 AM.
  293. // - If *pprgbData is NULL, then the routine will allocate
  294. // an array of 21 bytes using LocalAlloc (). The caller
  295. // is responsible of releasing the memory using LocalFree ().
  296. // - If *pprgbData is not NULL, the routine re-use the array as its
  297. // output parameter.
  298. //
  299. // HISTORY
  300. // 17-Jul-97 t-danm Creation.
  301. // 16-Sep-97 jonn Changed to UiScheduleDialog
  302. //
  303. HRESULT
  304. LogonScheduleDialog(
  305. HWND hwndParent, // IN: Parent's window handle
  306. BYTE ** pprgbData, // INOUT: Pointer to pointer to array of 21 bytes (one bit per hour)
  307. LPCTSTR pszTitle) // IN: Dialog title
  308. {
  309. return LogonScheduleDialogEx (hwndParent, pprgbData, pszTitle, SCHED_FLAG_INPUT_GMT);
  310. }
  311. HRESULT
  312. LogonScheduleDialogEx(
  313. HWND hwndParent, // IN: Parent's window handle
  314. BYTE ** pprgbData, // INOUT: Pointer to pointer to array of 21 bytes (one bit per hour)
  315. LPCTSTR pszTitle, // IN: Dialog title
  316. DWORD dwFlags)
  317. {
  318. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  319. // All of these asserts are backed up by validation checks.
  320. ASSERT(::IsWindow(hwndParent));
  321. ASSERT(pprgbData != NULL);
  322. // NOTICE-NTRAID#NTBUG9-547381-2002/02/18-artm pszTitle okay to be NULL
  323. // dlg.SetTitle() robustly handles NULL case
  324. ASSERT(pszTitle != NULL);
  325. ENDORSE(*pprgbData == NULL); // TRUE => Use default logon hours (7x24)
  326. if (*pprgbData == NULL)
  327. {
  328. BYTE * pargbData; // Pointer to allocated array of bytes
  329. pargbData = (BYTE *)LocalAlloc(0, CB_SCHEDULE_ARRAY_LENGTH); // Allocate 21 bytes
  330. if (pargbData == NULL)
  331. return E_OUTOFMEMORY;
  332. // Set the logon hours to be valid 24 hours a day and 7 days a week.
  333. memset(OUT pargbData, -1, CB_SCHEDULE_ARRAY_LENGTH);
  334. *pprgbData = pargbData;
  335. }
  336. // If hwndParent passed in, create a CWnd to pass as the parent window
  337. CWnd* pWnd = 0;
  338. if ( ::IsWindow (hwndParent) )
  339. {
  340. pWnd = new CWnd;
  341. if ( pWnd )
  342. {
  343. pWnd->Attach (hwndParent);
  344. }
  345. else
  346. return E_OUTOFMEMORY;
  347. }
  348. HRESULT hr = S_OK;
  349. bool fInputAsGMT = true;
  350. if ( dwFlags & SCHED_FLAG_INPUT_LOCAL_TIME )
  351. fInputAsGMT = false;
  352. CLogOnHoursDlg dlg (pWnd, fInputAsGMT);
  353. dlg.SetTitle (pszTitle);
  354. dlg.SetLogonBitArray(INOUT *pprgbData);
  355. dlg.SetFlags (dwFlags);
  356. if (IDOK != dlg.DoModal())
  357. hr = S_FALSE;
  358. if ( pWnd )
  359. {
  360. pWnd->Detach ();
  361. delete pWnd;
  362. }
  363. return hr;
  364. } // LogonScheduleDialog()
  365. HRESULT
  366. DialinHoursDialog (
  367. HWND hwndParent, // IN: Parent's window handle
  368. BYTE ** pprgbData, // INOUT: Pointer to pointer to array of 21 bytes (one bit per hour)
  369. LPCTSTR pszTitle) // IN: Dialog title
  370. {
  371. return DialinHoursDialogEx (hwndParent, pprgbData, pszTitle, SCHED_FLAG_INPUT_GMT);
  372. }
  373. HRESULT
  374. DialinHoursDialogEx (
  375. HWND hwndParent, // IN: Parent's window handle
  376. BYTE ** pprgbData, // INOUT: Pointer to pointer to array of 21 bytes (one bit per hour)
  377. LPCTSTR pszTitle, // IN: Dialog title
  378. DWORD dwFlags)
  379. {
  380. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  381. // These asserts are backed up by validation in release code.
  382. ASSERT(::IsWindow(hwndParent));
  383. ASSERT(pprgbData != NULL);
  384. // NOTICE-NTRAID#NTBUG9-547381-2002/02/18-artm pszTitle okay to be NULL
  385. // dlg.SetTitle() robustly handles NULL.
  386. ASSERT(pszTitle != NULL);
  387. ENDORSE(*pprgbData == NULL); // TRUE => Use default logon hours (7x24)
  388. if (*pprgbData == NULL)
  389. {
  390. BYTE * pargbData; // Pointer to allocated array of bytes
  391. pargbData = (BYTE *)LocalAlloc(0, CB_SCHEDULE_ARRAY_LENGTH); // Allocate 21 bytes
  392. if (pargbData == NULL)
  393. return E_OUTOFMEMORY;
  394. // Set the logon hours to be valid 24 hours a day and 7 days a week.
  395. memset(OUT pargbData, -1, CB_SCHEDULE_ARRAY_LENGTH);
  396. *pprgbData = pargbData;
  397. }
  398. // If hwndParent passed in, create a CWnd to pass as the parent window
  399. CWnd* pWnd = 0;
  400. if ( ::IsWindow (hwndParent) )
  401. {
  402. pWnd = new CWnd;
  403. if ( pWnd )
  404. {
  405. pWnd->Attach (hwndParent);
  406. }
  407. else
  408. return E_OUTOFMEMORY;
  409. }
  410. HRESULT hr = S_OK;
  411. bool fInputAsGMT = true;
  412. if ( dwFlags & SCHED_FLAG_INPUT_LOCAL_TIME )
  413. fInputAsGMT = false;
  414. CDialinHours dlg (pWnd, fInputAsGMT);
  415. dlg.SetTitle (pszTitle);
  416. dlg.SetLogonBitArray(INOUT *pprgbData);
  417. dlg.SetFlags (dwFlags);
  418. if (IDOK != dlg.DoModal())
  419. hr = S_FALSE;
  420. if ( pWnd )
  421. {
  422. pWnd->Detach ();
  423. delete pWnd;
  424. }
  425. return hr;
  426. } // DialinHoursDialog()
  427. void CLogOnHoursDlg::InitMatrix()
  428. {
  429. if ( m_prgbData21 )
  430. {
  431. BYTE rgbitData[CB_SCHEDULE_ARRAY_LENGTH]; // Array of logonhours bits
  432. // Make a copy of the logon hours (in case the user click on cancel button)
  433. memcpy (OUT rgbitData, IN m_prgbData21, sizeof (rgbitData));
  434. // Convert the hours from GMT to local hours.
  435. if ( m_fInputAsGMT )
  436. ConvertLogonHoursFromGMT (INOUT rgbitData, m_bAddDaylightBias);
  437. BYTE rgbDataT[CB_LOGON_ARRAY_LENGTH];
  438. if ( SUCCEEDED (ExpandBitArrayToByteArray (IN rgbitData,
  439. CB_SCHEDULE_ARRAY_LENGTH, OUT rgbDataT, sizeof (rgbDataT))) )
  440. {
  441. m_cbArray = sizeof (rgbDataT);
  442. }
  443. // Initialize the matrix
  444. InitMatrix2 (IN rgbDataT);
  445. }
  446. }
  447. UINT CLogOnHoursDlg::GetPercentageToSet(const BYTE bData)
  448. {
  449. ASSERT (TRUE == bData || FALSE == bData);
  450. return (TRUE == bData) ? 100 : 0;
  451. }
  452. BYTE CLogOnHoursDlg::GetMatrixPercentage(UINT nHour, UINT nDay)
  453. {
  454. return (BYTE) ((100 == m_schedulematrix.GetPercentage (nHour, nDay)) ?
  455. TRUE : FALSE);
  456. }
  457. UINT CLogOnHoursDlg::GetExpectedArrayLength()
  458. {
  459. return CB_LOGON_ARRAY_LENGTH;
  460. }
  461. // Called when WM_TIMECHANGE is received
  462. void CLogOnHoursDlg::TimeChange()
  463. {
  464. m_buttonAdd.EnableWindow (FALSE);
  465. m_buttonRemove.EnableWindow (FALSE);
  466. }
  467. /////////////////////////////////////////////////////////////////////////////
  468. // CDialinHours dialog
  469. CDialinHours::CDialinHours(CWnd* pParent, bool fInputAsGMT)
  470. : CLogOnHoursDlg(CDialinHours::IDD, pParent, fInputAsGMT, false)
  471. {
  472. //{{AFX_DATA_INIT(CDialinHours)
  473. // NOTE: the ClassWizard will add member initialization here
  474. //}}AFX_DATA_INIT
  475. }
  476. BEGIN_MESSAGE_MAP(CDialinHours, CLogOnHoursDlg)
  477. //{{AFX_MSG_MAP(CDialinHours)
  478. // NOTE: the ClassWizard will add message map macros here
  479. //}}AFX_MSG_MAP
  480. END_MESSAGE_MAP()
  481. /////////////////////////////////////////////////////////////////////////////
  482. // CDialinHours message handlers
  483. /////////////////////////////////////////////////////////////////////////////
  484. // CDirSyncScheduleDlg dialog
  485. CDirSyncScheduleDlg::CDirSyncScheduleDlg(CWnd* pParent /*=NULL*/)
  486. : CLogOnHoursDlg(CDirSyncScheduleDlg::IDD, pParent, true, false)
  487. {
  488. //{{AFX_DATA_INIT(CDirSyncScheduleDlg)
  489. // NOTE: the ClassWizard will add member initialization here
  490. //}}AFX_DATA_INIT
  491. }
  492. void CDirSyncScheduleDlg::DoDataExchange(CDataExchange* pDX)
  493. {
  494. CLogOnHoursDlg::DoDataExchange(pDX);
  495. //{{AFX_DATA_MAP(CDirSyncScheduleDlg)
  496. // NOTE: the ClassWizard will add DDX and DDV calls here
  497. //}}AFX_DATA_MAP
  498. }
  499. BEGIN_MESSAGE_MAP(CDirSyncScheduleDlg, CLogOnHoursDlg)
  500. //{{AFX_MSG_MAP(CDirSyncScheduleDlg)
  501. // NOTE: the ClassWizard will add message map macros here
  502. //}}AFX_MSG_MAP
  503. END_MESSAGE_MAP()
  504. BOOL CDirSyncScheduleDlg::OnInitDialog()
  505. {
  506. CLogOnHoursDlg::OnInitDialog();
  507. m_schedulematrix.SetSel (0, 0, 1, 1);
  508. return TRUE;
  509. }
  510. /////////////////////////////////////////////////////////////////////////////
  511. // CDirSyncScheduleDlg message handlers
  512. //
  513. // The data is passed in in GMT
  514. //
  515. HRESULT
  516. DirSyncScheduleDialog(
  517. HWND hwndParent, // IN: Parent's window handle
  518. BYTE ** pprgbData, // INOUT: Pointer to pointer to array of 21 bytes (one bit per hour)
  519. LPCTSTR pszTitle) // IN: Dialog title
  520. {
  521. return DirSyncScheduleDialogEx (hwndParent, pprgbData, pszTitle, 0);
  522. } // DirSyncScheduleDialog()
  523. HRESULT
  524. DirSyncScheduleDialogEx(
  525. HWND hwndParent, // IN: Parent's window handle
  526. BYTE ** pprgbData, // INOUT: Pointer to pointer to array of 21 bytes (one bit per hour)
  527. LPCTSTR pszTitle, // IN: Dialog title
  528. DWORD dwFlags) // IN: Option flags
  529. {
  530. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  531. // These asserts are backed up by validation code in release.
  532. ASSERT(::IsWindow(hwndParent));
  533. ASSERT(pprgbData != NULL);
  534. // NOTICE-NTRAID#NTBUG9-547381-2002/02/18-artm pszTitle okay to be NULL
  535. // dlg.SetTitle() robustly handles NULL.
  536. ASSERT(pszTitle != NULL);
  537. ENDORSE(*pprgbData == NULL); // TRUE => Use default logon hours (7x24)
  538. if (*pprgbData == NULL)
  539. {
  540. BYTE * pargbData; // Pointer to allocated array of bytes
  541. pargbData = (BYTE *)LocalAlloc(0, CB_SCHEDULE_ARRAY_LENGTH); // Allocate 21 bytes
  542. if (pargbData == NULL)
  543. return E_OUTOFMEMORY;
  544. // Set the logon hours to be valid 24 hours a day and 7 days a week.
  545. memset(OUT pargbData, -1, CB_SCHEDULE_ARRAY_LENGTH);
  546. *pprgbData = pargbData;
  547. }
  548. // If hwndParent passed in, create a CWnd to pass as the parent window
  549. CWnd* pWnd = 0;
  550. if ( ::IsWindow (hwndParent) )
  551. {
  552. pWnd = new CWnd;
  553. if ( pWnd )
  554. {
  555. pWnd->Attach (hwndParent);
  556. }
  557. else
  558. return E_OUTOFMEMORY;
  559. }
  560. HRESULT hr = S_OK;
  561. CDirSyncScheduleDlg dlg (pWnd);
  562. dlg.SetTitle (pszTitle);
  563. dlg.SetLogonBitArray(INOUT *pprgbData);
  564. dlg.SetFlags (dwFlags);
  565. if (IDOK != dlg.DoModal())
  566. hr = S_FALSE;
  567. if ( pWnd )
  568. {
  569. pWnd->Detach ();
  570. delete pWnd;
  571. }
  572. return hr;
  573. } // DirSyncScheduleDialogEx()