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.

637 lines
16 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. pgconst.cpp
  7. Implementation of CPgConstraints -- property page to edit
  8. profile attributes related to constraints
  9. FILE HISTORY:
  10. */
  11. // PgConst.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "resource.h"
  15. #include "PgConst.h"
  16. //#include "log_gmt.h"
  17. #include "hlptable.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CPgConstraintsMerge property page
  25. IMPLEMENT_DYNCREATE(CPgConstraintsMerge, CManagedPage)
  26. CPgConstraintsMerge::CPgConstraintsMerge(CRASProfileMerge* profile)
  27. : CManagedPage(CPgConstraintsMerge::IDD),
  28. m_pProfile(profile)
  29. {
  30. //{{AFX_DATA_INIT(CPgConstraintsMerge)
  31. m_bCallNumber = FALSE;
  32. m_bRestrictedToPeriod = FALSE;
  33. m_dwMaxSession = m_pProfile->m_dwSessionTimeout / 60; // sec --> min
  34. m_dwIdle = m_pProfile->m_dwIdleTimeout / 60;
  35. m_strCalledNumber = _T("");
  36. m_bIdle = FALSE;
  37. m_bSessionLen = FALSE;
  38. m_bPortTypes = FALSE;
  39. //}}AFX_DATA_INIT
  40. m_bSessionLen = ((m_pProfile->m_dwAttributeFlags & PABF_msRADIUSSessionTimeout) != 0);
  41. if(!m_bSessionLen) m_dwMaxSession = 1;
  42. m_bIdle = ((m_pProfile->m_dwAttributeFlags & PABF_msRADIUSIdleTimeout) != 0);
  43. if(!m_bIdle) m_dwIdle = 1;
  44. m_bCallNumber = ((m_pProfile->m_dwAttributeFlags & PABF_msNPCalledStationId) != 0);
  45. if(m_bCallNumber)
  46. m_strCalledNumber = *(m_pProfile->m_strArrayCalledStationId[(INT_PTR)0]);
  47. m_bRestrictedToPeriod = ((m_pProfile->m_dwAttributeFlags & PABF_msNPTimeOfDay) != 0);
  48. m_bPortTypes = ((m_pProfile->m_dwAttributeFlags & PABF_msNPAllowedPortTypes) != 0);
  49. m_bInited = false;
  50. SetHelpTable(g_aHelpIDs_IDD_CONSTRAINTS_MERGE);
  51. m_pBox = NULL;
  52. }
  53. CPgConstraintsMerge::~CPgConstraintsMerge()
  54. {
  55. delete m_pBox;
  56. }
  57. void CPgConstraintsMerge::DoDataExchange(CDataExchange* pDX)
  58. {
  59. ASSERT(m_pProfile);
  60. CPropertyPage::DoDataExchange(pDX);
  61. //{{AFX_DATA_MAP(CPgConstraintsMerge)
  62. DDX_Control(pDX, IDC_CHECK_PORTTYPES, m_CheckPortTypes);
  63. DDX_Control(pDX, IDC_LIST_PORTTYPES, m_listPortTypes);
  64. DDX_Control(pDX, IDC_CHECKSESSIONLEN, m_CheckSessionLen);
  65. DDX_Control(pDX, IDC_CHECKIDLE, m_CheckIdle);
  66. DDX_Control(pDX, IDC_BUTTONEDITTIMEOFDAY, m_ButtonEditTimeOfDay);
  67. DDX_Control(pDX, IDC_LISTTIMEOFDAY, m_ListTimeOfDay);
  68. DDX_Control(pDX, IDC_SPINMAXSESSION, m_SpinMaxSession);
  69. DDX_Control(pDX, IDC_SPINIDLETIME, m_SpinIdleTime);
  70. DDX_Control(pDX, IDC_EDITMAXSESSION, m_EditMaxSession);
  71. DDX_Control(pDX, IDC_EDITIDLETIME, m_EditIdleTime);
  72. DDX_Check(pDX, IDC_CHECKCALLNUMBER, m_bCallNumber);
  73. DDX_Check(pDX, IDC_CHECKRESTRICTPERIOD, m_bRestrictedToPeriod);
  74. DDX_Check(pDX, IDC_CHECKIDLE, m_bIdle);
  75. DDX_Check(pDX, IDC_CHECKSESSIONLEN, m_bSessionLen);
  76. DDX_Check(pDX, IDC_CHECK_PORTTYPES, m_bPortTypes);
  77. DDX_Text(pDX, IDC_EDITMAXSESSION, m_dwMaxSession);
  78. if(m_bSessionLen)
  79. {
  80. DDV_MinMaxUInt(pDX, m_dwMaxSession, 1, MAX_SESSIONTIME);
  81. }
  82. DDX_Text(pDX, IDC_EDITIDLETIME, m_dwIdle);
  83. if(m_bIdle)
  84. {
  85. DDV_MinMaxUInt(pDX, m_dwIdle, 1, MAX_IDLETIMEOUT);
  86. }
  87. DDX_Text(pDX, IDC_EDITCALLNUMBER, m_strCalledNumber);
  88. //}}AFX_DATA_MAP
  89. }
  90. BEGIN_MESSAGE_MAP(CPgConstraintsMerge, CPropertyPage)
  91. //{{AFX_MSG_MAP(CPgConstraintsMerge)
  92. ON_EN_CHANGE(IDC_EDITMAXSESSION, OnChangeEditmaxsession)
  93. ON_EN_CHANGE(IDC_EDITIDLETIME, OnChangeEditidletime)
  94. ON_BN_CLICKED(IDC_CHECKCALLNUMBER, OnCheckcallnumber)
  95. ON_BN_CLICKED(IDC_CHECKRESTRICTPERIOD, OnCheckrestrictperiod)
  96. ON_WM_HELPINFO()
  97. ON_BN_CLICKED(IDC_BUTTONEDITTIMEOFDAY, OnButtonedittimeofday)
  98. ON_EN_CHANGE(IDC_EDITCALLNUMBER, OnChangeEditcallnumber)
  99. ON_WM_CONTEXTMENU()
  100. ON_BN_CLICKED(IDC_CHECKIDLE, OnCheckidle)
  101. ON_BN_CLICKED(IDC_CHECKSESSIONLEN, OnChecksessionlen)
  102. ON_BN_CLICKED(IDC_CHECK_PORTTYPES, OnCheckPorttypes)
  103. ON_NOTIFY(LVXN_SETCHECK, IDC_LIST_PORTTYPES, OnItemclickListPorttypes)
  104. //}}AFX_MSG_MAP
  105. END_MESSAGE_MAP()
  106. /////////////////////////////////////////////////////////////////////////////
  107. // CPgConstraintsMerge message handlers
  108. BOOL CPgConstraintsMerge::OnInitDialog()
  109. {
  110. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  111. ModifyStyleEx(0, WS_EX_CONTEXTHELP);
  112. CPropertyPage::OnInitDialog();
  113. EnableSettings();
  114. // set spin range
  115. m_SpinIdleTime.SetRange(1, MAX_IDLETIMEOUT);
  116. m_SpinMaxSession.SetRange(1, MAX_SESSIONTIME);
  117. // list box
  118. // parse the time of day strings to hours bit map
  119. StrArrayToHourMap(m_pProfile->m_strArrayTimeOfDay, m_TimeOfDayHoursMap);
  120. // convert value from string to this map
  121. HourMapToStrArray(m_TimeOfDayHoursMap, m_strArrayTimeOfDayDisplay, TRUE /* localized */);
  122. try{
  123. m_pBox = new CStrBox<CListBox>(this, IDC_LISTTIMEOFDAY, m_strArrayTimeOfDayDisplay);
  124. m_pBox->Fill();
  125. }
  126. catch(CMemoryException&)
  127. {
  128. delete m_pBox;
  129. m_pBox = NULL;
  130. MyMessageBox(IDS_OUTOFMEMORY);
  131. };
  132. // Port Types, list box
  133. CStrArray portTypeNames;
  134. CDWArray portTypeIds;
  135. HRESULT hr = m_pProfile->GetPortTypeList(portTypeNames, portTypeIds);
  136. if FAILED(hr)
  137. ReportError(hr, IDS_ERR_PORTTYPELIST, NULL);
  138. else
  139. {
  140. ListView_SetExtendedListViewStyle(m_listPortTypes.GetSafeHwnd(),
  141. LVS_EX_FULLROWSELECT);
  142. // Initialize checkbox handling in the list control
  143. m_listPortTypes.InstallChecks();
  144. RECT rect;
  145. m_listPortTypes.GetClientRect(&rect);
  146. m_listPortTypes.InsertColumn(0, NULL, LVCFMT_LEFT, (rect.right - rect.left - 24));
  147. int cRow = 0;
  148. CString* pStr;
  149. BOOL bAllowedType = FALSE;
  150. for(int i = 0; i < portTypeNames.GetSize(); i++)
  151. {
  152. pStr = portTypeNames.GetAt(i);
  153. cRow = m_listPortTypes.InsertItem(0, *pStr);
  154. m_listPortTypes.SetItemData(cRow, portTypeIds.GetAt(i));
  155. // check if the current row is an allowed type
  156. bAllowedType = (-1 != m_pProfile->m_dwArrayAllowedPortTypes.Find(portTypeIds.GetAt(i)));
  157. m_listPortTypes.SetCheck(cRow, bAllowedType);
  158. }
  159. m_listPortTypes.SetItemState(0, LVIS_SELECTED ,LVIF_STATE | LVIS_SELECTED);
  160. }
  161. m_listPortTypes.EnableWindow(m_CheckPortTypes.GetCheck());
  162. m_bInited = true;
  163. return TRUE; // return TRUE unless you set the focus to a control
  164. // EXCEPTION: OCX Property Pages should return FALSE
  165. }
  166. void CPgConstraintsMerge::OnChangeEditmaxsession()
  167. {
  168. // TODO: If this is a RICHEDIT control, the control will not
  169. // send this notification unless you override the CPropertyPage::OnInitDialog()
  170. // function to send the EM_SETEVENTMASK message to the control
  171. // with the ENM_CHANGE flag ORed into the lParam mask.
  172. if(m_bInited) SetModified();
  173. }
  174. void CPgConstraintsMerge::OnChangeEditidletime()
  175. {
  176. // TODO: If this is a RICHEDIT control, the control will not
  177. // send this notification unless you override the CPropertyPage::OnInitDialog()
  178. // function to send the EM_SETEVENTMASK message to the control
  179. // with the ENM_CHANGE flag ORed into the lParam mask.
  180. if(m_bInited) SetModified();
  181. }
  182. BOOL CPgConstraintsMerge::OnApply()
  183. {
  184. if (!GetModified()) return TRUE;
  185. // get the allowed port(media) type
  186. m_pProfile->m_dwArrayAllowedPortTypes.DeleteAll();
  187. int count = m_listPortTypes.GetItemCount();
  188. if(m_CheckPortTypes.GetCheck())
  189. {
  190. BOOL bEmpty = TRUE;
  191. while(count-- > 0)
  192. {
  193. if(m_listPortTypes.GetCheck(count))
  194. {
  195. m_pProfile->m_dwArrayAllowedPortTypes.Add(m_listPortTypes.GetItemData(count));
  196. bEmpty = FALSE;
  197. }
  198. }
  199. if(bEmpty)
  200. {
  201. GotoDlgCtrl(&m_CheckPortTypes);
  202. MyMessageBox(IDS_ERR_NEEDPORTTYPE);
  203. return FALSE;
  204. }
  205. m_pProfile->m_dwAttributeFlags |= PABF_msNPAllowedPortTypes;
  206. }
  207. else
  208. m_pProfile->m_dwAttributeFlags &= (~PABF_msNPAllowedPortTypes);
  209. if(!m_bIdle)
  210. {
  211. m_pProfile->m_dwAttributeFlags &= (~PABF_msRADIUSIdleTimeout);
  212. m_pProfile->m_dwIdleTimeout = 0;
  213. }
  214. else
  215. {
  216. m_pProfile->m_dwAttributeFlags |= PABF_msRADIUSIdleTimeout;
  217. m_pProfile->m_dwIdleTimeout = m_dwIdle * 60;
  218. }
  219. if(!m_bSessionLen)
  220. {
  221. m_pProfile->m_dwAttributeFlags &= (~PABF_msRADIUSSessionTimeout);
  222. m_pProfile->m_dwSessionTimeout = 0;
  223. }
  224. else
  225. {
  226. m_pProfile->m_dwAttributeFlags |= PABF_msRADIUSSessionTimeout;
  227. m_pProfile->m_dwSessionTimeout = m_dwMaxSession * 60;
  228. }
  229. // Regure call to this number
  230. if(m_bCallNumber && m_strCalledNumber.GetLength())
  231. {
  232. m_pProfile->m_dwAttributeFlags |= PABF_msNPCalledStationId;
  233. if(m_pProfile->m_strArrayCalledStationId.GetSize())
  234. *(m_pProfile->m_strArrayCalledStationId[(INT_PTR)0]) = m_strCalledNumber;
  235. else
  236. m_pProfile->m_strArrayCalledStationId.Add(new CString(m_strCalledNumber));
  237. }
  238. else
  239. {
  240. m_pProfile->m_dwAttributeFlags &= (~PABF_msNPCalledStationId);
  241. m_pProfile->m_strArrayCalledStationId.DeleteAll();
  242. }
  243. if(!m_bRestrictedToPeriod)
  244. {
  245. m_pProfile->m_dwAttributeFlags &= (~PABF_msNPTimeOfDay);
  246. m_pProfile->m_strArrayTimeOfDay.DeleteAll();
  247. }
  248. else
  249. {
  250. if(m_pProfile->m_strArrayTimeOfDay.GetSize() == 0)
  251. {
  252. GotoDlgCtrl(&m_ButtonEditTimeOfDay);
  253. MyMessageBox(IDS_ERR_NEEDTIMEOFDAY);
  254. return FALSE;
  255. }
  256. m_pProfile->m_dwAttributeFlags |= PABF_msNPTimeOfDay;
  257. }
  258. return CManagedPage::OnApply();
  259. }
  260. void CPgConstraintsMerge::OnCheckcallnumber()
  261. {
  262. EnableCalledStation(((CButton*)GetDlgItem(IDC_CHECKCALLNUMBER))->GetCheck());
  263. if(m_bInited) SetModified();
  264. }
  265. void CPgConstraintsMerge::OnCheckrestrictperiod()
  266. {
  267. // TODO: Add your control notification handler code here
  268. if(((CButton*)GetDlgItem(IDC_CHECKRESTRICTPERIOD))->GetCheck())
  269. {
  270. EnableTimeOfDay(TRUE);
  271. if(!m_pProfile->m_strArrayTimeOfDay.GetSize())
  272. {
  273. // there is nothing defined as constraint
  274. BYTE* pMap = &(m_TimeOfDayHoursMap[0]);
  275. memset(m_TimeOfDayHoursMap, 0xff, sizeof(m_TimeOfDayHoursMap));
  276. HourMapToStrArray(pMap, m_pProfile->m_strArrayTimeOfDay, FALSE);
  277. // redraw the list box
  278. HourMapToStrArray(pMap, m_strArrayTimeOfDayDisplay, TRUE /* if localized */);
  279. m_pBox->Fill();
  280. }
  281. }
  282. else
  283. EnableTimeOfDay(FALSE);
  284. if(m_bInited) SetModified();
  285. }
  286. void CPgConstraintsMerge::EnableSettings()
  287. {
  288. EnableSessionSettings(m_bSessionLen);
  289. EnableIdleSettings(m_bIdle);
  290. EnableCalledStation(m_bCallNumber);
  291. EnableTimeOfDay(m_bRestrictedToPeriod);
  292. }
  293. void CPgConstraintsMerge::EnableCalledStation(BOOL b)
  294. {
  295. GetDlgItem(IDC_EDITCALLNUMBER)->EnableWindow(b);
  296. }
  297. void CPgConstraintsMerge::EnableMediaSelection(BOOL b)
  298. {
  299. }
  300. void CPgConstraintsMerge::EnableTimeOfDay(BOOL bEnable)
  301. {
  302. m_ListTimeOfDay.EnableWindow(bEnable);
  303. m_ButtonEditTimeOfDay.EnableWindow(bEnable);
  304. }
  305. //================================================
  306. // When to edit time of day information
  307. void CPgConstraintsMerge::OnButtonedittimeofday()
  308. {
  309. CString dlgTitle;
  310. dlgTitle.LoadString(IDS_DIALINHOURS);
  311. BYTE* pMap = &(m_TimeOfDayHoursMap[0]);
  312. // parse the time of day strings to hours bit map
  313. if(S_OK == OpenTimeOfDayDlgEx(m_hWnd, (BYTE**)&pMap, dlgTitle, SCHED_FLAG_INPUT_LOCAL_TIME))
  314. {
  315. HourMapToStrArray(pMap, m_pProfile->m_strArrayTimeOfDay, FALSE);
  316. // redraw the list box
  317. HourMapToStrArray(pMap, m_strArrayTimeOfDayDisplay, TRUE);
  318. m_pBox->Fill();
  319. SetModified();
  320. }
  321. }
  322. void CPgConstraintsMerge::EnableSessionSettings(BOOL bEnable)
  323. {
  324. m_EditMaxSession.EnableWindow(bEnable);
  325. m_SpinMaxSession.EnableWindow(bEnable);
  326. }
  327. void CPgConstraintsMerge::EnableIdleSettings(BOOL bEnable)
  328. {
  329. m_EditIdleTime.EnableWindow(bEnable);
  330. m_SpinIdleTime.EnableWindow(bEnable);
  331. }
  332. void CPgConstraintsMerge::OnChangeEditcallnumber()
  333. {
  334. if(m_bInited) SetModified();
  335. }
  336. void CPgConstraintsMerge::OnContextMenu(CWnd* pWnd, CPoint point)
  337. {
  338. CManagedPage::OnContextMenu(pWnd, point);
  339. }
  340. BOOL CPgConstraintsMerge::OnHelpInfo(HELPINFO* pHelpInfo)
  341. {
  342. return CManagedPage::OnHelpInfo(pHelpInfo);
  343. }
  344. void CPgConstraintsMerge::OnCheckidle()
  345. {
  346. SetModified();
  347. EnableIdleSettings(m_CheckIdle.GetCheck());
  348. }
  349. void CPgConstraintsMerge::OnChecksessionlen()
  350. {
  351. SetModified();
  352. EnableSessionSettings(m_CheckSessionLen.GetCheck());
  353. }
  354. BOOL CPgConstraintsMerge::OnKillActive()
  355. {
  356. CButton* pButton = (CButton*)GetDlgItem(IDC_CHECKCALLNUMBER);
  357. CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDITCALLNUMBER);
  358. int count;
  359. int errID;
  360. ASSERT(pButton); // if the IDC is not correct, the return will be NULL
  361. ASSERT(pEdit);
  362. if(pButton->GetCheck() && !pEdit->LineLength())
  363. {
  364. GotoDlgCtrl( pEdit );
  365. MyMessageBox(IDS_ERR_NEEDPHONENUMBER);
  366. return FALSE;
  367. }
  368. count = m_listPortTypes.GetItemCount();
  369. if(m_CheckPortTypes.GetCheck())
  370. {
  371. BOOL bEmpty = TRUE;
  372. while(count-- > 0)
  373. {
  374. if(m_listPortTypes.GetCheck(count))
  375. {
  376. bEmpty = FALSE;
  377. }
  378. }
  379. if(bEmpty)
  380. {
  381. GotoDlgCtrl(&m_CheckPortTypes);
  382. MyMessageBox(IDS_ERR_NEEDPORTTYPE);
  383. return FALSE;
  384. }
  385. }
  386. return CPropertyPage::OnKillActive();
  387. MyMessageBox(IDS_ERR_DATAENTRY);
  388. return FALSE;
  389. }
  390. void CPgConstraintsMerge::OnCheckPorttypes()
  391. {
  392. // TODO: Add your control notification handler code here
  393. m_listPortTypes.EnableWindow(m_CheckPortTypes.GetCheck());
  394. m_listPortTypes.SetFocus();
  395. m_listPortTypes.SetItemState(0, LVIS_FOCUSED | LVIS_SELECTED ,LVIF_STATE);
  396. SetModified();
  397. }
  398. void CPgConstraintsMerge::OnItemclickListPorttypes(NMHDR* pNMHDR, LRESULT* pResult)
  399. {
  400. HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
  401. // TODO: Add your control notification handler code here
  402. *pResult = 0;
  403. if(m_bInited)
  404. SetModified();
  405. }
  406. // hour map ( one bit for an hour of a week )
  407. static BYTE bitSetting[8] = { 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1};
  408. static LPCTSTR daysOfWeekinDS[7] = {RAS_DOW_SUN, RAS_DOW_MON, RAS_DOW_TUE, RAS_DOW_WED,
  409. RAS_DOW_THU, RAS_DOW_FRI, RAS_DOW_SAT};
  410. static UINT daysOfWeekIDS[7] = {IDS_SUNDAY, IDS_MONDAY, IDS_TUESDAY, IDS_WEDNESDAY, IDS_THURSDAY,
  411. IDS_FRIDAY, IDS_SATURDAY};
  412. static UINT daysOfWeekLCType[7] = {LOCALE_SABBREVDAYNAME7, LOCALE_SABBREVDAYNAME1 , LOCALE_SABBREVDAYNAME2 , LOCALE_SABBREVDAYNAME3 , LOCALE_SABBREVDAYNAME4 ,
  413. LOCALE_SABBREVDAYNAME5 , LOCALE_SABBREVDAYNAME6 };
  414. //+---------------------------------------------------------------------------
  415. //====================================================
  416. // convert an Array of Strings to Hour Map
  417. // Strings in following format: 0 1:00-12:00 15:00-17:00
  418. // hour map: a bit for an hour, 7 * 24 hours = 7 * 3 bytes
  419. void StrArrayToHourMap(CStrArray& array, BYTE* map)
  420. {
  421. CStrParser Parser;
  422. int sh, sm, eh, em = 0; // start hour, (min), end hour (min)
  423. int day;
  424. BYTE* pHourMap;
  425. int i;
  426. int count = array.GetSize();
  427. memset(map, 0, sizeof(BYTE) * 21);
  428. while(count--)
  429. {
  430. Parser.SetStr(*(array[(INT_PTR)count]));
  431. Parser.SkipBlank();
  432. day = Parser.DayOfWeek();
  433. Parser.SkipBlank();
  434. if(day == -1) continue;
  435. pHourMap = map + sizeof(BYTE) * 3 * day;
  436. while(-1 != (sh = Parser.GetUINT())) // sh:sm-eh:em
  437. {
  438. Parser.GotoAfter(_T(':'));
  439. if(-1 == (sm = Parser.GetUINT())) // min
  440. break;
  441. Parser.GotoAfter(_T('-'));
  442. if(-1 == (eh = Parser.GetUINT())) // hour
  443. break;
  444. if(-1 == (sm = Parser.GetUINT())) // min
  445. break;
  446. sm %= 60; sh %= 24; em %= 60; eh %= 25; // since we have end hour of 24:00
  447. for(i = sh; i < eh; i++)
  448. {
  449. *(pHourMap + i / 8) |= bitSetting[i % 8];
  450. }
  451. }
  452. }
  453. }
  454. //=====================================================
  455. // convert value from map to strings
  456. void HourMapToStrArray(BYTE* map, CStrArray& array, BOOL bLocalized)
  457. {
  458. int sh, eh; // start hour, (min), end hour (min)
  459. BYTE* pHourMap;
  460. int i, j;
  461. CString* pStr;
  462. CString tmpStr;
  463. TCHAR tempName[MAX_PATH];
  464. // update the profile table
  465. pHourMap = map;
  466. array.DeleteAll();
  467. for( i = 0; i < 7; i++) // for each day
  468. {
  469. // if any value for this day
  470. if(*pHourMap || *(pHourMap + 1) || *(pHourMap + 2))
  471. {
  472. // the string for this day
  473. try{
  474. pStr = NULL;
  475. if(bLocalized) // for display
  476. {
  477. int nLen = GetLocaleInfo(LOCALE_USER_DEFAULT, daysOfWeekLCType[i], tempName, MAX_PATH - 1);
  478. pStr = new CString;
  479. if(nLen == 0) // FAILED
  480. {
  481. pStr->LoadString(daysOfWeekIDS[i]);
  482. }
  483. else
  484. {
  485. *pStr = tempName;
  486. }
  487. }
  488. else // when write to DS
  489. pStr = new CString(daysOfWeekinDS[i]);
  490. sh = -1; eh = -1; // not start yet
  491. for(j = 0; j < 24; j++) // for every hour
  492. {
  493. int k = j / 8;
  494. int m = j % 8;
  495. if(*(pHourMap + k) & bitSetting[m]) // this hour is on
  496. {
  497. if(sh == -1) sh = j; // set start hour is empty
  498. eh = j; // extend end hour
  499. }
  500. else // this is not on
  501. {
  502. if(sh != -1) // some hours need to write out
  503. {
  504. tmpStr.Format(_T(" %02d:00-%02d:00"), sh, eh + 1);
  505. *pStr += tmpStr;
  506. sh = -1; eh = -1;
  507. }
  508. }
  509. }
  510. if(sh != -1)
  511. {
  512. tmpStr.Format(_T(" %02d:00-%02d:00"), sh, eh + 1);
  513. *pStr += tmpStr;
  514. sh = -1; eh = -1;
  515. }
  516. TRACE(*pStr);
  517. array.Add(pStr);
  518. }
  519. catch(CMemoryException&)
  520. {
  521. AfxMessageBox(IDS_OUTOFMEMORY);
  522. delete pStr;
  523. array.DeleteAll();
  524. return;
  525. }
  526. }
  527. pHourMap += 3;
  528. }
  529. }