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.

198 lines
5.0 KiB

  1. // NKUsrInf.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "resource.h"
  5. #include "keyring.h"
  6. #include "NKChseCA.h"
  7. #include "NKUsrInf.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. // defines for value names in the registry - not to be localized
  14. #define SZ_EMAIL "email"
  15. #define SZ_PHONE "phone"
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CNKUserInfo property page
  18. IMPLEMENT_DYNCREATE(CNKUserInfo, CPropertyPage)
  19. CNKUserInfo::CNKUserInfo()
  20. : CNKPages(CNKUserInfo::IDD),
  21. fRenewingKey( FALSE )
  22. {
  23. //{{AFX_DATA_INIT(CNKUserInfo)
  24. m_nkui_sz_email = _T("");
  25. m_nkui_sz_phone = _T("");
  26. m_nkui_sz_name = _T("");
  27. //}}AFX_DATA_INIT
  28. }
  29. CNKUserInfo::~CNKUserInfo()
  30. {
  31. }
  32. void CNKUserInfo::DoDataExchange(CDataExchange* pDX)
  33. {
  34. CPropertyPage::DoDataExchange(pDX);
  35. //{{AFX_DATA_MAP(CNKUserInfo)
  36. DDX_Text(pDX, IDC_NKUI_EMAIL_ADDRESS, m_nkui_sz_email);
  37. DDV_MaxChars(pDX, m_nkui_sz_email, 128);
  38. DDX_Text(pDX, IDC_NKUI_PHONE_NUMBER, m_nkui_sz_phone);
  39. DDV_MaxChars(pDX, m_nkui_sz_phone, 80);
  40. DDX_Text(pDX, IDC_NKUI_USER_NAME, m_nkui_sz_name);
  41. DDV_MaxChars(pDX, m_nkui_sz_name, 128);
  42. //}}AFX_DATA_MAP
  43. }
  44. BEGIN_MESSAGE_MAP(CNKUserInfo, CPropertyPage)
  45. //{{AFX_MSG_MAP(CNKUserInfo)
  46. ON_EN_CHANGE(IDC_NKUI_EMAIL_ADDRESS, OnChangeNkuiEmailAddress)
  47. ON_EN_CHANGE(IDC_NKUI_PHONE_NUMBER, OnChangeNkuiPhoneNumber)
  48. ON_EN_CHANGE(IDC_NKUI_USER_NAME, OnChangeNkuiUserName)
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. #define SZ_USER_NAME "USER_NAME"
  52. #define SZ_USER_PHONE "USER_PHONE"
  53. #define SZ_USER_EMAIL "USER_EMAIL"
  54. //----------------------------------------------------------------
  55. void CNKUserInfo::OnFinish()
  56. {
  57. // store the user entries
  58. SetStoredString( m_nkui_sz_name, SZ_USER_NAME );
  59. SetStoredString( m_nkui_sz_phone, SZ_USER_PHONE );
  60. SetStoredString( m_nkui_sz_email, SZ_USER_EMAIL );
  61. }
  62. //----------------------------------------------------------------
  63. BOOL CNKUserInfo::OnInitDialog( )
  64. {
  65. // if the entries from last time are available, use them, otherwise just
  66. // use the system's user name as a default
  67. try
  68. {
  69. FGetStoredString( m_nkui_sz_name, SZ_USER_NAME );
  70. FGetStoredString( m_nkui_sz_phone, SZ_USER_PHONE );
  71. FGetStoredString( m_nkui_sz_email, SZ_USER_EMAIL );
  72. // if we didn't get the user name, use the default
  73. if ( m_nkui_sz_name.IsEmpty() )
  74. {
  75. LPTSTR pName = m_nkui_sz_name.GetBuffer( MAX_PATH+1 );
  76. DWORD cbName = MAX_PATH;
  77. GetUserName( pName, &cbName );
  78. m_nkui_sz_name.ReleaseBuffer();
  79. }
  80. }
  81. catch( CException e )
  82. {
  83. m_nkui_sz_name.Empty();
  84. }
  85. // call superclass
  86. CPropertyPage::OnInitDialog();
  87. // return 0 to say we set the default item
  88. // return 1 to just select the default default item
  89. return 1;
  90. }
  91. //----------------------------------------------------------------
  92. BOOL CNKUserInfo::OnSetActive()
  93. {
  94. ActivateButtons();
  95. return CPropertyPage::OnSetActive();
  96. }
  97. //----------------------------------------------------------------
  98. void CNKUserInfo::ActivateButtons()
  99. {
  100. DWORD flags = PSWIZB_BACK;
  101. BOOL fCanGoOn = TRUE;
  102. UpdateData(TRUE);
  103. //now make sure there is something in each of the required fields
  104. fCanGoOn &= !m_nkui_sz_name.IsEmpty();
  105. fCanGoOn &= !m_nkui_sz_email.IsEmpty();
  106. fCanGoOn &= !m_nkui_sz_phone.IsEmpty();
  107. // if we can go on, hilite the button
  108. if ( fCanGoOn )
  109. {
  110. if ( fRenewingKey )
  111. flags |= PSWIZB_FINISH;
  112. else
  113. flags |= PSWIZB_NEXT;
  114. }
  115. // update the property sheet buttons
  116. m_pPropSheet->SetWizardButtons( flags );
  117. }
  118. //----------------------------------------------------------------
  119. BOOL CNKUserInfo::OnWizardFinish()
  120. {
  121. /*
  122. // now load up the registry key
  123. CString szRegKeyName;
  124. szRegKeyName.LoadString( IDS_REG_USER_INFO );
  125. // and open the key
  126. HKEY hKey;
  127. DWORD dwdisposition;
  128. if ( RegCreateKeyEx(
  129. HKEY_CURRENT_USER, // handle of open key
  130. szRegKeyName, // address of name of subkey to open
  131. 0, // reserved
  132. NULL, // pClass
  133. REG_OPTION_NON_VOLATILE, // special options flag
  134. KEY_ALL_ACCESS, // desired security access
  135. NULL, // address of key security
  136. &hKey, // address of handle of open key
  137. &dwdisposition
  138. ) == ERROR_SUCCESS )
  139. {
  140. // store the email name for later use
  141. RegSetValueEx( hKey, SZ_EMAIL, 0, REG_SZ, (PUCHAR)(LPCTSTR)m_nkui_sz_email, m_nkui_sz_email.GetLength()+1 );
  142. RegSetValueEx( hKey, SZ_PHONE, 0, REG_SZ, (PUCHAR)(LPCTSTR)m_nkui_sz_phone, m_nkui_sz_phone.GetLength()+1 );
  143. // close the key
  144. RegCloseKey( hKey );
  145. }
  146. */
  147. // finish by calling the superclass
  148. return CPropertyPage::OnWizardFinish();
  149. }
  150. /////////////////////////////////////////////////////////////////////////////
  151. // CNKUserInfo message handlers
  152. //----------------------------------------------------------------
  153. void CNKUserInfo::OnChangeNkuiEmailAddress()
  154. {
  155. ActivateButtons();
  156. }
  157. //----------------------------------------------------------------
  158. void CNKUserInfo::OnChangeNkuiPhoneNumber()
  159. {
  160. ActivateButtons();
  161. }
  162. //----------------------------------------------------------------
  163. void CNKUserInfo::OnChangeNkuiUserName()
  164. {
  165. ActivateButtons();
  166. }
  167.