home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / internet / httpsvr / rootpage.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  3.0 KB  |  119 lines

  1. // RootPage.cpp : implementation of the CRootPage class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1997-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14.  
  15. #include "HttpSvr.h"
  16. #include "RootPage.h"
  17. #include "HttpDoc.h"
  18.  
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CRootPage property page
  27.  
  28. IMPLEMENT_DYNCREATE(CRootPage, CPropertyPage)
  29.  
  30. CRootPage::CRootPage() : CPropertyPage(CRootPage::IDD)
  31. {
  32. }
  33.  
  34. CRootPage::CRootPage( CHttpSvrDoc* pDoc )
  35.     : CPropertyPage(CRootPage::IDD)
  36. {
  37.     //{{AFX_DATA_INIT(CRootPage)
  38.     m_strRoot = _T("");
  39.     //}}AFX_DATA_INIT
  40.     m_pDoc = pDoc;
  41. }
  42.  
  43. CRootPage::~CRootPage()
  44. {
  45. }
  46.  
  47. void CRootPage::DoDataExchange(CDataExchange* pDX)
  48. {
  49.     CPropertyPage::DoDataExchange(pDX);
  50.     //{{AFX_DATA_MAP(CRootPage)
  51.     DDX_Text(pDX, IDC_ROOTDIR, m_strRoot);
  52.     //}}AFX_DATA_MAP
  53. }
  54.  
  55.  
  56. BEGIN_MESSAGE_MAP(CRootPage, CPropertyPage)
  57.     //{{AFX_MSG_MAP(CRootPage)
  58.     ON_BN_CLICKED(IDC_RESET, OnReset)
  59.     ON_EN_CHANGE(IDC_ROOTDIR, OnChangeRootDir)
  60.     //}}AFX_MSG_MAP
  61. END_MESSAGE_MAP()
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CRootPage message handlers
  65.  
  66. void CRootPage::OnReset()
  67. {
  68.     SetDlgItemText( IDC_ROOTDIR, m_pDoc->m_strRoot );
  69.     SetModified( FALSE );
  70. }
  71.  
  72. void CRootPage::OnChangeRootDir()
  73. {
  74.     SetModified( TRUE );
  75. }
  76.  
  77. BOOL CRootPage::OnKillActive()
  78. {
  79.     BOOL bOk = CPropertyPage::OnKillActive();
  80.     if ( bOk )
  81.     {
  82.         // make sure it doesn't end in a separator char....
  83.         if ( m_strRoot[ m_strRoot.GetLength()-1 ] == SEPCHAR )
  84.             m_strRoot = m_strRoot.Left( m_strRoot.GetLength() - 1 );
  85.         // resolve to complete file path....
  86.         CString strFull;
  87.         GetFullPathName( m_strRoot, MAX_PATH, strFull.GetBuffer(MAX_PATH+1), NULL );
  88.         strFull.ReleaseBuffer();
  89.         // set the control to this complete, fixed path....
  90.         SetDlgItemText( IDC_ROOTDIR, strFull );
  91.         m_strRoot = strFull;
  92.         // make sure the directory is valid....
  93.         DWORD dwAttr = GetFileAttributes( strFull );
  94.         if ( dwAttr == -1 ||
  95.             (dwAttr & FILE_ATTRIBUTE_DIRECTORY) == 0 )
  96.         {
  97.             CString strText;
  98.             strText.LoadString( IDS_BAD_ROOT );
  99.             MessageBox( strText, NULL, MB_OK|MB_ICONSTOP );
  100.             bOk = FALSE;
  101.         }
  102.     }
  103.     return bOk;
  104. }
  105.  
  106. void CRootPage::OnOK()
  107. {
  108.     // make sure it doesn't end in a sepchar....
  109.     if ( m_strRoot[ m_strRoot.GetLength()-1 ] == SEPCHAR )
  110.         m_strRoot = m_strRoot.Left( m_strRoot.GetLength()-1 );
  111.     // copy it over....
  112.     if ( m_pDoc->m_strRoot.CompareNoCase( m_strRoot ) )
  113.     {
  114.         m_pDoc->m_strRoot = m_strRoot;
  115.         m_pDoc->SetModifiedFlag( TRUE );
  116.     }
  117.     CPropertyPage::OnOK();
  118. }
  119.