home *** CD-ROM | disk | FTP | other *** search
/ Troubleshooting Netware Systems / CSTRIAL0196.BIN / attach / msj / v10n04 / olecont.exe / CONTAIN.CPP < prev    next >
C/C++ Source or Header  |  1995-04-01  |  6KB  |  196 lines

  1. // contain.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "contain.h"
  6.  
  7. #include "mainfrm.h"
  8. #include "childfrm.h"
  9. #include "cntlinfo.h"
  10. #include "contdoc.h"
  11. #include "contview.h"
  12.  
  13. #include <initguid.h>
  14. #include <olectlid.h>
  15.  
  16. #ifdef _DEBUG
  17. #undef THIS_FILE
  18. static char BASED_CODE THIS_FILE[] = __FILE__;
  19. #endif
  20.  
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CContainerApp
  23.  
  24. BEGIN_MESSAGE_MAP(CContainerApp, CWinApp)
  25.     //{{AFX_MSG_MAP(CContainerApp)
  26.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  27.         // NOTE - the ClassWizard will add and remove mapping macros here.
  28.         //    DO NOT EDIT what you see in these blocks of generated code!
  29.     //}}AFX_MSG_MAP
  30.     // Standard file based document commands
  31.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  32.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  33.     // Standard print setup command
  34.     ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  35. END_MESSAGE_MAP()
  36.  
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CContainerApp construction
  39.  
  40. CContainerApp::CContainerApp()
  41. {
  42.     // TODO: add construction code here,
  43.     // Place all significant initialization in InitInstance
  44. }
  45.  
  46. /////////////////////////////////////////////////////////////////////////////
  47. // The one and only CContainerApp object
  48.  
  49. CContainerApp theApp;
  50.  
  51. // This identifier was generated to be statistically unique for your app.
  52. // You may change it if you prefer to choose a specific identifier.
  53. static const CLSID BASED_CODE clsid =
  54. { 0x56cca20, 0x1a79, 0x11b9, { 0xc0, 0x0, 0xaa, 0x7d, 0x4e, 0x61, 0x9d, 0xec } };
  55.  
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CContainerApp initialization
  58.  
  59. BOOL CContainerApp::InitInstance()
  60. {
  61.     // Initialize OLE libraries
  62.     if (!AfxOleInit())
  63.     {
  64.         AfxMessageBox(IDP_OLE_INIT_FAILED);
  65.         return FALSE;
  66.     }
  67.  
  68.     // Standard initialization
  69.     // If you are not using these features and wish to reduce the size
  70.     //  of your final executable, you should remove from the following
  71.     //  the specific initialization routines you do not need.
  72.  
  73.     Enable3dControls();
  74.  
  75.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  76.  
  77.     // Register the application's document templates.  Document templates
  78.     //  serve as the connection between documents, frame windows and views.
  79.  
  80.     CMultiDocTemplate* pDocTemplate;
  81.     pDocTemplate = new CMultiDocTemplate(
  82.         IDR_CONTTYPE,
  83.         RUNTIME_CLASS(CContainerDoc),
  84.         RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  85.         RUNTIME_CLASS(CContainerView));
  86.     pDocTemplate->SetContainerInfo(IDR_CONTTYPE_CNTR_IP);
  87.     AddDocTemplate(pDocTemplate);
  88.  
  89.     // Connect the COleTemplateServer to the document template.
  90.     //  The COleTemplateServer creates new documents on behalf
  91.     //  of requesting OLE containers by using information
  92.     //  specified in the document template.
  93.     m_server.ConnectTemplate(clsid, pDocTemplate, FALSE);
  94.  
  95.     // Register all OLE server factories as running.  This enables the
  96.     //  OLE libraries to create objects from other applications.
  97.     COleTemplateServer::RegisterAll();
  98.         // Note: MDI applications register all server objects without regard
  99.         //  to the /Embedding or /Automation on the command line.
  100.  
  101.     // create main MDI Frame window
  102.     CMainFrame* pMainFrame = new CMainFrame;
  103.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  104.         return FALSE;
  105.     m_pMainWnd = pMainFrame;
  106.  
  107.     // Enable DDE Execute open
  108.     EnableShellOpen();
  109.     RegisterShellFileTypes();
  110.  
  111.     // Parse the command line to see if launched as OLE server
  112.     if (RunEmbedded() || RunAutomated())
  113.     {
  114.         // Application was run with /Embedding or /Automation.  Don't show the
  115.         //  main window in this case.
  116.         return TRUE;
  117.     }
  118.  
  119.     // When a server application is launched stand-alone, it is a good idea
  120.     //  to update the system registry in case it has been damaged.
  121.     m_server.UpdateRegistry(OAT_DISPATCH_OBJECT);
  122.     COleObjectFactory::UpdateRegistryAll();
  123.  
  124.     // simple command line parsing
  125.     if (m_lpCmdLine[0] == '\0')
  126.     {
  127.         // create a new (empty) document
  128.         OnFileNew();
  129.     }
  130.     else
  131.     {
  132.         // open an existing document
  133.         OpenDocumentFile(m_lpCmdLine);
  134.     }
  135.  
  136.     // Enable drag/drop open
  137.     m_pMainWnd->DragAcceptFiles();
  138.  
  139.     // The main window has been initialized, so show and update it.
  140.     pMainFrame->ShowWindow(m_nCmdShow);
  141.     pMainFrame->UpdateWindow();
  142.  
  143.     return TRUE;
  144. }
  145.  
  146. /////////////////////////////////////////////////////////////////////////////
  147. // CAboutDlg dialog used for App About
  148.  
  149. class CAboutDlg : public CDialog
  150. {
  151. public:
  152.     CAboutDlg();
  153.  
  154. // Dialog Data
  155.     //{{AFX_DATA(CAboutDlg)
  156.     enum { IDD = IDD_ABOUTBOX };
  157.     //}}AFX_DATA
  158.  
  159. // Implementation
  160. protected:
  161.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  162.     //{{AFX_MSG(CAboutDlg)
  163.         // No message handlers
  164.     //}}AFX_MSG
  165.     DECLARE_MESSAGE_MAP()
  166. };
  167.  
  168. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  169. {
  170.     //{{AFX_DATA_INIT(CAboutDlg)
  171.     //}}AFX_DATA_INIT
  172. }
  173.  
  174. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  175. {
  176.     CDialog::DoDataExchange(pDX);
  177.     //{{AFX_DATA_MAP(CAboutDlg)
  178.     //}}AFX_DATA_MAP
  179. }
  180.  
  181. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  182.     //{{AFX_MSG_MAP(CAboutDlg)
  183.         // No message handlers
  184.     //}}AFX_MSG_MAP
  185. END_MESSAGE_MAP()
  186.  
  187. // App command to run the dialog
  188. void CContainerApp::OnAppAbout()
  189. {
  190.     CAboutDlg aboutDlg;
  191.     aboutDlg.DoModal();
  192. }
  193.  
  194. /////////////////////////////////////////////////////////////////////////////
  195. // CContainerApp commands
  196.