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

  1. // HttpSvr.cpp : Defines the class behaviors for the application.
  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 "Http.h"
  17. #include "MainFrm.h"
  18. #include "HttpDoc.h"
  19. #include "HttpView.h"
  20.  
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CHttpSvrApp
  29.  
  30. BEGIN_MESSAGE_MAP(CHttpSvrApp, CWinApp)
  31.     //{{AFX_MSG_MAP(CHttpSvrApp)
  32.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  33.     //}}AFX_MSG_MAP
  34.     // Standard file based document commands
  35.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  36.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  37. END_MESSAGE_MAP()
  38.  
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CHttpSvrApp construction
  41.  
  42. CHttpSvrApp::CHttpSvrApp()
  43. {
  44. }
  45.  
  46. CHttpSvrApp::~CHttpSvrApp()
  47. {
  48. }
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // The one and only CHttpSvrApp object
  52.  
  53. CHttpSvrApp theApp;
  54.  
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CHttpSvrApp initialization
  57.  
  58. BOOL CHttpSvrApp::InitInstance()
  59. {
  60.     // Standard initialization
  61.     // If you are not using these features and wish to reduce the size
  62.     //  of your final executable, you should remove from the following
  63.     //  the specific initialization routines you do not need.
  64.  
  65.     if ( !AfxSocketInit() )
  66.     {
  67.         AfxMessageBox( IDS_WINSOCK_FAILED, MB_OK | MB_ICONEXCLAMATION );
  68.         return FALSE;
  69.     }
  70.  
  71. #ifdef _AFXDLL
  72.     Enable3dControls();         // Call this when using MFC in a shared DLL
  73. #else
  74.     Enable3dControlsStatic();   // Call this when linking to MFC statically
  75. #endif
  76.     SetRegistryKey( IDS_REGISTRY_KEY ); // use the registry
  77.     LoadStdProfileSettings(4);  // Load standard INI file options (including MRU)
  78.  
  79.     // try to get the default host name....
  80.     int nOk =  gethostname( m_strDefSvr.GetBuffer(255), 255 );
  81.     m_strDefSvr.ReleaseBuffer();
  82.     if ( nOk != 0 )
  83.     {
  84.         // get the computer server name....
  85.         DWORD dwLen = MAX_COMPUTERNAME_LENGTH+1;
  86.         GetComputerName( m_strDefSvr.GetBuffer( dwLen ), &dwLen );
  87.         m_strDefSvr.ReleaseBuffer();
  88.         // all lower-case....
  89.         m_strDefSvr.MakeLower();
  90.     }
  91.  
  92.     // Register the application's document templates.  Document templates
  93.     //  serve as the connection between documents, frame windows and views.
  94.  
  95.     CSingleDocTemplate* pDocTemplate;
  96.     pDocTemplate = new CSingleDocTemplate(
  97.         IDR_MAINFRAME,
  98.         RUNTIME_CLASS(CHttpSvrDoc),
  99.         RUNTIME_CLASS(CMainFrame),       // main SDI frame window
  100.         RUNTIME_CLASS(CHttpSvrView));
  101.     AddDocTemplate(pDocTemplate);
  102.  
  103.     // Enable DDE Execute open
  104.     EnableShellOpen();
  105.     RegisterShellFileTypes(TRUE);
  106.     RegisterLogFile();
  107.  
  108.     // Parse command line for standard shell commands, DDE, file open
  109.     CCommandLineInfo cmdInfo;
  110.     ParseCommandLine(cmdInfo);
  111.  
  112.     // Dispatch commands specified on the command line
  113.     if (!ProcessShellCommand(cmdInfo))
  114.         return FALSE;
  115.  
  116.     // Enable drag/drop open.
  117.     m_pMainWnd->DragAcceptFiles();
  118.  
  119.     return TRUE;
  120. }
  121.  
  122. /////////////////////////////////////////////////////////////////////////////
  123. // CAboutDlg dialog used for App About
  124.  
  125. class CAboutDlg : public CDialog
  126. {
  127. public:
  128.     CAboutDlg();
  129.  
  130. // Dialog Data
  131.     //{{AFX_DATA(CAboutDlg)
  132.     enum { IDD = IDD_ABOUTBOX };
  133.     //}}AFX_DATA
  134.  
  135.     // ClassWizard generated virtual function overrides
  136.     //{{AFX_VIRTUAL(CAboutDlg)
  137.     protected:
  138.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  139.     //}}AFX_VIRTUAL
  140.  
  141. // Implementation
  142. protected:
  143.     //{{AFX_MSG(CAboutDlg)
  144.         // No message handlers
  145.     //}}AFX_MSG
  146.     DECLARE_MESSAGE_MAP()
  147. };
  148.  
  149. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  150. {
  151.     //{{AFX_DATA_INIT(CAboutDlg)
  152.     //}}AFX_DATA_INIT
  153. }
  154.  
  155. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  156. {
  157.     CDialog::DoDataExchange(pDX);
  158.     //{{AFX_DATA_MAP(CAboutDlg)
  159.     //}}AFX_DATA_MAP
  160. }
  161.  
  162. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  163.     //{{AFX_MSG_MAP(CAboutDlg)
  164.         // No message handlers
  165.     //}}AFX_MSG_MAP
  166. END_MESSAGE_MAP()
  167.  
  168. // App command to run the dialog
  169. void CHttpSvrApp::OnAppAbout()
  170. {
  171.     CAboutDlg aboutDlg;
  172.     aboutDlg.DoModal();
  173. }
  174.  
  175. /////////////////////////////////////////////////////////////////////////////
  176. // CHttpSvrApp commands
  177.  
  178. BOOL CHttpSvrApp::OnIdle(LONG lCount)
  179. {
  180.     BOOL bMore = CWinApp::OnIdle(lCount);
  181.     // if we still need more processing time, ask for it...
  182.     CHttpSvrDoc* pDoc = (CHttpSvrDoc*)(((CFrameWnd*)m_pMainWnd)->GetActiveDocument());
  183.     if ( pDoc->IdleProc( lCount ) )
  184.         bMore = TRUE;
  185.     return bMore;
  186. }
  187.  
  188. void AddFile( CString& strPath, UINT uStr )
  189. {
  190.     CString strFile;
  191.     strFile.LoadString( uStr );
  192.     AddFile( strPath, strFile );
  193. }
  194.  
  195. void AddFile( CString& strPath, const CString& strFile )
  196. {
  197.     if ( strPath.GetAt( strPath.GetLength()-1 ) != SEPCHAR )
  198.         strPath += SEPCHAR;
  199.     strPath += strFile;
  200. }
  201.  
  202. // declare this....
  203. void AFXAPI AfxGetModuleShortFileName(HINSTANCE hInst, CString& strShortName);
  204.  
  205. void CHttpSvrApp::RegisterLogFile( void )
  206. {
  207.     // get the full path (short version)....
  208.     CString strPath;
  209.     AfxGetModuleShortFileName( AfxGetInstanceHandle(), strPath );
  210.     // set the entries....
  211.     CString strType = "HttpSvr.Logfile";
  212.     ::RegSetValue( HKEY_CLASSES_ROOT, ".hsl", REG_SZ, strType, 0 );
  213.     ::RegSetValue( HKEY_CLASSES_ROOT, strType, REG_SZ, "HttpSvr Daily Log File", 0 );
  214.     ::RegSetValue( HKEY_CLASSES_ROOT, strType+"\\DefaultIcon", REG_SZ, strPath+",2", 0 );
  215.     ::RegSetValue( HKEY_CLASSES_ROOT, strType+"\\shell\\open\\command", REG_SZ, "notepad.exe \"%1\"", 0 );
  216. }
  217.