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.

330 lines
7.7 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. AccExp.cpp : implementation file
  5. CPropertyPage support for User mgmt wizard
  6. File History:
  7. JonY Apr-96 created
  8. --*/
  9. #include "stdafx.h"
  10. #include "speckle.h"
  11. #include "wizbased.h"
  12. #include "AccExp.h"
  13. #include <winreg.h>
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CAccExp property page
  20. IMPLEMENT_DYNCREATE(CAccExp, CWizBaseDlg)
  21. CAccExp::CAccExp() : CWizBaseDlg(CAccExp::IDD)
  22. {
  23. //{{AFX_DATA_INIT(CAccExp)
  24. m_sDayEdit = 0;
  25. m_sYearEdit = 0;
  26. m_sMonthEdit = 0;
  27. //}}AFX_DATA_INIT
  28. CTime t = CTime::GetCurrentTime();
  29. m_sDayEdit = t.GetDay();
  30. m_sMonthEdit = t.GetMonth();
  31. m_sYearEdit = t.GetYear() + 1;
  32. }
  33. CAccExp::~CAccExp()
  34. {
  35. }
  36. void CAccExp::DoDataExchange(CDataExchange* pDX)
  37. {
  38. CPropertyPage::DoDataExchange(pDX);
  39. //{{AFX_DATA_MAP(CAccExp)
  40. DDX_Control(pDX, IDC_STATIC2, m_cStatic2);
  41. DDX_Control(pDX, IDC_STATIC1, m_cStatic1);
  42. DDX_Control(pDX, IDC_DATE_SPIN, m_sbSpin);
  43. DDX_Text(pDX, IDC_MONTH_EDIT, m_csMonthEdit);
  44. DDX_Text(pDX, IDC_DAY_EDIT, m_csDayEdit);
  45. DDX_Text(pDX, IDC_YEAR_EDIT, m_csYearEdit);
  46. //}}AFX_DATA_MAP
  47. }
  48. BEGIN_MESSAGE_MAP(CAccExp, CWizBaseDlg)
  49. //{{AFX_MSG_MAP(CAccExp)
  50. ON_EN_SETFOCUS(IDC_DAY_EDIT, OnSetfocusDayEdit)
  51. ON_EN_SETFOCUS(IDC_MONTH_EDIT, OnSetfocusMonthEdit)
  52. ON_EN_SETFOCUS(IDC_YEAR_EDIT, OnSetfocusYearEdit)
  53. //}}AFX_MSG_MAP
  54. END_MESSAGE_MAP()
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CAccExp message handlers
  57. BOOL CAccExp::OnInitDialog()
  58. {
  59. CWizBaseDlg::OnInitDialog();
  60. GetDlgItem(IDC_DAY_EDIT)->EnableWindow(TRUE);
  61. GetDlgItem(IDC_MONTH_EDIT)->EnableWindow(TRUE);
  62. GetDlgItem(IDC_YEAR_EDIT)->EnableWindow(TRUE);
  63. GetDlgItem(IDC_DATE_SPIN)->EnableWindow(TRUE);
  64. // get date format from registry
  65. DWORD dwRet;
  66. HKEY hKey;
  67. DWORD cbProv = 0;
  68. TCHAR* lpProv = NULL;
  69. dwRet = RegOpenKey(HKEY_CURRENT_USER,
  70. TEXT("Control Panel\\International"), &hKey );
  71. TCHAR* lpSep;
  72. // date separator
  73. if ((dwRet = RegQueryValueEx( hKey, TEXT("sDate"), NULL, NULL, NULL, &cbProv )) == ERROR_SUCCESS)
  74. {
  75. lpSep = (TCHAR*)malloc(cbProv);
  76. if (lpSep == NULL)
  77. {
  78. AfxMessageBox(IDS_GENERIC_NO_HEAP, MB_ICONEXCLAMATION);
  79. ExitProcess(1);
  80. }
  81. dwRet = RegQueryValueEx( hKey, TEXT("sDate"), NULL, NULL, (LPBYTE) lpSep, &cbProv );
  82. }
  83. m_cStatic2.m_csDateSep = lpSep;
  84. // only use one char
  85. m_cStatic2.m_csDateSep = m_cStatic2.m_csDateSep.Left(1);
  86. m_cStatic1.m_csDateSep = m_cStatic2.m_csDateSep;
  87. // date order
  88. TCHAR* lpTemp;
  89. if ((dwRet = RegQueryValueEx( hKey, TEXT("sShortDate"), NULL, NULL, NULL, &cbProv )) == ERROR_SUCCESS)
  90. {
  91. lpTemp = (TCHAR*)malloc(cbProv);
  92. if (lpTemp == NULL)
  93. {
  94. AfxMessageBox(IDS_GENERIC_NO_HEAP, MB_ICONEXCLAMATION);
  95. ExitProcess(1);
  96. }
  97. dwRet = RegQueryValueEx( hKey, TEXT("sShortDate"), NULL, NULL, (LPBYTE) lpTemp, &cbProv );
  98. }
  99. // determine the order
  100. TCHAR* pTemp = _tcstok(lpTemp, lpSep);
  101. USHORT xPos = 170; // left most control
  102. USHORT yPos = 41;
  103. USHORT sCount = 0;
  104. while(pTemp != NULL)
  105. {
  106. CRect cr;
  107. if ((*pTemp == 'm') || (*pTemp == 'M'))
  108. {
  109. GetDlgItem(IDC_MONTH_EDIT)->SetWindowPos(0, xPos, yPos, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  110. GetDlgItem(IDC_MONTH_EDIT)->GetWindowRect(&cr);
  111. xPos += cr.Width();
  112. }
  113. else if ((*pTemp == 'd') || (*pTemp == 'D'))
  114. {
  115. GetDlgItem(IDC_DAY_EDIT)->SetWindowPos(0, xPos, yPos, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  116. GetDlgItem(IDC_DAY_EDIT)->GetWindowRect(&cr);
  117. xPos += cr.Width();
  118. }
  119. else if ((*pTemp == 'y') || (*pTemp == 'Y'))
  120. {
  121. GetDlgItem(IDC_YEAR_EDIT)->SetWindowPos(0, xPos, yPos, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  122. GetDlgItem(IDC_YEAR_EDIT)->GetWindowRect(&cr);
  123. xPos += cr.Width();
  124. }
  125. if (sCount == 0)
  126. {
  127. GetDlgItem(IDC_STATIC1)->SetWindowPos(0, xPos, yPos, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  128. GetDlgItem(IDC_STATIC1)->GetWindowRect(&cr);
  129. xPos += cr.Width();
  130. }
  131. if (sCount == 1)
  132. {
  133. GetDlgItem(IDC_STATIC2)->SetWindowPos(0, xPos, yPos, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  134. GetDlgItem(IDC_STATIC2)->GetWindowRect(&cr);
  135. xPos += cr.Width();
  136. }
  137. pTemp = _tcstok(NULL, lpSep);
  138. sCount++;
  139. }
  140. free(lpTemp);
  141. free(lpSep);
  142. RegCloseKey(hKey);
  143. // put the initial numeric values into the edit controls
  144. TCHAR pTemp2[4];
  145. wsprintf(pTemp2, L"%d", m_sDayEdit);
  146. m_csDayEdit = pTemp2;
  147. wsprintf(pTemp2, L"%d", m_sMonthEdit);
  148. m_csMonthEdit = pTemp2;
  149. wsprintf(pTemp2, L"%d", m_sYearEdit);
  150. m_csYearEdit = pTemp2;
  151. UpdateData(FALSE);
  152. return TRUE; // return TRUE unless you set the focus to a control
  153. // EXCEPTION: OCX Property Pages should return FALSE
  154. }
  155. void CAccExp::OnSetfocusDayEdit()
  156. {
  157. m_sbSpin.SetBuddy(GetDlgItem(IDC_DAY_EDIT));
  158. m_sbSpin.SetRange(1,31);
  159. }
  160. void CAccExp::OnSetfocusMonthEdit()
  161. {
  162. m_sbSpin.SetBuddy(GetDlgItem(IDC_MONTH_EDIT));
  163. m_sbSpin.SetRange(1,12);
  164. }
  165. void CAccExp::OnSetfocusYearEdit()
  166. {
  167. m_sbSpin.SetBuddy(GetDlgItem(IDC_YEAR_EDIT));
  168. m_sbSpin.SetRange(1996, 2030);
  169. }
  170. LRESULT CAccExp::OnWizardNext()
  171. {
  172. UpdateData(TRUE);
  173. // get the numberic values back out of the edit control(s)
  174. m_sDayEdit = _wtoi((LPCTSTR)m_csDayEdit);
  175. m_sMonthEdit = _wtoi((LPCTSTR)m_csMonthEdit);
  176. m_sYearEdit = _wtoi((LPCTSTR)m_csYearEdit);
  177. // check for valid values
  178. USHORT sDays[] = {31,28,31,30,31,30,31,31,30,31,30,31};
  179. // leap year?
  180. if (((m_sYearEdit - 1992) % 4) == 0) sDays[1] = 29;
  181. if ((m_sDayEdit > sDays[m_sMonthEdit - 1]) || (m_sDayEdit < 1))
  182. {
  183. AfxMessageBox(IDS_INVALID_DAY);
  184. GetDlgItem(IDC_DAY_EDIT)->SetFocus();
  185. return -1;
  186. }
  187. if ((m_sMonthEdit > 12) || (m_sMonthEdit < 1))
  188. {
  189. AfxMessageBox(IDS_INVALID_MONTH);
  190. GetDlgItem(IDC_MONTH_EDIT)->SetFocus();
  191. return -1;
  192. }
  193. if ((m_sYearEdit > 2030) || (m_sYearEdit < 1970))
  194. {
  195. AfxMessageBox(IDS_INVALID_YEAR);
  196. GetDlgItem(IDC_YEAR_EDIT)->SetFocus();
  197. return -1;
  198. }
  199. CTime t = CTime::GetCurrentTime();
  200. CTime tSet = CTime(m_sYearEdit, m_sMonthEdit, m_sDayEdit + 1, 23, 59, 59);
  201. if (tSet < t)
  202. {
  203. if (AfxMessageBox(IDS_ALREADY_EXPIRED, MB_YESNO) != IDYES) return -1;
  204. }
  205. // convert both values to GMT
  206. struct tm* GMTTime;
  207. GMTTime = tSet.GetGmtTm(NULL);
  208. CTime tGMTSet = CTime((GMTTime->tm_year + 1900),
  209. GMTTime->tm_mon + 1,
  210. GMTTime->tm_mday,
  211. 0, 0, 30, GMTTime->tm_isdst);
  212. CTime tStart = CTime(1970, 1, 1, 0, 0, 0);
  213. GMTTime = tStart.GetGmtTm(NULL);
  214. CTime tGMTStart = CTime((GMTTime->tm_year + 1900),
  215. GMTTime->tm_mon + 1,
  216. GMTTime->tm_mday,
  217. 0, 0, 0, GMTTime->tm_isdst);
  218. CTimeSpan ct = tGMTSet - tGMTStart;
  219. CSpeckleApp* pApp = (CSpeckleApp*)AfxGetApp();
  220. pApp->m_dwExpirationDate = ct.GetTotalSeconds();
  221. if (pApp->m_bHours) return IDD_HOURS_DLG;
  222. else if (pApp->m_bWorkstation) return IDD_LOGONTO_DLG;
  223. else if (pApp->m_bNW) return IDD_NWLOGON_DIALOG;
  224. else return IDD_FINISH;
  225. return CWizBaseDlg::OnWizardNext();
  226. }
  227. LRESULT CAccExp::OnWizardBack()
  228. {
  229. return IDD_RESTRICTIONS_DIALOG;
  230. }
  231. /////////////////////////////////////////////////////////////////////////////
  232. // CStaticDelim
  233. CStaticDelim::CStaticDelim()
  234. {
  235. m_pFont = new CFont;
  236. LOGFONT lf;
  237. memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
  238. lf.lfHeight = 15;
  239. _tcscpy(lf.lfFaceName, TEXT("Arial"));
  240. lf.lfWeight = 100;
  241. m_pFont->CreateFontIndirect(&lf); // Create the font.
  242. }
  243. CStaticDelim::~CStaticDelim()
  244. {
  245. delete m_pFont;
  246. }
  247. BEGIN_MESSAGE_MAP(CStaticDelim, CStatic)
  248. //{{AFX_MSG_MAP(CStaticDelim)
  249. ON_WM_PAINT()
  250. //}}AFX_MSG_MAP
  251. END_MESSAGE_MAP()
  252. /////////////////////////////////////////////////////////////////////////////
  253. // CStaticDelim message handlers
  254. void CStaticDelim::OnPaint()
  255. {
  256. CPaintDC dc(this); // device context for painting
  257. dc.SetBkColor(RGB(255, 255, 255));
  258. dc.SelectObject(m_pFont);
  259. dc.TextOut(0, 0, m_csDateSep);
  260. // Do not call CStatic::OnPaint() for painting messages
  261. }