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

  1. // scribble.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 "scribble.h"
  16. #include "mainfrm.h"
  17. #include "scribfrm.h"
  18. #include "ipframe.h"
  19. #include "scribdoc.h"
  20. #include "scribvw.h"
  21.  
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CScribbleApp
  29.  
  30. BEGIN_MESSAGE_MAP(CScribbleApp, CWinApp)
  31.     //{{AFX_MSG_MAP(CScribbleApp)
  32.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  33.         // NOTE - the ClassWizard will add and remove mapping macros here.
  34.         //    DO NOT EDIT what you see in these blocks of generated code !
  35.     //}}AFX_MSG_MAP
  36.     // Standard file based document commands
  37.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  38.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  39.     // Standard print setup command
  40.     ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  41. END_MESSAGE_MAP()
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CScribbleApp construction
  45.  
  46. CScribbleApp::CScribbleApp()
  47. {
  48.     // TODO: add construction code here,
  49.     // Place all significant initialization in InitInstance
  50. }
  51.  
  52. /////////////////////////////////////////////////////////////////////////////
  53. // The one and only CScribbleApp object
  54.  
  55. CScribbleApp theApp;
  56. // This identifier was generated to be statistically unique for your app.
  57. // You may change it if you prefer to choose a specific identifier.
  58.  
  59. //This ID is different than the normal Scribble tutorial
  60. // to assure our uniqueness
  61. static const GUID BASED_CODE clsid =
  62.    { 0x9040eb00, 0x7c29, 0x11ce, { 0x94, 0x66, 0xf4, 0xc9, 0xcb, 0xe2, 0x16, 0x2c }};
  63.  
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CScribbleApp initialization
  66.  
  67. BOOL CScribbleApp::InitInstance()
  68. {
  69.     // Initialize OLE libraries
  70.     if (!AfxOleInit())
  71.     {
  72.         AfxMessageBox(IDP_OLE_INIT_FAILED);
  73.         return FALSE;
  74.     }
  75.  
  76.     // Standard initialization
  77.     // If you are not using these features and wish to reduce the size
  78.     //  of your final executable, you should remove from the following
  79.     //  the specific initialization routines you do not need.
  80.  
  81. #ifdef _AFXDLL
  82.     Enable3dControls();                     // Call this when using MFC in a shared DLL
  83. #else
  84.     Enable3dControlsStatic();       // Call this when linking to MFC statically
  85. #endif
  86.  
  87.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  88.  
  89.     // Register the application's document templates.  Document templates
  90.     //  serve as the connection between documents, frame windows and views.
  91.  
  92.     CMultiDocTemplate* pDocTemplate;
  93.     pDocTemplate = new CMultiDocTemplate(
  94.         IDR_SCRIBTYPE,
  95.         RUNTIME_CLASS(CScribDoc),
  96.         RUNTIME_CLASS(CScribFrame),     // MDI child frame with splitter wnd
  97.         RUNTIME_CLASS(CScribView));
  98.  
  99.     pDocTemplate->SetServerInfo(
  100.         IDR_SCRIBTYPE_SRVR_EMB, IDR_SCRIBTYPE_SRVR_IP,
  101.         RUNTIME_CLASS(CInPlaceFrame));
  102.     AddDocTemplate(pDocTemplate);
  103.  
  104.     // Connect the COleTemplateServer to the document template.
  105.     //  The COleTemplateServer creates new documents on behalf
  106.     //  of requesting OLE containers by using information
  107.     //  specified in the document template.
  108.     m_server.ConnectTemplate(clsid, pDocTemplate, FALSE);
  109.  
  110.     // Register all OLE server factories as running.  This enables the
  111.     //  OLE libraries to create objects from other applications.
  112.     COleTemplateServer::RegisterAll();
  113.     // Note: MDI applications register all server objects without regard
  114.     //   to the /Embedding or /Automation on the command line.
  115.  
  116.     // create main MDI Frame window
  117.     CMainFrame* pMainFrame = new CMainFrame;
  118.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  119.         return FALSE;
  120.     m_pMainWnd = pMainFrame;
  121.  
  122.     // Enable DDE Execute open
  123.     EnableShellOpen();
  124.     RegisterShellFileTypes();
  125.  
  126.     // Parse command line for standard shell commands, DDE, file open
  127.     CCommandLineInfo cmdInfo;
  128.     ParseCommandLine(cmdInfo);
  129.  
  130.     // Check to see if launched as OLE server
  131.     if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
  132.     {
  133.         // Application was run with /Embedding or /Automation.  Don't show the
  134.         //  main window in this case.
  135.         return TRUE;
  136.     }
  137.  
  138.     // When a server application is launched stand-alone, it is a good idea
  139.     //  to update the system registry in case it has been damaged.
  140.  
  141.     m_server.UpdateRegistry(OAT_DOC_OBJECT_SERVER);
  142.  
  143.     // Dispatch commands specified on the command line
  144.     if (!ProcessShellCommand(cmdInfo))
  145.         return FALSE;
  146.  
  147.     // The main window has been initialized, so show and update it.
  148.     pMainFrame->ShowWindow(m_nCmdShow);
  149.     pMainFrame->UpdateWindow();
  150.  
  151.     return TRUE;
  152. }
  153.  
  154. /////////////////////////////////////////////////////////////////////////////
  155. // CAboutDlg dialog used for App About
  156.  
  157. class CAboutDlg : public CDialog
  158. {
  159. public:
  160.     CAboutDlg();
  161.  
  162. // Dialog Data
  163.     //{{AFX_DATA(CAboutDlg)
  164.     enum { IDD = IDD_ABOUTBOX };
  165.     //}}AFX_DATA
  166.  
  167. // Implementation
  168. protected:
  169.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  170.     //{{AFX_MSG(CAboutDlg)
  171.         // No message handlers
  172.     //}}AFX_MSG
  173.     DECLARE_MESSAGE_MAP()
  174. };
  175.  
  176. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  177. {
  178.     //{{AFX_DATA_INIT(CAboutDlg)
  179.     //}}AFX_DATA_INIT
  180. }
  181.  
  182. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  183. {
  184.     CDialog::DoDataExchange(pDX);
  185.     //{{AFX_DATA_MAP(CAboutDlg)
  186.     //}}AFX_DATA_MAP
  187. }
  188.  
  189. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  190.     //{{AFX_MSG_MAP(CAboutDlg)
  191.         // No message handlers
  192.     //}}AFX_MSG_MAP
  193. END_MESSAGE_MAP()
  194.  
  195. // App command to run the dialog
  196. void CScribbleApp::OnAppAbout()
  197. {
  198.     CAboutDlg aboutDlg;
  199.     aboutDlg.DoModal();
  200. }
  201.  
  202. /////////////////////////////////////////////////////////////////////////////
  203. // CScribbleApp commands
  204.