home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / appwiz / hierwiz / template / root.cpp < prev    next >
C/C++ Source or Header  |  1998-03-05  |  6KB  |  224 lines

  1. // $$root$$.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-1995 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 Microsoft
  9. // QuickHelp and/or WinHelp 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 "$$root$$.h"
  16. $$IF(WANTS_TEXTVIEW)
  17. #include "textview.h"
  18. $$ENDIF //WANTS_TEXTVIEW
  19. #include "mainfrm.h"
  20. #include "ipframe.h"
  21. #include "svrdoc.h"
  22. #include "svrview.h"
  23.  
  24. #ifdef _DEBUG
  25. #undef THIS_FILE
  26. static char BASED_CODE THIS_FILE[] = __FILE__;
  27. #endif
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CServerApp
  31.  
  32. BEGIN_MESSAGE_MAP(CServerApp, CWinApp)
  33.     //{{AFX_MSG_MAP(CServerApp)
  34.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  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. END_MESSAGE_MAP()
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CServerApp construction
  43. // Place all significant initialization in InitInstance
  44.  
  45. CServerApp::CServerApp()
  46. {
  47. }
  48.  
  49. /////////////////////////////////////////////////////////////////////////////
  50. // The one and only CServerApp object
  51.  
  52. CServerApp NEAR theApp;
  53.  
  54. // this is the GUID for HIERSVR documents
  55. static const GUID BASED_CODE clsid =
  56.     { 0x00021821, 0, 0, { 0xC0, 0, 0, 0, 0, 0, 0, 0x46 } };
  57.  
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CServerApp initialization
  60.  
  61. BOOL CServerApp::InitInstance()
  62. {
  63.     CString Commandline ;
  64.  
  65. #ifdef _DEBUG
  66.     // turn on extra memory tracking
  67.     afxMemDF |= checkAlwaysMemDF;
  68. #endif
  69.  
  70.     // OLE 2.0 initialization
  71.     if (!AfxOleInit())
  72.     {
  73.         AfxMessageBox(IDP_AFXOLEINIT_FAILED);
  74.         return FALSE;
  75.     }
  76.  
  77. $$IF(USER_INPUT_DATA)
  78.     // Sample document
  79.     m_iWantDefDoc = TRUE ;
  80.     m_DefaultDoc = "$$root$$.txt" ;
  81. $$ENDIF //USER_INPUT_DATA
  82. $$IF(OPEN_FILE)
  83.     m_DefaultDoc = "$$hiersample$$" ;
  84.     Commandline = m_lpCmdLine ;
  85.     if(Commandline.IsEmpty())
  86.         Commandline = m_DefaultDoc ;
  87. $$ENDIF //OPEN_FILE
  88.     // Standard initialization
  89.     Enable3dControls();
  90.     LoadStdProfileSettings();
  91.  
  92.     // Register document templates
  93.     pDocTemplate = new CMultiDocTemplate(IDR_HIERSVRTYPE,
  94.             RUNTIME_CLASS(CServerDoc),
  95.             RUNTIME_CLASS(CMDIChildWnd),    // standard MDI child frame
  96.             RUNTIME_CLASS(CServerView));
  97.  
  98. $$IF(WANTS_TEXTVIEW)
  99.     // Add a CEditview
  100.     pDocTxtTemplate = new CMultiDocTemplate(IDR_HIERSVRTYPE,
  101.             RUNTIME_CLASS(CServerDoc),
  102.             RUNTIME_CLASS(CMDIChildWnd),    // standard MDI child frame
  103.             RUNTIME_CLASS(CTextView));
  104. $$ENDIF
  105.     pDocTemplate->SetServerInfo(
  106.         IDR_HIERSVRTYPE_SRVR_EMB, IDR_HIERSVRTYPE_SRVR_IP,
  107.         RUNTIME_CLASS(CInPlaceFrame), RUNTIME_CLASS(CServerView));
  108.  
  109.     AddDocTemplate(pDocTemplate);
  110. $$IF(WANTS_TEXTVIEW)
  111.     AddDocTemplate(pDocTxtTemplate) ;
  112. $$ENDIF
  113.  
  114.     // create main MDI Frame window
  115.     CMainFrame* pMainFrame = new CMainFrame;
  116.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  117.         return FALSE;
  118.     m_pMainWnd = pMainFrame;
  119.  
  120.     // enable file manager drag/drop and DDE Execute open
  121.     m_pMainWnd->DragAcceptFiles();
  122.     EnableShellOpen();
  123.  
  124.     // connect the COleTemplate server to the document template
  125.     m_server.ConnectTemplate(clsid, pDocTemplate, FALSE);
  126.     COleTemplateServer::RegisterAll();
  127.         // Note: MDI applications register all class objects regardless of
  128.         //  the /Embedding on the command line.
  129.  
  130.     // try to launch as an OLE server
  131.     if (RunEmbedded())
  132.     {
  133.         // application was run with /Embedding flag.  Instead of showing
  134.         //  the window, the application waits to receive OLE requests.
  135.         return TRUE;
  136.     }
  137.     m_server.UpdateRegistry();
  138.     RegisterShellFileTypes();
  139.  
  140.     if (Commandline.IsEmpty())
  141.     {
  142.         // create a new (empty) document using the default view.
  143.         pDocTemplate->OpenDocumentFile(NULL);
  144. $$IF(USER_INPUT_DATA)
  145.         CServerView * pSrvView = (CServerView *)((pMainFrame->GetActiveFrame()))->GetActiveView() ;
  146.         pSrvView->OpenTextFile(m_DefaultDoc) ;
  147.         //Display a text view and tile the windows.
  148.         pSrvView->CreateTextView() ;
  149.         pMainFrame->MDITile() ;
  150. $$ENDIF //USER_INPUT_DATA
  151.     }
  152.     else
  153.     {
  154.         // open an existing document
  155.         OpenDocumentFile(Commandline);
  156. $$IF(WANTS_TEXTVIEW)
  157.         //Display a text view and tile the windows.
  158.         CServerView * pSrvView = (CServerView *)((pMainFrame->GetActiveFrame()))->GetActiveView() ;
  159.         pSrvView->CreateTextView() ;
  160.         pMainFrame->MDITile() ;
  161. $$ENDIF
  162.  
  163.     }
  164.  
  165.     pMainFrame->ShowWindow(m_nCmdShow);
  166.     pMainFrame->UpdateWindow();
  167.  
  168.     return TRUE;
  169. }
  170.  
  171. int CServerApp::ExitInstance()
  172. {
  173.     return CWinApp::ExitInstance();
  174. }
  175.  
  176. /////////////////////////////////////////////////////////////////////////////
  177. // CAboutDlg dialog used for App About
  178.  
  179. class CAboutDlg : public CDialog
  180. {
  181. public:
  182.     CAboutDlg() : CDialog(CAboutDlg::IDD)
  183.     {
  184.     //{{AFX_DATA_INIT(CAboutDlg)
  185.     //}}AFX_DATA_INIT
  186.     }
  187.  
  188. // Dialog Data
  189.     //{{AFX_DATA(CAboutDlg)
  190.     enum { IDD = IDD_ABOUTBOX };
  191.     //}}AFX_DATA
  192.  
  193. // Implementation
  194. protected:
  195.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  196.     //{{AFX_MSG(CAboutDlg)
  197.         // No message handlers
  198.     //}}AFX_MSG
  199.     DECLARE_MESSAGE_MAP()
  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 CServerApp::OnAppAbout()
  217. {
  218.     CAboutDlg aboutDlg;
  219.     aboutDlg.DoModal();
  220. }
  221.  
  222. /////////////////////////////////////////////////////////////////////////////
  223. // CServerApp commands
  224.