home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / ole / oclient / oclient.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  4.1 KB  |  142 lines

  1. // oclient.cpp : Defines the class behaviors for the application.
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-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.  
  14. #include "stdafx.h"
  15. #include <stddef.h>
  16. #include "oclient.h"
  17.  
  18. #include "frame.h"
  19. #include "maindoc.h"
  20. #include "mainview.h"
  21. #include "splitfra.h"
  22.  
  23. #ifdef _DEBUG
  24. #undef THIS_FILE
  25. static char BASED_CODE THIS_FILE[] = __FILE__;
  26. #endif
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. // The one and only COleClientApp object
  30.  
  31. COleClientApp NEAR theApp;
  32.  
  33. // this is the GUID for OCLIENT documents
  34. static const GUID BASED_CODE clsid =
  35.     { 0x00021842, 0, 0, { 0xC0, 0, 0, 0, 0, 0, 0, 0x46 } };
  36.  
  37. /////////////////////////////////////////////////////////////////////////////
  38. // COleClientApp
  39.  
  40. BEGIN_MESSAGE_MAP(COleClientApp, CWinApp)
  41.     //{{AFX_MSG_MAP(COleClientApp)
  42.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  43.     //}}AFX_MSG_MAP
  44.     // Standard file based document commands
  45.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  46.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  47.     // Standard print setup command
  48.     ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  49.     // Global help commands
  50.     ON_COMMAND(ID_HELP_INDEX, CWinApp::OnHelpIndex)
  51.     ON_COMMAND(ID_HELP_USING, CWinApp::OnHelpUsing)
  52.     ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  53.     ON_COMMAND(ID_DEFAULT_HELP, CWinApp::OnHelpIndex)
  54.     ON_COMMAND(ID_CONTEXT_HELP, CWinApp::OnContextHelp)
  55. END_MESSAGE_MAP()
  56.  
  57. /////////////////////////////////////////////////////////////////////////////
  58. // COleClientApp construction
  59. // Place all significant initialization in InitInstance
  60.  
  61. COleClientApp::COleClientApp()
  62. {
  63. }
  64.  
  65. /////////////////////////////////////////////////////////////////////////////
  66. // COleClientApp initialization
  67.  
  68. BOOL COleClientApp::InitInstance()
  69. {
  70. #if defined(_DEBUG) && !defined(_AFX_NO_DEBUG_CRT)
  71.     // turn on extra memory tracking
  72.     afxMemDF |= checkAlwaysMemDF;
  73. #endif
  74.  
  75.     // Initialize OLE 2.0 libraries
  76.     if (!AfxOleInit())
  77.     {
  78.         AfxMessageBox(IDP_AFXOLEINIT_FAILED);
  79.         return FALSE;
  80.     }
  81.  
  82.     // Standard initialization
  83.     Enable3dControls();    // enable 3d controls in dialogs
  84.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  85.  
  86.     // Register document templates
  87.     CMultiDocTemplate* pDocTemplate = new CMultiDocTemplate(IDR_OCLIENTTYPE,
  88.             RUNTIME_CLASS(CMainDoc),
  89.             RUNTIME_CLASS(CSplitFrame),
  90.             RUNTIME_CLASS(CMainView));
  91.     pDocTemplate->SetContainerInfo(IDR_OCLIENTTYPE_CNTR_IP);
  92.     AddDocTemplate(pDocTemplate);
  93.  
  94.     // create main MDI Frame window
  95.     CMainFrame* pMainFrame = new CMainFrame;
  96.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  97.         return FALSE;
  98.     m_pMainWnd = pMainFrame;
  99.  
  100.     // enable file manager drag/drop and DDE Execute open
  101.     m_pMainWnd->DragAcceptFiles();
  102.  
  103.     EnableShellOpen();
  104.     RegisterShellFileTypes(TRUE);
  105.  
  106.     // connect the COleTemplate server to the document template
  107.     m_server.ConnectTemplate(clsid, pDocTemplate, FALSE);
  108.     COleTemplateServer::RegisterAll();
  109.         // Note: MDI applications register all class objects regardless of
  110.         //  the /Embedding on the command line.
  111.  
  112.     // Parse command line for standard shell commands, DDE, file open
  113.     CCommandLineInfo cmdInfo;
  114.     ParseCommandLine(cmdInfo);
  115.  
  116.     if (RunEmbedded())
  117.     {
  118.         // application was run with /Embedding flag.  Instead of showing
  119.         //  the window, the application waits to receive OLE requests.
  120.         return TRUE;
  121.     }
  122.     // always update system registry when run non-embedded
  123.     m_server.UpdateRegistry(OAT_CONTAINER);
  124.  
  125.     // Dispatch commands specified on the command line
  126.     if (!ProcessShellCommand(cmdInfo))
  127.         return FALSE;
  128.  
  129.     pMainFrame->ShowWindow(m_nCmdShow);
  130.     pMainFrame->UpdateWindow();
  131.  
  132.     return TRUE;
  133. }
  134.  
  135. /////////////////////////////////////////////////////////////////////////////
  136. // COleClientApp commands
  137.  
  138. void COleClientApp::OnAppAbout()
  139. {
  140.     CDialog(IDD_ABOUTBOX).DoModal();
  141. }
  142.