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.

308 lines
8.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: benefits.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "BenSvr.h"
  12. #include "Benefits.h"
  13. #include "RootNode.h"
  14. CBenefits::CBenefits()
  15. {
  16. m_pNode = new CRootNode;
  17. _ASSERTE(m_pNode != NULL);
  18. }
  19. //
  20. // Standard destructor. Simply deletes
  21. // the root node.
  22. //
  23. CBenefits::~CBenefits()
  24. {
  25. delete m_pNode;
  26. m_pNode = NULL;
  27. }
  28. HRESULT CBenefits::Initialize(LPUNKNOWN pUnknown)
  29. {
  30. HRESULT hr = IComponentDataImpl<CBenefits, CBenefitsComponent >::Initialize(pUnknown);
  31. if (FAILED(hr))
  32. return hr;
  33. CComPtr<IImageList> spImageList;
  34. if (m_spConsole->QueryScopeImageList(&spImageList) != S_OK)
  35. {
  36. ATLTRACE(_T("IConsole::QueryScopeImageList failed\n"));
  37. return E_UNEXPECTED;
  38. }
  39. // Load bitmaps associated with the scope pane
  40. // and add them to the image list
  41. // Loads the default bitmaps generated by the wizard
  42. // Change as required
  43. HBITMAP hBitmap16 = LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_BENEFITS_16));
  44. if (hBitmap16 == NULL)
  45. return S_OK;
  46. HBITMAP hBitmap32 = LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_BENEFITS_32));
  47. if (hBitmap32 == NULL)
  48. return S_OK;
  49. if (spImageList->ImageListSetStrip((long*)hBitmap16,
  50. (long*)hBitmap32, 0, RGB(0, 128, 128)) != S_OK)
  51. {
  52. ATLTRACE(_T("IImageList::ImageListSetStrip failed\n"));
  53. return E_UNEXPECTED;
  54. }
  55. //
  56. // This is called to create the unique sub-nodes.
  57. //
  58. ( (CRootNode*) m_pNode )->InitializeSubNodes();
  59. return S_OK;
  60. }
  61. //
  62. // This is overridden to handle update notifications from
  63. // the property pages.
  64. //
  65. HRESULT CBenefits::Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, long arg, long param)
  66. {
  67. HRESULT hr = E_NOTIMPL;
  68. if ( lpDataObject != NULL )
  69. {
  70. return IComponentDataImpl<CBenefits,CBenefitsComponent>::Notify( lpDataObject, event, arg, param );
  71. }
  72. else
  73. {
  74. //
  75. // There are many events which are sent to Notify with
  76. // the dataobject == NULL. Make sure that the correct one is
  77. // being dealt with.
  78. //
  79. switch( event )
  80. {
  81. case MMCN_PROPERTY_CHANGE:
  82. //
  83. // Send the notification to our root node for further processing.
  84. //
  85. ( (CRootNode*) m_pNode )->OnPropertyChange( m_spConsole );
  86. //
  87. // Since we've received an update notification, we'll cause the console
  88. // to be refreshed. This should handle the updates.
  89. //
  90. hr = m_spConsole->UpdateAllViews( NULL, NULL, NULL );
  91. break;
  92. }
  93. }
  94. return( hr );
  95. }
  96. //
  97. // Call the root node's implementation.
  98. //
  99. STDMETHODIMP CBenefits::IsDirty()
  100. {
  101. return( ( (CRootNode*) m_pNode )->IsDirty() );
  102. }
  103. //
  104. // Call the root node's implementation.
  105. //
  106. STDMETHODIMP CBenefits::Load(LPSTREAM pStm)
  107. {
  108. return( ( (CRootNode*) m_pNode )->Load( pStm ) );
  109. }
  110. //
  111. // Call the root node's implementation.
  112. //
  113. STDMETHODIMP CBenefits::Save(LPSTREAM pStm, BOOL fClearDirty)
  114. {
  115. return( ( (CRootNode*) m_pNode )->Save( pStm, fClearDirty ) );
  116. }
  117. //
  118. // Call the root node's implementation.
  119. //
  120. STDMETHODIMP CBenefits::GetSizeMax(ULARGE_INTEGER FAR* pcbSize )
  121. {
  122. return( ( (CRootNode*) m_pNode )->GetSizeMax( pcbSize ) );
  123. }
  124. //
  125. // This function copies the data from the given employee and populates
  126. // the appropriate controls within the page.
  127. //
  128. LRESULT CEmployeeNamePage::OnInitDialog( UINT uiMsg, WPARAM wParam, LPARAM lParam, BOOL& fHandled )
  129. {
  130. UNUSED_ALWAYS( uiMsg );
  131. UNUSED_ALWAYS( wParam );
  132. UNUSED_ALWAYS( lParam );
  133. UNUSED_ALWAYS( fHandled );
  134. USES_CONVERSION;
  135. _ASSERTE( m_pEmployee != NULL );
  136. SetDlgItemText( IDC_EDIT_LASTNAME, W2T( m_pEmployee->m_szLastName ) );
  137. SetDlgItemText( IDC_EDIT_FIRSTNAME, W2T( m_pEmployee->m_szFirstName ) );
  138. SetDlgItemText( IDC_EDIT_SOCIALSECURITY, W2T( m_pEmployee->m_szSocialSecurity ) );
  139. SetDlgItemText( IDC_EDIT_MOTHERNAME, W2T( m_pEmployee->m_szMotherMaiden ) );
  140. return( TRUE );
  141. }
  142. //
  143. // Handle the storage of any new values to the employee.
  144. //
  145. BOOL CEmployeeNamePage::OnWizardFinish()
  146. {
  147. USES_CONVERSION;
  148. BOOL fValid = TRUE;
  149. TCHAR szBuf[ 256 ];
  150. //
  151. // Get the values from the appropriate edit controls.
  152. // For demo purposes, always assume success unless the last name
  153. // and first are bad.
  154. //
  155. GetDlgItemText( IDC_EDIT_LASTNAME, szBuf, sizeof( szBuf ) );
  156. wcscpy( m_pEmployee->m_szLastName, T2W( szBuf ) );
  157. GetDlgItemText( IDC_EDIT_FIRSTNAME, szBuf, sizeof( szBuf ) );
  158. wcscpy( m_pEmployee->m_szFirstName, T2W( szBuf ) );
  159. GetDlgItemText( IDC_EDIT_SOCIALSECURITY, szBuf, sizeof( szBuf ) );
  160. wcscpy( m_pEmployee->m_szSocialSecurity, T2W( szBuf ) );
  161. GetDlgItemText( IDC_EDIT_MOTHERNAME, szBuf, sizeof( szBuf ) );
  162. wcscpy( m_pEmployee->m_szMotherMaiden, T2W( szBuf ) );
  163. //
  164. // Check for validity of first name and last name.
  165. //
  166. if ( wcslen( m_pEmployee->m_szLastName ) == 0 || wcslen( m_pEmployee->m_szFirstName ) == 0 ||
  167. m_pEmployee->m_szLastName[ 0 ] == ' ' || m_pEmployee->m_szFirstName[ 0 ] == ' ' )
  168. {
  169. //
  170. // Inform the user of the error.
  171. //
  172. MessageBox( _T( "Must enter valid first and last name." ) );
  173. fValid = FALSE;
  174. }
  175. else
  176. {
  177. //
  178. // Data is valid. As a result, post a notification to the snap-in
  179. // that the employee contents have changes. This demonstration does
  180. // not use any sort of hinting, so NULL can be safely pass in as
  181. // the nofication's arguement.
  182. //
  183. PropertyChangeNotify( NULL );
  184. }
  185. return( fValid );
  186. }
  187. //
  188. // This is overridden to modify the UI depending on whether
  189. // we're in start-up mode or not.
  190. //
  191. BOOL CEmployeeNamePage::OnSetActive()
  192. {
  193. if ( m_fStartup )
  194. {
  195. //
  196. // Must use post message during the setactive message.
  197. //
  198. CWindow( GetParent() ).PostMessage( PSM_SETWIZBUTTONS, 0, PSWIZB_NEXT );
  199. }
  200. return TRUE;
  201. }
  202. //
  203. // This function copies the data from the given employee and populates
  204. // the appropriate controls within the page.
  205. //
  206. LRESULT CEmployeeAddressPage::OnInitDialog( UINT uiMsg, WPARAM wParam, LPARAM lParam, BOOL& fHandled )
  207. {
  208. UNUSED_ALWAYS( uiMsg );
  209. UNUSED_ALWAYS( wParam );
  210. UNUSED_ALWAYS( lParam );
  211. UNUSED_ALWAYS( fHandled );
  212. USES_CONVERSION;
  213. _ASSERTE( m_pEmployee != NULL );
  214. SetDlgItemText( IDC_EDIT_ADDRESSFIRST, W2T( m_pEmployee->m_szAddress1 ) );
  215. SetDlgItemText( IDC_EDIT_ADDRESSSECOND, W2T( m_pEmployee->m_szAddress2 ) );
  216. SetDlgItemText( IDC_EDIT_CITY, W2T( m_pEmployee->m_szCity ) );
  217. SetDlgItemText( IDC_EDIT_STATE, W2T( m_pEmployee->m_szState ) );
  218. SetDlgItemText( IDC_EDIT_ZIP, W2T( m_pEmployee->m_szZip ) );
  219. SetDlgItemText( IDC_EDIT_PHONE, W2T( m_pEmployee->m_szPhone ) );
  220. return( TRUE );
  221. }
  222. //
  223. // Handle the storage of any new values to the employee.
  224. //
  225. BOOL CEmployeeAddressPage::OnWizardFinish()
  226. {
  227. USES_CONVERSION;
  228. BOOL fValid = TRUE;
  229. TCHAR szBuf[ 256 ];
  230. //
  231. // Get the values from the appropriate edit controls.
  232. // For demo purposes, always assume success unless the last name
  233. // and first are bad.
  234. //
  235. GetDlgItemText( IDC_EDIT_ADDRESSFIRST, szBuf, sizeof( szBuf ) );
  236. wcscpy( m_pEmployee->m_szAddress1, T2W( szBuf ) );
  237. GetDlgItemText( IDC_EDIT_ADDRESSSECOND, szBuf, sizeof( szBuf ) );
  238. wcscpy( m_pEmployee->m_szAddress2, T2W( szBuf ) );
  239. GetDlgItemText( IDC_EDIT_CITY, szBuf, sizeof( szBuf ) );
  240. wcscpy( m_pEmployee->m_szCity, T2W( szBuf ) );
  241. GetDlgItemText( IDC_EDIT_STATE, szBuf, sizeof( szBuf ) );
  242. wcscpy( m_pEmployee->m_szState, T2W( szBuf ) );
  243. GetDlgItemText( IDC_EDIT_ZIP, szBuf, sizeof( szBuf ) );
  244. wcscpy( m_pEmployee->m_szZip, T2W( szBuf ) );
  245. GetDlgItemText( IDC_EDIT_PHONE, szBuf, sizeof( szBuf ) );
  246. wcscpy( m_pEmployee->m_szPhone, T2W( szBuf ) );
  247. //
  248. // Data is valid. As a result, post a notification to the snap-in
  249. // that the employee contents have changes. This demonstration does
  250. // not use any sort of hinting, so NULL can be safely pass in as
  251. // the nofication's arguement.
  252. //
  253. PropertyChangeNotify( NULL );
  254. return( fValid );
  255. }
  256. //
  257. // This is overridden to modify the UI depending on whether
  258. // we're in start-up mode or not.
  259. //
  260. BOOL CEmployeeAddressPage::OnSetActive()
  261. {
  262. if ( m_fStartup )
  263. {
  264. //
  265. // Must use post message during the setactive message.
  266. //
  267. CWindow( GetParent() ).PostMessage( PSM_SETWIZBUTTONS, 0, PSWIZB_BACK | PSWIZB_FINISH );
  268. }
  269. return TRUE;
  270. }