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 / namepage.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  3.2 KB  |  134 lines

  1. // NamePage.cpp : implementation of the CNamePage 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. #include "httpsvr.h"
  15. #include "NamePage.h"
  16. #include "HttpDoc.h"
  17.  
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CNamePage property page
  26.  
  27. IMPLEMENT_DYNCREATE(CNamePage, CPropertyPage)
  28.  
  29. CNamePage::CNamePage() : CPropertyPage(CNamePage::IDD)
  30. {
  31. }
  32.  
  33. CNamePage::CNamePage( CHttpSvrDoc* pDoc )
  34.     : CPropertyPage(CNamePage::IDD)
  35. {
  36.     //{{AFX_DATA_INIT(CNamePage)
  37.     m_strName = _T("");
  38.     m_nNameSetting = -1;
  39.     m_uPort = 0;
  40.     //}}AFX_DATA_INIT
  41.     m_pDoc = pDoc;
  42. }
  43.  
  44. CNamePage::~CNamePage()
  45. {
  46. }
  47.  
  48. void CNamePage::DoDataExchange(CDataExchange* pDX)
  49. {
  50.     CPropertyPage::DoDataExchange(pDX);
  51.     //{{AFX_DATA_MAP(CNamePage)
  52.     DDX_Text(pDX, IDC_SVRNAME, m_strName);
  53.     DDX_Radio(pDX, IDC_DEFNAME, m_nNameSetting);
  54.     DDX_Text(pDX, IDC_PORT, m_uPort);
  55.     DDV_MinMaxUInt(pDX, m_uPort, 0, 65535);
  56.     //}}AFX_DATA_MAP
  57. }
  58.  
  59.  
  60. BEGIN_MESSAGE_MAP(CNamePage, CPropertyPage)
  61.     //{{AFX_MSG_MAP(CNamePage)
  62.     ON_BN_CLICKED(IDC_DEFNAME, OnDefName)
  63.     ON_BN_CLICKED(IDC_USENAME, OnUseName)
  64.     //}}AFX_MSG_MAP
  65. END_MESSAGE_MAP()
  66.  
  67. /////////////////////////////////////////////////////////////////////////////
  68. // CNamePage message handlers
  69.  
  70. BOOL CNamePage::OnInitDialog()
  71. {
  72.     CPropertyPage::OnInitDialog();
  73.     CWnd* pwndEdit = GetDlgItem( IDC_SVRNAME );
  74.     pwndEdit->EnableWindow( (m_nNameSetting?TRUE:FALSE) );
  75.  
  76.     return TRUE;  // return TRUE unless you set the focus to a control
  77.                   // EXCEPTION: OCX Property Pages should return FALSE
  78. }
  79.  
  80. void CNamePage::OnDefName()
  81. {
  82.     // disable the edit control....
  83.     CWnd* pwndEdit = GetDlgItem( IDC_SVRNAME );
  84.     if ( pwndEdit )
  85.         pwndEdit->EnableWindow( FALSE );
  86. }
  87.  
  88. void CNamePage::OnUseName()
  89. {
  90.     // enable the edit control and move to it....
  91.     CWnd* pwndEdit = GetDlgItem( IDC_SVRNAME );
  92.     if ( pwndEdit )
  93.     {
  94.         pwndEdit->EnableWindow( TRUE );
  95.         pwndEdit->SetFocus();
  96.     }
  97. }
  98.  
  99. void CNamePage::OnOK()
  100. {
  101.     BOOL bModified = FALSE;
  102.     CString strNewName;
  103.     if ( m_nNameSetting && !m_strName.IsEmpty() )
  104.         strNewName = m_strName;
  105.     else
  106.     {
  107.         strNewName = ((CHttpSvrApp*)AfxGetApp())->m_strDefSvr;
  108.         m_nNameSetting = 0;
  109.     }
  110.     // see if anything has changed....
  111.     if ( m_pDoc->m_nSvrName != m_nNameSetting )
  112.     {
  113.         m_pDoc->m_nSvrName = m_nNameSetting;
  114.         bModified = TRUE;
  115.     }
  116.     if ( strNewName.CompareNoCase(m_pDoc->m_strServer) )
  117.     {
  118.         m_pDoc->m_strServer = strNewName;
  119.         bModified = TRUE;
  120.     }
  121.  
  122.     // if the port has changed, we need to reset the listen socket....
  123.     if ( m_pDoc->m_uPort != m_uPort )
  124.     {
  125.         m_pDoc->m_uPort = m_uPort;
  126.         m_pDoc->m_bResetListen = bModified = TRUE;
  127.     }
  128.  
  129.     if ( bModified )
  130.         m_pDoc->SetModifiedFlag( TRUE );
  131.  
  132.     CPropertyPage::OnOK();
  133. }
  134.