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.

723 lines
23 KiB

  1. //////////////////////////////////////////////////////////////
  2. //
  3. // NewDomainDlg.cpp
  4. //
  5. // Implementation of the "Add Domain" dialog
  6. //
  7. //////////////////////////////////////////////////////////////
  8. #include "stdafx.h"
  9. #include "ServerProp.h"
  10. #include "ServerNode.h"
  11. #include <dsrole.h>
  12. #include <shlobj.h>
  13. #include <htmlhelp.h>
  14. #include "Pop3Auth.h"
  15. #include <AuthID.h>
  16. #include <Pop3RegKeys.h>
  17. LRESULT CServerGeneralPage::OnInitDialog( UINT mMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled )
  18. {
  19. if( !m_spServerConfig || !m_pParent ) return 0;
  20. HRESULT hr = S_OK;
  21. //IDC_NAME
  22. SetDlgItemText( IDC_NAME, m_pParent->m_bstrDisplayName );
  23. //IDC_PORT
  24. // Read in the current port, and set it as the default
  25. long lPort = 0L;
  26. TCHAR szPort[128] = {0};
  27. CComPtr<IP3Service> spService = NULL;
  28. hr = m_spServerConfig->get_Service( &spService );
  29. if( FAILED(hr) || !spService ) return 0;
  30. hr = spService->get_Port( &lPort );
  31. if( FAILED(hr) ) return 0;
  32. _sntprintf( szPort, 127, _T("%d"), lPort );
  33. SetDlgItemText( IDC_PORT, szPort );
  34. //IDC_DIRECTORY
  35. // Read in the current mail root directory, and set it as the default
  36. CComBSTR bstrRoot = _T("");
  37. hr = m_spServerConfig->get_MailRoot(&bstrRoot);
  38. if( FAILED(hr) ) return 0;
  39. SetDlgItemText(IDC_DIRECTORY, bstrRoot);
  40. //IDC_SERVER_CREATEUSER
  41. // Read in the current state of Creating Users for accounts
  42. CheckDlgButton(IDC_SERVER_CREATEUSER, (m_pParent->m_bCreateUser ? BST_CHECKED : BST_UNCHECKED) );
  43. //IDC_SERVER_SPA_REQ
  44. // Read in the current state of SPA Requirement for the server
  45. // Do our SPA Required Property
  46. DWORD dwValue = 0;
  47. RegQuerySPARequired( dwValue, m_pParent->m_bstrDisplayName );
  48. CheckDlgButton(IDC_SERVER_SPA_REQ, (dwValue ? BST_CHECKED : BST_UNCHECKED) );
  49. //IDC_AUTHENTICATION
  50. // Loop through all Authentication methods, and add them to our combo box
  51. CComBSTR bstrName;
  52. CComVariant var;
  53. CComPtr<IAuthMethods> spMethods = NULL;
  54. CComPtr<IAuthMethod> spAuth = NULL;
  55. long lCount = 0L;
  56. long lCurrent = 0L;
  57. int nIndex = 0;
  58. // Variables used to make sure the drop box of the combo is the right width
  59. HWND hwndCombo = GetDlgItem(IDC_AUTHENTICATION);
  60. if( !hwndCombo ) return 0;
  61. // Get the width information
  62. int iScrollBarWidth = GetSystemMetrics(SM_CXHSCROLL);
  63. long lOriginalMax = ::SendMessage(hwndCombo, CB_GETDROPPEDWIDTH, 0, 0) - iScrollBarWidth;
  64. long lMax = lOriginalMax;
  65. // Get the DC to the Combo box
  66. HDC hDC = ::GetWindowDC(hwndCombo);
  67. if( !hDC ) return 0;
  68. // Set the mapping mode
  69. SIZE size;
  70. int iMode = ::SetMapMode( hDC, MM_TEXT );
  71. // Select the font
  72. HGDIOBJ hObj = ::SelectObject( hDC, reinterpret_cast<HGDIOBJ>(::SendMessage((hwndCombo), WM_GETFONT, 0, 0 )));
  73. if( !hObj )
  74. {
  75. ::ReleaseDC(hwndCombo, hDC);
  76. return 0;
  77. }
  78. hr = m_spServerConfig->get_Authentication( &spMethods );
  79. if ( SUCCEEDED(hr) )
  80. {
  81. hr = spMethods->get_Count( &lCount );
  82. }
  83. if ( SUCCEEDED(hr) )
  84. {
  85. hr = spMethods->get_CurrentAuthMethod( &var );
  86. }
  87. if ( SUCCEEDED(hr) )
  88. {
  89. lCurrent = V_I4( &var );
  90. }
  91. else if ( HRESULT_FROM_WIN32(ERROR_DS_AUTH_METHOD_NOT_SUPPORTED) == hr )
  92. {
  93. lCurrent = -1;
  94. var = lCurrent; // Set variant type
  95. hr = S_OK;
  96. }
  97. for ( V_I4(&var) = 1, nIndex = 0; SUCCEEDED(hr) && ( V_I4(&var) <= lCount ); V_I4(&var)++, nIndex++ )
  98. {
  99. hr = spMethods->get_Item( var, &spAuth );
  100. if ( SUCCEEDED(hr) )
  101. {
  102. hr = spAuth->get_Name( &bstrName );
  103. }
  104. if ( SUCCEEDED(hr) )
  105. {
  106. if(::GetTextExtentPoint32(hDC, bstrName, bstrName.Length(), &size))
  107. {
  108. lMax = (size.cx > lMax ? size.cx : lMax);
  109. }
  110. ::SendMessage( hwndCombo, CB_INSERTSTRING, nIndex, (LPARAM)(LPCTSTR)bstrName );
  111. ::SendMessage( hwndCombo, CB_SETITEMDATA, nIndex, (LPARAM)V_I4(&var) );
  112. if( V_I4(&var) == lCurrent )
  113. {
  114. ::SendMessage(hwndCombo, CB_SETCURSEL, nIndex, 0);
  115. }
  116. }
  117. }
  118. // Finish making sure the combo drop box is the right width
  119. ::SetMapMode( hDC, iMode );
  120. ::SelectObject( hDC, hObj );
  121. const int ciExtraRoomEndOfLine = 10;
  122. if(lMax > lOriginalMax)
  123. {
  124. lMax += iScrollBarWidth + ciExtraRoomEndOfLine;
  125. ::SendMessage( hwndCombo, CB_SETDROPPEDWIDTH, lMax, 0 );
  126. }
  127. ::ReleaseDC(hwndCombo, hDC);
  128. ::DeleteObject(hObj);
  129. // If there are any domains, do not allow change of authentication
  130. long lDomains = 0L;
  131. CComPtr<IP3Domains> spDomains = NULL;
  132. hr = m_spServerConfig->get_Domains( &spDomains );
  133. if( SUCCEEDED(hr) )
  134. {
  135. hr = spDomains->get_Count( &lDomains );
  136. }
  137. Prefix_EnableWindow( m_hWnd, IDC_AUTHENTICATION, ((lDomains == 0) && SUCCEEDED(hr)) );
  138. // Check if the Auth is Hash Password and disable the checkbox.
  139. CComBSTR bstrID;
  140. if ( SUCCEEDED(hr) )
  141. {
  142. var.Clear();
  143. V_VT( &var ) = VT_I4;
  144. V_I4( &var ) = lCurrent;
  145. hr = spMethods->get_Item( var, &spAuth );
  146. }
  147. if( SUCCEEDED(hr) )
  148. {
  149. hr = spAuth->get_ID( &bstrID );
  150. }
  151. if( SUCCEEDED(hr) )
  152. {
  153. BOOL bHashPW = (_tcsicmp(bstrID, SZ_AUTH_ID_MD5_HASH) == 0);
  154. Prefix_EnableWindow( m_hWnd, IDC_SERVER_CREATEUSER, !bHashPW);
  155. Prefix_EnableWindow( m_hWnd, IDC_SERVER_SPA_REQ, !bHashPW);
  156. }
  157. //IDC_LOGGING
  158. // Some initialization of variables used for combo box sizing
  159. tstring strComboItem = _T("");
  160. hwndCombo = GetDlgItem(IDC_LOGGING);
  161. if( !hwndCombo ) return 0;
  162. iScrollBarWidth = GetSystemMetrics(SM_CXHSCROLL);
  163. lOriginalMax = ::SendMessage(hwndCombo, CB_GETDROPPEDWIDTH, 0, 0) - iScrollBarWidth;
  164. lMax = lOriginalMax;
  165. hDC = ::GetWindowDC(hwndCombo);
  166. if( !hDC ) return 0;
  167. iMode = ::SetMapMode( hDC, MM_TEXT );
  168. hObj = ::SelectObject( hDC, reinterpret_cast<HGDIOBJ>(::SendMessage((hwndCombo), WM_GETFONT, 0, 0 )));
  169. if( !hObj )
  170. {
  171. ::ReleaseDC( hwndCombo, hDC );
  172. return 0;
  173. }
  174. // Fill in the options for logging
  175. strComboItem = StrLoadString(IDS_SERVERPROP_LOG_0);
  176. if( ::GetTextExtentPoint32( hDC, strComboItem.c_str(), strComboItem.length(), &size ) )
  177. {
  178. lMax = (size.cx > lMax ? size.cx : lMax);
  179. }
  180. SendDlgItemMessage( IDC_LOGGING, CB_INSERTSTRING, 0, (LPARAM)(LPCTSTR)strComboItem.c_str() );
  181. strComboItem = StrLoadString(IDS_SERVERPROP_LOG_1);
  182. if( ::GetTextExtentPoint32( hDC, strComboItem.c_str(), strComboItem.length(), &size ) )
  183. {
  184. lMax = (size.cx > lMax ? size.cx : lMax);
  185. }
  186. SendDlgItemMessage( IDC_LOGGING, CB_INSERTSTRING, 1, (LPARAM)(LPCTSTR)strComboItem.c_str() );
  187. strComboItem = StrLoadString(IDS_SERVERPROP_LOG_2);
  188. if( ::GetTextExtentPoint32( hDC, strComboItem.c_str(), strComboItem.length(), &size ) )
  189. {
  190. lMax = (size.cx > lMax ? size.cx : lMax);
  191. }
  192. SendDlgItemMessage( IDC_LOGGING, CB_INSERTSTRING, 2, (LPARAM)(LPCTSTR)strComboItem.c_str() );
  193. strComboItem = StrLoadString(IDS_SERVERPROP_LOG_3);
  194. if( ::GetTextExtentPoint32( hDC, strComboItem.c_str(), strComboItem.length(), &size ) )
  195. {
  196. lMax = (size.cx > lMax ? size.cx : lMax);
  197. }
  198. SendDlgItemMessage( IDC_LOGGING, CB_INSERTSTRING, 3, (LPARAM)(LPCTSTR)strComboItem.c_str() );
  199. // Finish making sure the combo drop box is the right width
  200. ::SetMapMode( hDC, iMode );
  201. ::SelectObject( hDC, hObj );
  202. if(lMax > lOriginalMax)
  203. {
  204. lMax += iScrollBarWidth + ciExtraRoomEndOfLine;
  205. ::SendMessage( hwndCombo, CB_SETDROPPEDWIDTH, lMax, 0 );
  206. }
  207. ::ReleaseDC(hwndCombo, hDC);
  208. ::DeleteObject(hObj);
  209. // Then select the logging level
  210. long lLoggingLevel = 0L;
  211. hr = m_spServerConfig->get_LoggingLevel(&lLoggingLevel);
  212. if( FAILED(hr) ) return 0;
  213. ::SendMessage(GetDlgItem(IDC_LOGGING), CB_SETCURSEL, lLoggingLevel, 0);
  214. // Limit the text length of these controls
  215. SendDlgItemMessage( IDC_PORT, EM_LIMITTEXT, 5, 0 );
  216. SendDlgItemMessage( IDC_DIRECTORY, EM_LIMITTEXT, MAX_PATH, 0 );
  217. HWND hwndPort = GetDlgItem(IDC_PORT);
  218. if( hwndPort && ::IsWindow(hwndPort) )
  219. {
  220. m_wndPort.SubclassWindow( hwndPort );
  221. }
  222. //No service restart
  223. m_dwSvcRestart=0;
  224. return 0;
  225. }
  226. LRESULT CServerGeneralPage::OnChange( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled )
  227. {
  228. if( !m_spServerConfig ) return 0;
  229. SetModified(TRUE);
  230. if( wID == IDC_PORT || wID == IDC_SERVER_SPA_REQ )
  231. {
  232. m_dwSvcRestart |= RESTART_POP3SVC;
  233. }
  234. else if( wID == IDC_LOGGING || wID == IDC_DIRECTORY )
  235. {
  236. m_dwSvcRestart |= RESTART_SMTP;
  237. }
  238. else if( wID == IDC_AUTHENTICATION )
  239. {
  240. m_dwSvcRestart |= RESTART_POP3SVC;
  241. long lIndex = SendDlgItemMessage(IDC_AUTHENTICATION, CB_GETCURSEL, 0, 0);
  242. long lAuth = SendDlgItemMessage(IDC_AUTHENTICATION, CB_GETITEMDATA, lIndex, 0);
  243. HRESULT hr = S_OK;
  244. CComPtr<IAuthMethods> spMethods;
  245. CComPtr<IAuthMethod> spAuth;
  246. CComBSTR bstrID;
  247. CComVariant var;
  248. hr = m_spServerConfig->get_Authentication( &spMethods );
  249. if ( SUCCEEDED(hr) )
  250. {
  251. var.Clear();
  252. V_VT( &var ) = VT_I4;
  253. V_I4( &var ) = lAuth;
  254. hr = spMethods->get_Item( var, &spAuth );
  255. }
  256. if( SUCCEEDED(hr) )
  257. {
  258. hr = spAuth->get_ID( &bstrID );
  259. }
  260. if( SUCCEEDED(hr) )
  261. {
  262. // Disable the checkbox if necessary
  263. BOOL bHashPW = (_tcsicmp(bstrID, SZ_AUTH_ID_MD5_HASH) == 0);
  264. CheckDlgButton( IDC_SERVER_CREATEUSER, ( bHashPW ? BST_UNCHECKED : BST_CHECKED) );
  265. Prefix_EnableWindow( m_hWnd, IDC_SERVER_CREATEUSER, !bHashPW);
  266. CheckDlgButton( IDC_SERVER_SPA_REQ, BST_UNCHECKED );
  267. Prefix_EnableWindow( m_hWnd, IDC_SERVER_SPA_REQ, !bHashPW);
  268. }
  269. }
  270. return 0;
  271. }
  272. BOOL CServerGeneralPage::OnApply()
  273. {
  274. if( !m_spServerConfig || !m_pParent ) return FALSE;
  275. // Validate settings
  276. HRESULT hr = S_OK;
  277. if( !ValidateControls() )
  278. {
  279. return FALSE;
  280. }
  281. // Set the Logging Level
  282. long lLogLevel = SendDlgItemMessage(IDC_LOGGING, CB_GETCURSEL, 0, 0);
  283. hr = m_spServerConfig->put_LoggingLevel( lLogLevel );
  284. if( FAILED(hr) )
  285. {
  286. // Error placing the Logging Level
  287. tstring strMessage = StrLoadString( IDS_ERROR_SETLOGGING );
  288. tstring strTitle = StrLoadString(IDS_SNAPINNAME);
  289. DisplayError( m_hWnd, strMessage.c_str(), strTitle.c_str(), hr );
  290. ::SetFocus( GetDlgItem(IDC_LOGGING) );
  291. return FALSE;
  292. }
  293. // Set the Port Number
  294. long lPort = 0L;
  295. CComPtr<IP3Service> spService = NULL;
  296. hr = m_spServerConfig->get_Service( &spService );
  297. if( SUCCEEDED(hr) && spService )
  298. {
  299. lPort = (long)GetDlgItemInt( IDC_PORT, NULL, FALSE );
  300. hr = spService->put_Port( lPort );
  301. }
  302. if( FAILED(hr) )
  303. {
  304. // Error Setting the port
  305. tstring strMessage = StrLoadString( IDS_ERROR_SETPORT );
  306. tstring strTitle = StrLoadString(IDS_SNAPINNAME);
  307. DisplayError( m_hWnd, strMessage.c_str(), strTitle.c_str(), hr );
  308. ::SetFocus( GetDlgItem(IDC_PORT) );
  309. return FALSE;
  310. }
  311. // Set the Authentication type
  312. if( ::IsWindowEnabled(GetDlgItem(IDC_AUTHENTICATION)) )
  313. {
  314. long lIndex = SendDlgItemMessage( IDC_AUTHENTICATION, CB_GETCURSEL, 0, 0 );
  315. long lAuth = SendDlgItemMessage( IDC_AUTHENTICATION, CB_GETITEMDATA, lIndex, 0 );
  316. CComVariant var;
  317. CComPtr<IAuthMethods> spMethods = NULL;
  318. hr = m_spServerConfig->get_Authentication( &spMethods );
  319. if( SUCCEEDED(hr) )
  320. {
  321. var.Clear();
  322. V_VT( &var ) = VT_I4;
  323. V_I4( &var ) = lAuth;
  324. hr = spMethods->put_CurrentAuthMethod( var );
  325. }
  326. if( SUCCEEDED(hr) )
  327. {
  328. hr = spMethods->Save();
  329. }
  330. }
  331. if( FAILED(hr) )
  332. {
  333. // Error setting the Authentication type
  334. tstring strMessage = StrLoadString( IDS_ERROR_SETAUTH );
  335. tstring strTitle = StrLoadString(IDS_SNAPINNAME);
  336. DisplayError( m_hWnd, strMessage.c_str(), strTitle.c_str(), hr );
  337. ::SetFocus( GetDlgItem(IDC_AUTHENTICATION) );
  338. return FALSE;
  339. }
  340. // Set the Mail Root
  341. CComBSTR bstrOldRoot = _T("");
  342. hr = m_spServerConfig->get_MailRoot( &bstrOldRoot );
  343. if( SUCCEEDED(hr) )
  344. {
  345. TCHAR szMailRoot[MAX_PATH+1];
  346. GetDlgItemText(IDC_DIRECTORY, szMailRoot, MAX_PATH+1);
  347. // If there are any domains, display message
  348. long lDomains = 0L;
  349. CComPtr<IP3Domains> spDomains = NULL;
  350. HRESULT hrDomain = m_spServerConfig->get_Domains( &spDomains );
  351. if( SUCCEEDED(hrDomain) )
  352. {
  353. hrDomain = spDomains->get_Count( &lDomains );
  354. }
  355. CComBSTR bstrNewRoot = szMailRoot;
  356. hr = m_spServerConfig->put_MailRoot( bstrNewRoot );
  357. if( SUCCEEDED(hr) )
  358. {
  359. // Issue a warning after they've switched mail roots
  360. if( (FAILED(hrDomain) || (lDomains > 0)) && (_tcsicmp( OLE2T(bstrOldRoot), szMailRoot) != 0) )
  361. {
  362. tstring strMessage = StrLoadString(IDS_WARNING_MAILROOT);
  363. tstring strTitle = StrLoadString(IDS_SNAPINNAME);
  364. ::MessageBox( m_hWnd, strMessage.c_str(), strTitle.c_str(), MB_OK | MB_ICONWARNING );
  365. }
  366. }
  367. else
  368. {
  369. // Error setting the Mail Root
  370. tstring strMessage = StrLoadString(IDS_ERROR_SETROOT);
  371. tstring strTitle = StrLoadString(IDS_SNAPINNAME);
  372. DisplayError( m_hWnd, strMessage.c_str(), strTitle.c_str(), hr );
  373. ::SetFocus( GetDlgItem(IDC_DIRECTORY) );
  374. return FALSE;
  375. }
  376. }
  377. // Set the User Creation Flag
  378. m_pParent->m_bCreateUser = (IsDlgButtonChecked(IDC_SERVER_CREATEUSER) == BST_CHECKED);
  379. BOOL bSPARequired = (IsDlgButtonChecked(IDC_SERVER_SPA_REQ) == BST_CHECKED);
  380. // Do our User creation and SPA property
  381. RegSetCreateUser ( m_pParent->m_bCreateUser, m_pParent->m_bstrDisplayName );
  382. RegSetSPARequired( bSPARequired, m_pParent->m_bstrDisplayName );
  383. MMCPropertyChangeNotify(m_lNotifyHandle, (LPARAM)m_pParent);
  384. UINT uID=0;
  385. UINT uErrID=0;
  386. if( m_dwSvcRestart )
  387. {
  388. long lP3Status=SERVICE_STOPPED;
  389. long lSMTPStatus=SERVICE_STOPPED;
  390. if( RESTART_POP3SVC == m_dwSvcRestart )
  391. {
  392. hr = spService->get_POP3ServiceStatus(&lP3Status);
  393. if(FAILED(hr) || SERVICE_STOPPED != lP3Status )
  394. {
  395. uID = IDS_WARNING_POP3SVC_RESTART;
  396. }
  397. }
  398. else
  399. {
  400. hr = spService->get_POP3ServiceStatus(&lP3Status);
  401. if(SUCCEEDED(hr))
  402. {
  403. hr = spService->get_SMTPServiceStatus(&lSMTPStatus);
  404. }
  405. if (FAILED (hr) ||
  406. SERVICE_STOPPED != lP3Status ||
  407. SERVICE_STOPPED != lSMTPStatus )
  408. {
  409. uID = IDS_WARNING_POP_SMTP_RESTART;
  410. }
  411. }
  412. if(uID)
  413. {
  414. tstring strMessage = StrLoadString( uID );
  415. tstring strTitle = StrLoadString(IDS_SNAPINNAME);
  416. if(IDYES ==
  417. ::MessageBox( m_hWnd, strMessage.c_str(), strTitle.c_str(), MB_YESNO))
  418. {
  419. if(SERVICE_STOPPED != lP3Status)
  420. {
  421. hr=spService->StopPOP3Service();
  422. if(SUCCEEDED(hr))
  423. {
  424. hr=spService->StartPOP3Service();
  425. if(FAILED(hr))
  426. {
  427. uErrID=IDS_ERROR_STARTSERVICE;
  428. }
  429. }
  430. else
  431. {
  432. uErrID=IDS_ERROR_STOPSERVICE;
  433. }
  434. }
  435. if(SUCCEEDED(hr))
  436. {
  437. if(IDS_WARNING_POP_SMTP_RESTART == uID &&
  438. SERVICE_STOPPED != lSMTPStatus )
  439. {
  440. hr=spService->StopSMTPService();
  441. if(SUCCEEDED(hr))
  442. {
  443. hr=spService->StartSMTPService();
  444. if(FAILED(hr))
  445. {
  446. uErrID=IDS_ERROR_SMTP_STARTSERVICE;
  447. }
  448. }
  449. else
  450. {
  451. uErrID=IDS_ERROR_SMTP_STOPSERVICE;
  452. }
  453. }
  454. }
  455. if(FAILED(hr))
  456. {
  457. tstring strMessage = StrLoadString(uErrID );
  458. tstring strTitle = StrLoadString(IDS_SNAPINNAME);
  459. ::MessageBox( m_hWnd, strMessage.c_str(), strTitle.c_str(), MB_OK | MB_ICONWARNING );
  460. m_dwSvcRestart =0;
  461. return FALSE;
  462. }
  463. }
  464. }
  465. }
  466. m_dwSvcRestart =0;
  467. return TRUE;
  468. }
  469. LRESULT CServerGeneralPage::OnBrowse(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  470. {
  471. TCHAR szPath[MAX_PATH];
  472. TCHAR pBuffer[MAX_PATH];
  473. int nImage = 0;
  474. tstring strTitle = StrLoadString(IDS_SERVERPROP_BROWSE_TITLE);
  475. LPITEMIDLIST pList = NULL;
  476. CComPtr<IMalloc> spMalloc = NULL;
  477. HRESULT hr = SHGetMalloc(&spMalloc);
  478. if( SUCCEEDED(hr) )
  479. {
  480. BROWSEINFO BrowseInfo;
  481. BrowseInfo.hwndOwner = m_hWnd;
  482. BrowseInfo.pidlRoot = NULL;
  483. BrowseInfo.pszDisplayName = szPath;
  484. BrowseInfo.lpszTitle = strTitle.c_str();
  485. BrowseInfo.ulFlags = BIF_RETURNONLYFSDIRS;
  486. BrowseInfo.lpfn = NULL;
  487. BrowseInfo.lParam = NULL;
  488. BrowseInfo.iImage = nImage;
  489. pList = ::SHBrowseForFolder(&BrowseInfo);
  490. }
  491. if( pList )
  492. {
  493. if( ::SHGetPathFromIDList(pList, pBuffer) )
  494. {
  495. SetDlgItemText( IDC_DIRECTORY, pBuffer );
  496. }
  497. spMalloc->Free( pList );
  498. pList = NULL;
  499. }
  500. return 0;
  501. }
  502. LRESULT CServerGeneralPage::OnHelpMsg( UINT mMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled )
  503. {
  504. TCHAR szWindowsDir[MAX_PATH+1] = {0};
  505. LPHELPINFO lpHelpInfo = (LPHELPINFO)lParam;
  506. UINT nSize = GetSystemWindowsDirectory( szWindowsDir, MAX_PATH );
  507. if( nSize == 0 || nSize > MAX_PATH )
  508. {
  509. return 0;
  510. }
  511. tstring strPath = szWindowsDir;
  512. strPath += _T("\\Help\\");
  513. strPath += StrLoadString( IDS_CONTEXTHELPFILE );
  514. if( lpHelpInfo )
  515. {
  516. switch( lpHelpInfo->iCtrlId )
  517. {
  518. case IDC_PORT_STATIC:
  519. case IDC_PORT:
  520. {
  521. ::WinHelp( m_hWnd, strPath.c_str(), HELP_CONTEXTPOPUP, IDH_POP3_server_prop_servPort);
  522. break;
  523. }
  524. case IDC_DIRECTORY_STATIC:
  525. case IDC_DIRECTORY:
  526. {
  527. ::WinHelp( m_hWnd, strPath.c_str(), HELP_CONTEXTPOPUP, IDH_POP3_server_prop_mailRoot );
  528. break;
  529. }
  530. case IDC_AUTHENTICATION_STATIC:
  531. case IDC_AUTHENTICATION:
  532. {
  533. ::WinHelp( m_hWnd, strPath.c_str(), HELP_CONTEXTPOPUP, IDH_POP3_server_prop_authMech );
  534. break;
  535. }
  536. case IDC_LOGGING_STATIC:
  537. case IDC_LOGGING:
  538. {
  539. ::WinHelp( m_hWnd, strPath.c_str(), HELP_CONTEXTPOPUP, IDH_POP3_server_prop_logLvl );
  540. break;
  541. }
  542. case IDC_SERVER_CREATEUSER:
  543. {
  544. ::WinHelp( m_hWnd, strPath.c_str(), HELP_CONTEXTPOPUP, IDH_POP3_server_prop_createUser );
  545. break;
  546. }
  547. case IDC_SERVER_SPA_REQ:
  548. {
  549. ::WinHelp( m_hWnd, strPath.c_str(), HELP_CONTEXTPOPUP, IDH_POP3_server_prop_spaRequired );
  550. break;
  551. }
  552. default:
  553. {
  554. strPath = szWindowsDir;
  555. strPath += _T("\\Help\\");
  556. strPath += StrLoadString( IDS_HELPFILE );
  557. strPath += _T("::/");
  558. strPath += StrLoadString( IDS_HELPTOPIC );
  559. HtmlHelp( m_hWnd, strPath.c_str(), HH_DISPLAY_TOPIC, NULL );
  560. break;
  561. }
  562. }
  563. }
  564. else
  565. {
  566. strPath = szWindowsDir;
  567. strPath += _T("\\Help\\");
  568. strPath += StrLoadString( IDS_HELPFILE );
  569. strPath += _T("::/");
  570. strPath += StrLoadString( IDS_HELPTOPIC );
  571. HtmlHelp( m_hWnd, strPath.c_str(), HH_DISPLAY_TOPIC, NULL );
  572. }
  573. return 0;
  574. }
  575. BOOL CServerGeneralPage::ValidateControls()
  576. {
  577. BOOL bTrans;
  578. // Validate the Port
  579. UINT nPort = GetDlgItemInt( IDC_PORT, &bTrans, FALSE );
  580. if( !bTrans || ((nPort <= 0) || (nPort > 65535)) )
  581. {
  582. // Error Setting the port
  583. tstring strMessage = StrLoadString( IDS_ERROR_PORTRANGE );
  584. tstring strTitle = StrLoadString(IDS_SNAPINNAME);
  585. ::MessageBox( m_hWnd, strMessage.c_str(), strTitle.c_str(), MB_OK | MB_ICONWARNING );
  586. ::SetFocus( GetDlgItem(IDC_PORT) );
  587. return FALSE;
  588. }
  589. return TRUE;
  590. }
  591. void CServerGeneralPage::OnFinalMessage(HWND hW)
  592. {
  593. if(m_pParent)
  594. {
  595. m_pParent->Release();
  596. }
  597. }