home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / labs / c11 / lab02 / baseline / urldialog.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  3.9 KB  |  167 lines

  1. // URLDialog.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "IC_2.h"
  6.  
  7. #include "URLDialog.h"
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CUrlDialog dialog
  17.  
  18.  
  19. CUrlDialog::CUrlDialog(CWnd* pParent /*=NULL*/)
  20.     : CDialog(CUrlDialog::IDD, pParent)
  21. {
  22.     //{{AFX_DATA_INIT(CUrlDialog)
  23.     m_Server = _T("");
  24.     m_Object = _T("");
  25.     //}}AFX_DATA_INIT
  26. }
  27.  
  28.  
  29. void CUrlDialog::DoDataExchange(CDataExchange* pDX)
  30. {
  31.     CDialog::DoDataExchange(pDX);
  32.     //{{AFX_DATA_MAP(CUrlDialog)
  33.     //}}AFX_DATA_MAP
  34. }
  35.  
  36.  
  37. BEGIN_MESSAGE_MAP(CUrlDialog, CDialog)
  38.     //{{AFX_MSG_MAP(CUrlDialog)
  39.     ON_BN_CLICKED(IDC_PARSE, OnParse)
  40.     ON_EN_CHANGE(IDC_EDIT_URL, OnChangeEditUrl)
  41.     //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43.  
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CUrlDialog message handlers
  46.  
  47. void CUrlDialog::OnParse() 
  48. {
  49.     CString url;
  50.     CEdit * ce = (CEdit *)GetDlgItem(IDC_EDIT_URL);
  51.     
  52.     ce->GetWindowText(url);
  53.     
  54.     // Parse the URL and place its 4 components into the appropriate variables
  55.     AfxParseURL(url, m_ServerType, m_Server, m_Object, m_Port);
  56.  
  57.     // Display the 4 components in the static controls on the dialog box.
  58.     CStatic * cs = (CStatic *)GetDlgItem(IDC_SERVER);
  59.     cs->SetWindowText(m_Server);
  60.  
  61.     cs = (CStatic *)GetDlgItem(IDC_OBJECT);
  62.     cs->SetWindowText(m_Object);
  63.  
  64.     cs = (CStatic *)GetDlgItem(IDC_SERVICE_TYPE);
  65.     switch (m_ServerType)
  66.     {
  67.         case AFX_INET_SERVICE_FTP:
  68.             cs->SetWindowText("FTP");
  69.             break;
  70.         case AFX_INET_SERVICE_HTTP:
  71.             cs->SetWindowText("HTTP");
  72.             break;
  73.         case AFX_INET_SERVICE_GOPHER:
  74.             cs->SetWindowText("GOPHER");
  75.             break;
  76.         case AFX_INET_SERVICE_FILE:
  77.             cs->SetWindowText("FILE");
  78.             break;
  79.         case AFX_INET_SERVICE_MAILTO:
  80.             cs->SetWindowText("MAILTO");
  81.             break;
  82.         case AFX_INET_SERVICE_NEWS:
  83.             cs->SetWindowText("NEWS");
  84.             break;
  85.         case AFX_INET_SERVICE_NNTP:
  86.             cs->SetWindowText("NNTP");
  87.             break;
  88.         case AFX_INET_SERVICE_TELNET:
  89.             cs->SetWindowText("TELNET");
  90.             break;
  91.         case AFX_INET_SERVICE_WAIS:
  92.             cs->SetWindowText("WAIS");
  93.             break;
  94.         case AFX_INET_SERVICE_MID:
  95.             cs->SetWindowText("MID");
  96.             break;
  97.         case AFX_INET_SERVICE_CID:
  98.             cs->SetWindowText("CID");
  99.             break;
  100.         case AFX_INET_SERVICE_PROSPERO:
  101.             cs->SetWindowText("PROSPERO");
  102.             break;
  103.         case AFX_INET_SERVICE_AFS:
  104.             cs->SetWindowText("AFS");
  105.             break;
  106.         case AFX_INET_SERVICE_UNK:
  107.             cs->SetWindowText("Unknown");
  108.     }
  109.  
  110.     // convert the port number to a string.
  111.     char buff[10];
  112.     itoa(m_Port, buff, 10);
  113.     cs = (CStatic *)GetDlgItem(IDC_PORT);
  114.     cs->SetWindowText(buff);
  115.  
  116.     // Finally, enable the OK button,
  117.     CButton * cb = (CButton *)GetDlgItem(IDOK);
  118.     cb->EnableWindow(TRUE);
  119.  
  120.     // and disable the Parse button.
  121.     cb = (CButton *)GetDlgItem(IDC_PARSE);
  122.     cb->EnableWindow(FALSE);
  123.  
  124. }
  125.  
  126. BOOL CUrlDialog::OnInitDialog() 
  127. {
  128.     CDialog::OnInitDialog();
  129.     
  130.     // Initially, the OK button and Parse buttons are disabled
  131.     CButton * cb = (CButton *)GetDlgItem(IDOK);
  132.     cb->EnableWindow(FALSE);
  133.     cb = (CButton *)GetDlgItem(IDC_PARSE);
  134.     cb->EnableWindow(FALSE);
  135.  
  136.     CEdit * ce = (CEdit *)GetDlgItem(IDC_EDIT_URL);
  137.  
  138.     // The default server will be on this same machine.
  139.     unsigned long len = MAX_COMPUTERNAME_LENGTH + 1;
  140.     char buff[MAX_COMPUTERNAME_LENGTH + 1];
  141.     
  142.     GetComputerName(buff,  &len);
  143.     strlwr(buff);
  144.     
  145.     CString sMachineName(buff);
  146.     CString sHTTP = "http://";
  147.     CString sScripts = "/";
  148.     
  149.     // Assemble the 3 pieces.
  150.     CString sURL = sHTTP + sMachineName + sScripts;
  151.     int textlen = sURL.GetLength();
  152.     ce->SetWindowText(sURL);
  153.  
  154.     // Place the cursor at the end of the supplied string.
  155.     ce->SetSel(textlen, textlen);
  156.     ce->SetFocus();
  157.  
  158.     // return FALSE since I set focus.
  159.     return FALSE;
  160. }
  161.  
  162. void CUrlDialog::OnChangeEditUrl() 
  163. {
  164.     CButton * cb = (CButton *)GetDlgItem(IDC_PARSE);
  165.     cb->EnableWindow(TRUE);
  166. }
  167.