home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / source / chap04 / lst42 / lst42.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-26  |  5.4 KB  |  185 lines

  1. // lst42.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "lst42.h"
  6.  
  7. #include "MainFrm.h"
  8. #include "IpFrame.h"
  9. #include "lst42Doc.h"
  10. #include "lst42View.h"
  11.  
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CLst42App
  20.  
  21. BEGIN_MESSAGE_MAP(CLst42App, CWinApp)
  22.     //{{AFX_MSG_MAP(CLst42App)
  23.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  24.         // NOTE - the ClassWizard will add and remove mapping macros here.
  25.         //    DO NOT EDIT what you see in these blocks of generated code!
  26.     //}}AFX_MSG_MAP
  27.     // Standard file based document commands
  28.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  29.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  30.     // Standard print setup command
  31.     ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  32. END_MESSAGE_MAP()
  33.  
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CLst42App construction
  36.  
  37. CLst42App::CLst42App()
  38. {
  39.     // TODO: add construction code here,
  40.     // Place all significant initialization in InitInstance
  41. }
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // The one and only CLst42App object
  45.  
  46. CLst42App theApp;
  47.  
  48. // This identifier was generated to be statistically unique for your app.
  49. // You may change it if you prefer to choose a specific identifier.
  50.  
  51. // {06B70DA0-1818-11D0-A6AD-00AA00602553}
  52. static const CLSID clsid =
  53. { 0x6b70da0, 0x1818, 0x11d0, { 0xa6, 0xad, 0x0, 0xaa, 0x0, 0x60, 0x25, 0x53 } };
  54.  
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CLst42App initialization
  57.  
  58. BOOL CLst42App::InitInstance()
  59. {
  60.     // Initialize OLE libraries
  61.     if (!AfxOleInit())
  62.     {
  63.         AfxMessageBox(IDP_OLE_INIT_FAILED);
  64.         return FALSE;
  65.     }
  66.  
  67.     // Standard initialization
  68.     // If you are not using these features and wish to reduce the size
  69.     //  of your final executable, you should remove from the following
  70.     //  the specific initialization routines you do not need.
  71.  
  72. #ifdef _AFXDLL
  73.     Enable3dControls();            // Call this when using MFC in a shared DLL
  74. #else
  75.     Enable3dControlsStatic();    // Call this when linking to MFC statically
  76. #endif
  77.  
  78.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  79.  
  80.     // Register the application's document templates.  Document templates
  81.     //  serve as the connection between documents, frame windows and views.
  82.  
  83.     CSingleDocTemplate* pDocTemplate;
  84.     pDocTemplate = new CSingleDocTemplate(
  85.         IDR_MAINFRAME,
  86.         RUNTIME_CLASS(CLst42Doc),
  87.         RUNTIME_CLASS(CMainFrame),       // main SDI frame window
  88.         RUNTIME_CLASS(CLst42View));
  89.     pDocTemplate->SetServerInfo(
  90.         IDR_SRVR_EMBEDDED, IDR_SRVR_INPLACE,
  91.         RUNTIME_CLASS(CInPlaceFrame));
  92.     AddDocTemplate(pDocTemplate);
  93.  
  94.     // Connect the COleTemplateServer to the document template.
  95.     //  The COleTemplateServer creates new documents on behalf
  96.     //  of requesting OLE containers by using information
  97.     //  specified in the document template.
  98.     m_server.ConnectTemplate(clsid, pDocTemplate, TRUE);
  99.         // Note: SDI applications register server objects only if /Embedding
  100.         //   or /Automation is present on the command line.
  101.  
  102.     // Parse command line for standard shell commands, DDE, file open
  103.     CCommandLineInfo cmdInfo;
  104.     ParseCommandLine(cmdInfo);
  105.  
  106.     // Check to see if launched as OLE server
  107.     if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
  108.     {
  109.         // Register all OLE server (factories) as running.  This enables the
  110.         //  OLE libraries to create objects from other applications.
  111.         COleTemplateServer::RegisterAll();
  112.  
  113.         // Application was run with /Embedding or /Automation.  Don't show the
  114.         //  main window in this case.
  115.         return TRUE;
  116.     }
  117.  
  118.     // When a server application is launched stand-alone, it is a good idea
  119.     //  to update the system registry in case it has been damaged.
  120.     m_server.UpdateRegistry(OAT_INPLACE_SERVER);
  121.     COleObjectFactory::UpdateRegistryAll();
  122.  
  123.     // When a mini-server is run stand-alone the registry is updated and the
  124.     //  user is instructed to use the Insert Object dialog in a container
  125.     //  to use the server.  Mini-servers do not have stand-alone user interfaces.
  126.     AfxMessageBox(IDP_USE_INSERT_OBJECT);
  127.     return FALSE;
  128. }
  129.  
  130. /////////////////////////////////////////////////////////////////////////////
  131. // CAboutDlg dialog used for App About
  132.  
  133. class CAboutDlg : public CDialog
  134. {
  135. public:
  136.     CAboutDlg();
  137.  
  138. // Dialog Data
  139.     //{{AFX_DATA(CAboutDlg)
  140.     enum { IDD = IDD_ABOUTBOX };
  141.     //}}AFX_DATA
  142.  
  143.     // ClassWizard generated virtual function overrides
  144.     //{{AFX_VIRTUAL(CAboutDlg)
  145.     protected:
  146.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  147.     //}}AFX_VIRTUAL
  148.  
  149. // Implementation
  150. protected:
  151.     //{{AFX_MSG(CAboutDlg)
  152.         // No message handlers
  153.     //}}AFX_MSG
  154.     DECLARE_MESSAGE_MAP()
  155. };
  156.  
  157. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  158. {
  159.     //{{AFX_DATA_INIT(CAboutDlg)
  160.     //}}AFX_DATA_INIT
  161. }
  162.  
  163. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  164. {
  165.     CDialog::DoDataExchange(pDX);
  166.     //{{AFX_DATA_MAP(CAboutDlg)
  167.     //}}AFX_DATA_MAP
  168. }
  169.  
  170. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  171.     //{{AFX_MSG_MAP(CAboutDlg)
  172.         // No message handlers
  173.     //}}AFX_MSG_MAP
  174. END_MESSAGE_MAP()
  175.  
  176. // App command to run the dialog
  177. void CLst42App::OnAppAbout()
  178. {
  179.     CAboutDlg aboutDlg;
  180.     aboutDlg.DoModal();
  181. }
  182.  
  183. /////////////////////////////////////////////////////////////////////////////
  184. // CLst42App commands
  185.