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

  1. // hiersvr.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 "hiersvr.h"
  16.  
  17. #include "mainfrm.h"
  18. #include "ipframe.h"
  19. #include "svrdoc.h"
  20. #include "svrview.h"
  21.  
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CServerApp
  29.  
  30. BEGIN_MESSAGE_MAP(CServerApp, CWinApp)
  31.     //{{AFX_MSG_MAP(CServerApp)
  32.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  33.     //}}AFX_MSG_MAP
  34.     // Standard file based document commands
  35.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  36.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  37. END_MESSAGE_MAP()
  38.  
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CServerApp construction
  41. // Place all significant initialization in InitInstance
  42.  
  43. CServerApp::CServerApp()
  44. {
  45. }
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // The one and only CServerApp object
  49.  
  50. CServerApp theApp;
  51.  
  52. // this is the GUID for HIERSVR documents
  53. static const GUID BASED_CODE clsid =
  54.     { 0x00021841, 0, 0, { 0xC0, 0, 0, 0, 0, 0, 0, 0x46 } };
  55.  
  56. /////////////////////////////////////////////////////////////////////////////
  57. //
  58.  
  59. CHierSvrDocTemplate::CHierSvrDocTemplate()
  60. : CMultiDocTemplate(IDR_HIERSVRTYPE,
  61.     RUNTIME_CLASS(CServerDoc),
  62.     RUNTIME_CLASS(CMDIChildWnd), // standard MDI child frame
  63.     RUNTIME_CLASS(CServerView))
  64. {
  65. }
  66.  
  67. CDocTemplate::Confidence CHierSvrDocTemplate::MatchDocType(LPCTSTR lpszPathName,
  68.     CDocument*& rpDocMatch)
  69. {
  70.     CDocTemplate::Confidence ret;
  71.  
  72.     ret = CMultiDocTemplate::MatchDocType(lpszPathName, rpDocMatch);
  73.  
  74.     if (ret == CDocTemplate::yesAttemptForeign)
  75.         ret = CDocTemplate::noAttempt;
  76.  
  77.     return ret;
  78. }
  79.  
  80. /////////////////////////////////////////////////////////////////////////////
  81. // CServerApp initialization
  82.  
  83. BOOL CServerApp::InitInstance()
  84. {
  85. #ifdef _DEBUG
  86.     // turn on extra memory tracking
  87.     afxMemDF |= checkAlwaysMemDF;
  88. #endif
  89.  
  90.     // OLE 2.0 initialization
  91.     if (!AfxOleInit())
  92.     {
  93.         AfxMessageBox(IDP_AFXOLEINIT_FAILED);
  94.         return FALSE;
  95.     }
  96.  
  97.     // Standard initialization
  98.     Enable3dControls();
  99.     LoadStdProfileSettings();
  100.  
  101.     // Register document templates
  102.     CDocTemplate* pDocTemplate;
  103.     pDocTemplate = new CHierSvrDocTemplate;
  104.     pDocTemplate->SetServerInfo(
  105.         IDR_HIERSVRTYPE_SRVR_EMB, IDR_HIERSVRTYPE_SRVR_IP,
  106.         RUNTIME_CLASS(CInPlaceFrame), RUNTIME_CLASS(CServerView));
  107.     AddDocTemplate(pDocTemplate);
  108.  
  109.     // create main MDI Frame window
  110.     CMainFrame* pMainFrame = new CMainFrame;
  111.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  112.         return FALSE;
  113.     m_pMainWnd = pMainFrame;
  114.  
  115.     // enable file manager drag/drop and DDE Execute open
  116.     m_pMainWnd->DragAcceptFiles();
  117.     EnableShellOpen();
  118.  
  119.     // connect the COleTemplate server to the document template
  120.     m_server.ConnectTemplate(clsid, pDocTemplate, FALSE);
  121.     COleTemplateServer::RegisterAll();
  122.         // Note: MDI applications register all class objects regardless of
  123.         //  the /Embedding on the command line.
  124.  
  125.     // Parse command line for standard shell commands, DDE, file open
  126.     CCommandLineInfo cmdInfo;
  127.     ParseCommandLine(cmdInfo);
  128.  
  129.     // try to launch as an OLE server
  130.     if (cmdInfo.m_bRunEmbedded)
  131.     {
  132.         // application was run with /Embedding flag.  Instead of showing
  133.         //  the window, the application waits to receive OLE requests.
  134.         return TRUE;
  135.     }
  136.  
  137.     m_server.UpdateRegistry();
  138.     RegisterShellFileTypes(TRUE);
  139.     COleObjectFactory::UpdateRegistryAll();
  140.  
  141.     // Dispatch commands specified on the command line
  142.     if (!ProcessShellCommand(cmdInfo))
  143.         return FALSE;
  144.  
  145.     pMainFrame->ShowWindow(m_nCmdShow);
  146.     pMainFrame->UpdateWindow();
  147.  
  148.     return TRUE;
  149. }
  150.  
  151. int CServerApp::ExitInstance()
  152. {
  153.     return CWinApp::ExitInstance();
  154. }
  155.  
  156. /////////////////////////////////////////////////////////////////////////////
  157. // CAboutDlg dialog used for App About
  158.  
  159. class CAboutDlg : public CDialog
  160. {
  161. public:
  162.     CAboutDlg() : CDialog(CAboutDlg::IDD)
  163.     {
  164.     //{{AFX_DATA_INIT(CAboutDlg)
  165.     //}}AFX_DATA_INIT
  166.     }
  167.  
  168. // Dialog Data
  169.     //{{AFX_DATA(CAboutDlg)
  170.     enum { IDD = IDD_ABOUTBOX };
  171.     //}}AFX_DATA
  172.  
  173. // Implementation
  174. protected:
  175.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  176.     //{{AFX_MSG(CAboutDlg)
  177.         // No message handlers
  178.     //}}AFX_MSG
  179.     DECLARE_MESSAGE_MAP()
  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 CServerApp::OnAppAbout()
  197. {
  198.     CAboutDlg aboutDlg;
  199.     aboutDlg.DoModal();
  200. }
  201.  
  202. /////////////////////////////////////////////////////////////////////////////
  203. // CServerApp commands
  204.