home *** CD-ROM | disk | FTP | other *** search
/ Mastering Microsoft Visual C++ 4 (2nd Edition) / VisualC4.ISO / servdemo / servdemo.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-30  |  5.5 KB  |  189 lines

  1. // ServDemo.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "ServDemo.h"
  6.  
  7. #include "MainFrm.h"
  8. #include "IpFrame.h"
  9. #include "ServDDoc.h"
  10. #include "ServDeVw.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. // CServDemoApp
  20.  
  21. BEGIN_MESSAGE_MAP(CServDemoApp, CWinApp)
  22.    //{{AFX_MSG_MAP(CServDemoApp)
  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. // CServDemoApp construction
  34.  
  35. CServDemoApp::CServDemoApp()
  36. {
  37.    // TODO: add construction code here,
  38.    // Place all significant initialization in InitInstance
  39. }
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // The one and only CServDemoApp object
  43.  
  44. CServDemoApp 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. // {D1B122C0-F277-11CE-8F29-BD0C02C41026}
  50. static const CLSID clsid =
  51. { 0xd1b122c0, 0xf277, 0x11ce, { 0x8f, 0x29, 0xbd, 0xc, 0x2, 0xc4, 0x10, 0x26 } };
  52.  
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CServDemoApp initialization
  55.  
  56. BOOL CServDemoApp::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. #ifdef _AFXDLL
  71.    Enable3dControls();        // Call this when using MFC in a shared DLL
  72. #else
  73.    Enable3dControlsStatic();  // Call this when linking to MFC statically
  74. #endif
  75.  
  76.    LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  77.  
  78.    // Register the application's document templates.  Document templates
  79.    //  serve as the connection between documents, frame windows and views.
  80.  
  81.    CSingleDocTemplate* pDocTemplate;
  82.    pDocTemplate = new CSingleDocTemplate(
  83.       IDR_MAINFRAME,
  84.       RUNTIME_CLASS(CServDemoDoc),
  85.       RUNTIME_CLASS(CMainFrame),       // main SDI frame window
  86.       RUNTIME_CLASS(CServDemoView));
  87.    pDocTemplate->SetServerInfo(
  88.       IDR_SRVR_EMBEDDED, IDR_SRVR_INPLACE,
  89.       RUNTIME_CLASS(CInPlaceFrame));
  90.    AddDocTemplate(pDocTemplate);
  91.  
  92.    // Connect the COleTemplateServer to the document template.
  93.    //  The COleTemplateServer creates new documents on behalf
  94.    //  of requesting OLE containers by using information
  95.    //  specified in the document template.
  96.    m_server.ConnectTemplate(clsid, pDocTemplate, TRUE);
  97.       // Note: SDI applications register server objects only if /Embedding
  98.       //   or /Automation is present on the command line.
  99.  
  100.    // Enable DDE Execute open
  101.    EnableShellOpen();
  102.    RegisterShellFileTypes(TRUE);
  103.  
  104.    // Parse command line for standard shell commands, DDE, file open
  105.    CCommandLineInfo cmdInfo;
  106.    ParseCommandLine(cmdInfo);
  107.  
  108.    // Check to see if launched as OLE server
  109.    if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
  110.    {
  111.       // Register all OLE server (factories) as running.  This enables the
  112.       //  OLE libraries to create objects from other applications.
  113.       COleTemplateServer::RegisterAll();
  114.  
  115.       // Application was run with /Embedding or /Automation.  Don't show the
  116.       //  main window in this case.
  117.       return TRUE;
  118.    }
  119.  
  120.    // When a server application is launched stand-alone, it is a good idea
  121.    //  to update the system registry in case it has been damaged.
  122.    m_server.UpdateRegistry(OAT_INPLACE_SERVER);
  123.  
  124.    // Dispatch commands specified on the command line
  125.    if (!ProcessShellCommand(cmdInfo))
  126.       return FALSE;
  127.  
  128.    // Enable drag/drop open
  129.    m_pMainWnd->DragAcceptFiles();
  130.  
  131.    return TRUE;
  132. }
  133.  
  134. /////////////////////////////////////////////////////////////////////////////
  135. // CAboutDlg dialog used for App About
  136.  
  137. class CAboutDlg : public CDialog
  138. {
  139. public:
  140.    CAboutDlg();
  141.  
  142. // Dialog Data
  143.    //{{AFX_DATA(CAboutDlg)
  144.    enum { IDD = IDD_ABOUTBOX };
  145.    //}}AFX_DATA
  146.  
  147.    // ClassWizard generated virtual function overrides
  148.    //{{AFX_VIRTUAL(CAboutDlg)
  149.    protected:
  150.    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  151.    //}}AFX_VIRTUAL
  152.  
  153. // Implementation
  154. protected:
  155.    //{{AFX_MSG(CAboutDlg)
  156.       // No message handlers
  157.    //}}AFX_MSG
  158.    DECLARE_MESSAGE_MAP()
  159. };
  160.  
  161. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  162. {
  163.    //{{AFX_DATA_INIT(CAboutDlg)
  164.    //}}AFX_DATA_INIT
  165. }
  166.  
  167. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  168. {
  169.    CDialog::DoDataExchange(pDX);
  170.    //{{AFX_DATA_MAP(CAboutDlg)
  171.    //}}AFX_DATA_MAP
  172. }
  173.  
  174. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  175.    //{{AFX_MSG_MAP(CAboutDlg)
  176.       // No message handlers
  177.    //}}AFX_MSG_MAP
  178. END_MESSAGE_MAP()
  179.  
  180. // App command to run the dialog
  181. void CServDemoApp::OnAppAbout()
  182. {
  183.    CAboutDlg aboutDlg;
  184.    aboutDlg.DoModal();
  185. }
  186.  
  187. /////////////////////////////////////////////////////////////////////////////
  188. // CServDemoApp commands
  189.