home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / com / acdual / server / autoclik.cpp < prev    next >
C/C++ Source or Header  |  1998-04-02  |  7KB  |  224 lines

  1. // AutoClik.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. #include "stdafx.h"
  14. #include "AutoClik.h"
  15.  
  16. #include "MainFrm.h"
  17. #include "ChildFrm.h"
  18. #include "AClikDoc.h"
  19. #include "AClikVw.h"
  20.  
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CAutoClickApp
  29.  
  30. BEGIN_MESSAGE_MAP(CAutoClickApp, CWinApp)
  31.     //{{AFX_MSG_MAP(CAutoClickApp)
  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. // CAutoClickApp construction
  45.  
  46. CAutoClickApp::CAutoClickApp()
  47. {
  48.     // TODO: add construction code here,
  49.     // Place all significant initialization in InitInstance
  50. }
  51.  
  52. /////////////////////////////////////////////////////////////////////////////
  53. // The one and only CAutoClickApp object
  54.  
  55. CAutoClickApp theApp;
  56.  
  57.  
  58. // DUAL_SUPPORT_START
  59. // Original Code:
  60. //    // This identifier was generated to be statistically unique for your app.
  61. //    // You may change it if you prefer to choose a specific identifier.
  62. //
  63. //    // {47D53E03-CC33-11CE-8F35-00DD01109044}
  64. //    static const CLSID clsid =
  65. //    { 0x47d53e03, 0xcc33, 0x11ce, { 0x8f, 0x35, 0x0, 0xdd, 0x1, 0x10, 0x90, 0x44 } };
  66.  
  67. // See ACDual.H for the definition of CLSID_Document
  68. // DUAL_SUPPORT_END
  69.  
  70. /////////////////////////////////////////////////////////////////////////////
  71. // CAutoClickApp initialization
  72.  
  73. BOOL CAutoClickApp::InitInstance()
  74. {
  75.     // Initialize OLE libraries
  76.     if (!AfxOleInit())
  77.     {
  78.         AfxMessageBox(IDP_OLE_INIT_FAILED);
  79.         return FALSE;
  80.     }
  81.  
  82.     // Standard initialization
  83.     // If you are not using these features and wish to reduce the size
  84.     //  of your final executable, you should remove from the following
  85.     //  the specific initialization routines you do not need.
  86.  
  87. #ifdef _AFXDLL
  88.     Enable3dControls();                     // Call this when using MFC in a shared DLL
  89. #else
  90.     Enable3dControlsStatic();       // Call this when linking to MFC statically
  91. #endif
  92.  
  93.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  94.  
  95.     // Register the application's document templates.  Document templates
  96.     //  serve as the connection between documents, frame windows and views.
  97.  
  98.     CMultiDocTemplate* pDocTemplate;
  99.     pDocTemplate = new CMultiDocTemplate(
  100.         IDR_ACLICKTYPE,
  101.         RUNTIME_CLASS(CAutoClickDoc),
  102.         RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  103.         RUNTIME_CLASS(CAutoClickView));
  104.     AddDocTemplate(pDocTemplate);
  105.  
  106.     // Connect the COleTemplateServer to the document template.
  107.     //  The COleTemplateServer creates new documents on behalf
  108.     //  of requesting OLE containers by using information
  109.     //  specified in the document template.
  110.  
  111.     // DUAL_SUPPORT_START
  112.     // Original Code:
  113.     //     m_server.ConnectTemplate(clsid, pDocTemplate, FALSE);
  114.     m_server.ConnectTemplate(CLSID_Document, pDocTemplate, FALSE);
  115.     // DUAL_SUPPORT_END
  116.  
  117.     // Register all OLE server factories as running.  This enables the
  118.     //  OLE libraries to create objects from other applications.
  119.     COleTemplateServer::RegisterAll();
  120.         // Note: MDI applications register all server objects without regard
  121.         //  to the /Embedding or /Automation on the command line.
  122.  
  123.     // create main MDI Frame window
  124.     CMainFrame* pMainFrame = new CMainFrame;
  125.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  126.         return FALSE;
  127.     m_pMainWnd = pMainFrame;
  128.  
  129.     // Enable drag/drop open
  130.     m_pMainWnd->DragAcceptFiles();
  131.  
  132.     // Enable DDE Execute open
  133.     EnableShellOpen();
  134.     RegisterShellFileTypes(TRUE);
  135.  
  136.     // Parse command line for standard shell commands, DDE, file open
  137.     CCommandLineInfo cmdInfo;
  138.     ParseCommandLine(cmdInfo);
  139.  
  140.     // Check to see if launched as OLE server
  141.     if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
  142.     {
  143.         // Application was run with /Embedding or /Automation.  Don't show the
  144.         //  main window in this case.
  145.         return TRUE;
  146.     }
  147.  
  148.     // When a server application is launched stand-alone, it is a good idea
  149.     //  to update the system registry in case it has been damaged.
  150.     m_server.UpdateRegistry(OAT_DISPATCH_OBJECT);
  151.     COleObjectFactory::UpdateRegistryAll();
  152.  
  153.     // DUAL_SUPPORT_START
  154.     //    make sure the type library is registerd. Otherwise dual interface won't work!
  155.     AfxOleRegisterTypeLib(AfxGetInstanceHandle(), LIBID_ACDual, _T("AutoClik.TLB"));
  156.     // DUAL_SUPPORT_END
  157.  
  158.     // Dispatch commands specified on the command line
  159.     if (!ProcessShellCommand(cmdInfo))
  160.         return FALSE;
  161.  
  162.     // The main window has been initialized, so show and update it.
  163.     pMainFrame->ShowWindow(m_nCmdShow);
  164.     pMainFrame->UpdateWindow();
  165.  
  166.     return TRUE;
  167. }
  168.  
  169. /////////////////////////////////////////////////////////////////////////////
  170. // CAboutDlg dialog used for App About
  171.  
  172. class CAboutDlg : public CDialog
  173. {
  174. public:
  175.     CAboutDlg();
  176.  
  177. // Dialog Data
  178.     //{{AFX_DATA(CAboutDlg)
  179.     enum { IDD = IDD_ABOUTBOX };
  180.     //}}AFX_DATA
  181.  
  182.     // ClassWizard generated virtual function overrides
  183.     //{{AFX_VIRTUAL(CAboutDlg)
  184.     protected:
  185.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  186.     //}}AFX_VIRTUAL
  187.  
  188. // Implementation
  189. protected:
  190.     //{{AFX_MSG(CAboutDlg)
  191.         // No message handlers
  192.     //}}AFX_MSG
  193.     DECLARE_MESSAGE_MAP()
  194. };
  195.  
  196. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  197. {
  198.     //{{AFX_DATA_INIT(CAboutDlg)
  199.     //}}AFX_DATA_INIT
  200. }
  201.  
  202. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  203. {
  204.     CDialog::DoDataExchange(pDX);
  205.     //{{AFX_DATA_MAP(CAboutDlg)
  206.     //}}AFX_DATA_MAP
  207. }
  208.  
  209. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  210.     //{{AFX_MSG_MAP(CAboutDlg)
  211.         // No message handlers
  212.     //}}AFX_MSG_MAP
  213. END_MESSAGE_MAP()
  214.  
  215. // App command to run the dialog
  216. void CAutoClickApp::OnAppAbout()
  217. {
  218.     CAboutDlg aboutDlg;
  219.     aboutDlg.DoModal();
  220. }
  221.  
  222. /////////////////////////////////////////////////////////////////////////////
  223. // CAutoClickApp commands
  224.