home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / atl / mfcatl / mfcatl.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  3KB  |  108 lines

  1. // MfcAtl.cpp : Defines the class behaviors for the application.
  2. //
  3. // This is a part of the Active Template Library.
  4. // Copyright (C) 1996-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Active Template Library Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Active Template Library product.
  12.  
  13. #include "premfcat.h"
  14. #include "MfcAtl.h"
  15. #include "MfcAtlDl.h"
  16. #include "interf.h"
  17. #include "ObjTwo.h"
  18.  
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. // ATL Global Module only instance
  26. CAtlGlobalModule _Module;
  27.  
  28. // ATL GLobal Object Map
  29. BEGIN_OBJECT_MAP(ObjectMap)
  30.     OBJECT_ENTRY(CLSID_ObjectTwo, CObjectTwo)
  31. END_OBJECT_MAP()
  32.  
  33.  
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CMfcAtlApp
  36.  
  37. BEGIN_MESSAGE_MAP(CMfcAtlApp, CWinApp)
  38.     //{{AFX_MSG_MAP(CMfcAtlApp)
  39.         // NOTE - the ClassWizard will add and remove mapping macros here.
  40.         //    DO NOT EDIT what you see in these blocks of generated code!
  41.     //}}AFX_MSG
  42.     ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  43. END_MESSAGE_MAP()
  44.  
  45. /////////////////////////////////////////////////////////////////////////////
  46. // The one and only CMfcAtlApp object
  47.  
  48. CMfcAtlApp theApp;
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CMfcAtlApp initialization
  52.  
  53. BOOL CMfcAtlApp::InitInstance()
  54. {
  55.     // Initialize OLE libraries
  56.     if (!AfxOleInit())
  57.     {
  58.         AfxMessageBox(IDP_OLE_INIT_FAILED);
  59.         return FALSE;
  60.     }
  61.  
  62.     // Initialize the ATL Module
  63.     _Module.Init(ObjectMap,m_hInstance);
  64.  
  65. #ifdef _AFXDLL
  66.     Enable3dControls();         // Call this when using MFC in a shared DLL
  67. #else
  68.     Enable3dControlsStatic();   // Call this when linking to MFC statically
  69. #endif
  70.  
  71.     // Update the System Registry
  72.     COleObjectFactory::UpdateRegistryAll();         // MFC Classes
  73.     VERIFY(SUCCEEDED(_Module.RegisterServer(TRUE)));// ATL Classes
  74.  
  75.     // create the modeless dialog, originally hidden
  76.     CMfcAtlDlg* pDlg = new CMfcAtlDlg;
  77.     if (!pDlg->Create(IDD_MFCATL_DIALOG))
  78.     {
  79.         delete pDlg;
  80.         return FALSE;
  81.     }
  82.     m_pMainWnd = pDlg;
  83.  
  84.     // Register OLE Class Factories
  85.     // MFC ones are for multiple as specified by the IMPLEMENT_OLECREATE() macro
  86.     COleObjectFactory::RegisterAll();
  87.     // ATL ones specifically register with REGCLS_MULTIPLEUSE
  88.     VERIFY(SUCCEEDED(_Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE)));
  89.  
  90.     // Parse the command line to see if launched as OLE server
  91.     if (RunEmbedded() || RunAutomated())
  92.     {
  93.         // Application was run with /Embedding or /Automation.  Don't show the
  94.         //  main window in this case.
  95.         return TRUE;
  96.     }
  97.     pDlg->ShowWindow(m_nCmdShow);
  98.     return TRUE;
  99. }
  100.  
  101. int CMfcAtlApp::ExitInstance()
  102. {
  103.     // MFC's class factories registration is automatically revoked by MFC itself
  104.     _Module.RevokeClassObjects(); // Revoke class factories for ATL
  105.     _Module.Term();               // clanup ATL GLobal Module
  106.     return CWinApp::ExitInstance();
  107. }
  108.