home *** CD-ROM | disk | FTP | other *** search
/ Using Visual C++ 4 (Special Edition) / Using_Visual_C_4_Special_Edition_QUE_1996.iso / ch08 / oserver / oserver.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-16  |  4.9 KB  |  176 lines

  1. // OServer.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "OServer.h"
  6.  
  7. #include "MainFrm.h"
  8. #include "IpFrame.h"
  9. #include "OServerDoc.h"
  10. #include "OServerView.h"
  11.  
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // COServerApp
  20.  
  21. BEGIN_MESSAGE_MAP(COServerApp, CWinApp)
  22.     //{{AFX_MSG_MAP(COServerApp)
  23.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  24.         // NOTE - the ClassWizard will add and remove mapping macros here.
  25.         //    DO NOT EDIT what you see in these blocks of generated code!
  26.     //}}AFX_MSG_MAP
  27.     // Standard file based document commands
  28.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  29.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  30. END_MESSAGE_MAP()
  31.  
  32. /////////////////////////////////////////////////////////////////////////////
  33. // COServerApp construction
  34.  
  35. COServerApp::COServerApp()
  36. {
  37.     // TODO: add construction code here,
  38.     // Place all significant initialization in InitInstance
  39. }
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // The one and only COServerApp object
  43.  
  44. COServerApp theApp;
  45.  
  46. // This identifier was generated to be statistically unique for your app.
  47. // You may change it if you prefer to choose a specific identifier.
  48.  
  49. // {47954A82-F4EB-11CE-852A-080036667C02}
  50. static const CLSID clsid =
  51. { 0x47954a82, 0xf4eb, 0x11ce, { 0x85, 0x2a, 0x8, 0x0, 0x36, 0x66, 0x7c, 0x2 } };
  52.  
  53. /////////////////////////////////////////////////////////////////////////////
  54. // COServerApp initialization
  55.  
  56. BOOL COServerApp::InitInstance()
  57. {
  58.     // Initialize OLE libraries
  59.     if (!AfxOleInit())
  60.     {
  61.         AfxMessageBox(IDP_OLE_INIT_FAILED);
  62.         return FALSE;
  63.     }
  64.  
  65.     // Standard initialization
  66.     // If you are not using these features and wish to reduce the size
  67.     //  of your final executable, you should remove from the following
  68.     //  the specific initialization routines you do not need.
  69.  
  70.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  71.  
  72.     // Register the application's document templates.  Document templates
  73.     //  serve as the connection between documents, frame windows and views.
  74.  
  75.     CSingleDocTemplate* pDocTemplate;
  76.     pDocTemplate = new CSingleDocTemplate(
  77.         IDR_MAINFRAME,
  78.         RUNTIME_CLASS(COServerDoc),
  79.         RUNTIME_CLASS(CMainFrame),       // main SDI frame window
  80.         RUNTIME_CLASS(COServerView));
  81.     pDocTemplate->SetServerInfo(
  82.         IDR_SRVR_EMBEDDED, IDR_SRVR_INPLACE,
  83.         RUNTIME_CLASS(CInPlaceFrame));
  84.     AddDocTemplate(pDocTemplate);
  85.  
  86.     // Connect the COleTemplateServer to the document template.
  87.     //  The COleTemplateServer creates new documents on behalf
  88.     //  of requesting OLE containers by using information
  89.     //  specified in the document template.
  90.     m_server.ConnectTemplate(clsid, pDocTemplate, TRUE);
  91.         // Note: SDI applications register server objects only if /Embedding
  92.         //   or /Automation is present on the command line.
  93.  
  94.     // Parse command line for standard shell commands, DDE, file open
  95.     CCommandLineInfo cmdInfo;
  96.     ParseCommandLine(cmdInfo);
  97.  
  98.     // Check to see if launched as OLE server
  99.     if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
  100.     {
  101.         // Register all OLE server (factories) as running.  This enables the
  102.         //  OLE libraries to create objects from other applications.
  103.         COleTemplateServer::RegisterAll();
  104.  
  105.         // Application was run with /Embedding or /Automation.  Don't show the
  106.         //  main window in this case.
  107.         return TRUE;
  108.     }
  109.  
  110.     // When a server application is launched stand-alone, it is a good idea
  111.     //  to update the system registry in case it has been damaged.
  112.     m_server.UpdateRegistry(OAT_INPLACE_SERVER);
  113.  
  114.     // Dispatch commands specified on the command line
  115.     if (!ProcessShellCommand(cmdInfo))
  116.         return FALSE;
  117.  
  118.     return TRUE;
  119. }
  120.  
  121. /////////////////////////////////////////////////////////////////////////////
  122. // CAboutDlg dialog used for App About
  123.  
  124. class CAboutDlg : public CDialog
  125. {
  126. public:
  127.     CAboutDlg();
  128.  
  129. // Dialog Data
  130.     //{{AFX_DATA(CAboutDlg)
  131.     enum { IDD = IDD_ABOUTBOX };
  132.     //}}AFX_DATA
  133.  
  134.     // ClassWizard generated virtual function overrides
  135.     //{{AFX_VIRTUAL(CAboutDlg)
  136.     protected:
  137.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  138.     //}}AFX_VIRTUAL
  139.  
  140. // Implementation
  141. protected:
  142.     //{{AFX_MSG(CAboutDlg)
  143.         // No message handlers
  144.     //}}AFX_MSG
  145.     DECLARE_MESSAGE_MAP()
  146. };
  147.  
  148. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  149. {
  150.     //{{AFX_DATA_INIT(CAboutDlg)
  151.     //}}AFX_DATA_INIT
  152. }
  153.  
  154. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  155. {
  156.     CDialog::DoDataExchange(pDX);
  157.     //{{AFX_DATA_MAP(CAboutDlg)
  158.     //}}AFX_DATA_MAP
  159. }
  160.  
  161. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  162.     //{{AFX_MSG_MAP(CAboutDlg)
  163.         // No message handlers
  164.     //}}AFX_MSG_MAP
  165. END_MESSAGE_MAP()
  166.  
  167. // App command to run the dialog
  168. void COServerApp::OnAppAbout()
  169. {
  170.     CAboutDlg aboutDlg;
  171.     aboutDlg.DoModal();
  172. }
  173.  
  174. /////////////////////////////////////////////////////////////////////////////
  175. // COServerApp commands
  176.