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

  1. // ipdrive.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 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 "ipdrive.h"
  15.  
  16. #include "mainfrm.h"
  17. #include "ipdridoc.h"
  18. #include "ipdrivw.h"
  19.  
  20. #ifdef _DEBUG
  21. #undef THIS_FILE
  22. static char BASED_CODE THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. //This routine is used where you want to dump com exception info, 
  26. //especially in catch blocks 
  27. void dump_com_error(_com_error &e)
  28. {
  29.     _bstr_t bstrSource(e.Source());
  30.     _bstr_t bstrDescription(e.Description());
  31.     TCHAR szTemp[1024];
  32.     CString csMsg = "Oops - hit an error!\n";
  33.     wsprintf(szTemp, _T("Code = %08lx\n"), e.Error());
  34.     csMsg += szTemp;
  35.     wsprintf(szTemp, _T("Code meaning = %s\n"), e.ErrorMessage());
  36.     csMsg += szTemp;
  37.     wsprintf(szTemp, _T("Source = %s\n"), bstrSource.length() ? (LPCTSTR)bstrSource : _T("null"));
  38.     csMsg += szTemp;
  39.     wsprintf(szTemp, _T("Description = %s\n"), bstrDescription.length() ? (LPCTSTR)bstrDescription : _T("null"));
  40.     csMsg += szTemp;
  41.     AfxMessageBox(csMsg);
  42. }
  43.  
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CDriveApp
  46.  
  47. BEGIN_MESSAGE_MAP(CDriveApp, CWinApp)
  48.     //{{AFX_MSG_MAP(CDriveApp)
  49.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  50.         // NOTE - the ClassWizard will add and remove mapping macros here.
  51.         //    DO NOT EDIT what you see in these blocks of generated code!
  52.     //}}AFX_MSG_MAP
  53.     // Standard file based document commands
  54.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  55.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  56. END_MESSAGE_MAP()
  57.  
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CDriveApp construction
  60.  
  61. CDriveApp::CDriveApp()
  62. {
  63.     // TODO: add construction code here,
  64.     // Place all significant initialization in InitInstance
  65. }
  66.  
  67. /////////////////////////////////////////////////////////////////////////////
  68. // The one and only CDriveApp object
  69.  
  70. CDriveApp NEAR theApp;
  71.  
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CDriveApp initialization
  74.  
  75. BOOL CDriveApp::InitInstance()
  76. {
  77.     // Initialize OLE libraries
  78.     if (S_OK != OleInitialize(NULL))
  79.     {
  80.         AfxMessageBox(IDP_OLE_INIT_FAILED);
  81.         return FALSE;
  82.     }
  83.  
  84.     // Standard initialization
  85.     // If you are not using these features and wish to reduce the size
  86.     //  of your final executable, you should remove from the following
  87.     //  the specific initialization routines you do not need.
  88.  
  89. #if (_MFC_VER >= 0x300)
  90.     Enable3dControls();
  91. #else
  92.     SetDialogBkColor();
  93. #endif  
  94.  
  95.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  96.  
  97.     // Register the application's document templates.  Document templates
  98.     //  serve as the connection between documents, frame windows and views.
  99.  
  100.     CSingleDocTemplate* pDocTemplate;
  101.     pDocTemplate = new CSingleDocTemplate(
  102.         IDR_MAINFRAME,
  103.         RUNTIME_CLASS(CDriverDoc),
  104.         RUNTIME_CLASS(CMainFrame),       // main SDI frame window
  105.         RUNTIME_CLASS(CDriverView));
  106.     AddDocTemplate(pDocTemplate);
  107.  
  108.     // create a new (empty) document
  109.     OnFileNew();
  110.  
  111.     if (m_lpCmdLine[0] != '\0')
  112.     {
  113.         // TODO: add command line processing here
  114.     }
  115.  
  116. #ifdef _MAC
  117.     // Enable drag/drop open
  118.     m_pMainWnd->DragAcceptFiles();
  119. #endif
  120.  
  121.     return TRUE;
  122. }
  123.  
  124. /////////////////////////////////////////////////////////////////////////////
  125. //  Clean up at the end of the program
  126.  
  127. int CDriveApp::ExitInstance ()
  128. {
  129.     OleUninitialize();
  130.     return CWinApp::ExitInstance();
  131. }
  132.  
  133. /////////////////////////////////////////////////////////////////////////////
  134. // CAboutDlg dialog used for App About
  135.  
  136. class CAboutDlg : public CDialog
  137. {
  138. public:
  139.     CAboutDlg();
  140.  
  141. // Dialog Data
  142.     //{{AFX_DATA(CAboutDlg)
  143.     enum { IDD = IDD_ABOUTBOX };
  144.     //}}AFX_DATA
  145.  
  146. // Implementation
  147. protected:
  148.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  149.     //{{AFX_MSG(CAboutDlg)
  150.         // No message handlers
  151.     //}}AFX_MSG
  152.     DECLARE_MESSAGE_MAP()
  153. };
  154.  
  155. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  156. {
  157.     //{{AFX_DATA_INIT(CAboutDlg)
  158.     //}}AFX_DATA_INIT
  159. }
  160.  
  161. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  162. {
  163.     CDialog::DoDataExchange(pDX);
  164.     //{{AFX_DATA_MAP(CAboutDlg)
  165.     //}}AFX_DATA_MAP
  166. }
  167.  
  168. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  169.     //{{AFX_MSG_MAP(CAboutDlg)
  170.         // No message handlers
  171.     //}}AFX_MSG_MAP
  172. END_MESSAGE_MAP()
  173.  
  174. // App command to run the dialog
  175. void CDriveApp::OnAppAbout()
  176. {
  177.     CAboutDlg aboutDlg;
  178.     aboutDlg.DoModal();
  179. }
  180.  
  181. /////////////////////////////////////////////////////////////////////////////
  182. // CDriveApp commands
  183.