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

  1. // DaoView.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. #include "stdafx.h"
  14. #include "DaoView.h"
  15.  
  16. #include "MainFrm.h"
  17.  
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CDaoViewApp
  25.  
  26. BEGIN_MESSAGE_MAP(CDaoViewApp, CWinApp)
  27.     //{{AFX_MSG_MAP(CDaoViewApp)
  28.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  29.         // NOTE - the ClassWizard will add and remove mapping macros here.
  30.         //    DO NOT EDIT what you see in these blocks of generated code!
  31.     //}}AFX_MSG_MAP
  32.     // Standard file based document commands
  33.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  34.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  35. END_MESSAGE_MAP()
  36.  
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CDaoViewApp construction
  39.  
  40. CDaoViewApp::CDaoViewApp()
  41. {
  42.     m_bShowSystemObjects = FALSE;
  43.     m_bShowWarnings = TRUE;
  44.     m_bOpenODBC = FALSE;
  45.     m_nMaxRecords = 100;
  46. }
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49. // The one and only CDaoViewApp object
  50.  
  51. CDaoViewApp theApp;
  52.  
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CDaoViewApp initialization
  55.  
  56. BOOL CDaoViewApp::InitInstance()
  57. {
  58.     if(!AfxOleInit()){
  59.         AfxMessageBox(_T("Ole Initialization failed"));
  60.         return FALSE;
  61.     }
  62.  
  63. #ifdef _AFXDLL
  64.     Enable3dControls();         // Call this when using MFC in a shared DLL
  65. #else
  66.     Enable3dControlsStatic();   // Call this when linking to MFC statically
  67. #endif
  68.  
  69.     LoadStdProfileSettings(6);  // Load standard INI file options (including MRU)
  70.  
  71.     // Register the application's document templates.  Document templates
  72.     //  serve as the connection between documents, frame windows and views.
  73.  
  74.     CSingleDocTemplate* pDocTemplate;
  75.     pDocTemplate = new CSingleDocTemplate(
  76.         IDR_MAINFRAME,
  77.         RUNTIME_CLASS(CDaoViewDoc),
  78.         RUNTIME_CLASS(CMainFrame),       // main SDI frame window
  79.         RUNTIME_CLASS(CDaoTreeView));
  80.     AddDocTemplate(pDocTemplate);
  81.  
  82.     // Enable DDE Execute open
  83.     EnableShellOpen();
  84.     RegisterShellFileTypes(TRUE);
  85.  
  86.     // Parse command line for standard shell commands, DDE, file open
  87.     CCommandLineInfo cmdInfo;
  88.     ParseCommandLine(cmdInfo);
  89.     // Dispatch commands specified on the command line
  90.     if (!ProcessShellCommand(cmdInfo))
  91.         return FALSE;
  92.  
  93.     // Enable drag/drop open
  94.     m_pMainWnd->DragAcceptFiles();
  95.  
  96.     return TRUE;
  97. }
  98.  
  99. /////////////////////////////////////////////////////////////////////////////
  100. // CAboutDlg dialog used for App About
  101.  
  102. class CAboutDlg : public CDialog
  103. {
  104. public:
  105.     CAboutDlg();
  106.  
  107. // Dialog Data
  108.     //{{AFX_DATA(CAboutDlg)
  109.     enum { IDD = IDD_ABOUTBOX };
  110.     //}}AFX_DATA
  111.  
  112. // Implementation
  113. protected:
  114.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  115.     //{{AFX_MSG(CAboutDlg)
  116.     virtual BOOL OnInitDialog();
  117.     //}}AFX_MSG
  118.     DECLARE_MESSAGE_MAP()
  119. };
  120.  
  121. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  122. {
  123.     //{{AFX_DATA_INIT(CAboutDlg)
  124.     //}}AFX_DATA_INIT
  125. }
  126.  
  127. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  128. {
  129.     CDialog::DoDataExchange(pDX);
  130.     //{{AFX_DATA_MAP(CAboutDlg)
  131.     //}}AFX_DATA_MAP
  132. }
  133.  
  134. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  135.     //{{AFX_MSG_MAP(CAboutDlg)
  136.     //}}AFX_MSG_MAP
  137. END_MESSAGE_MAP()
  138.  
  139. // App command to run the dialog
  140. void CDaoViewApp::OnAppAbout()
  141. {
  142.     CAboutDlg aboutDlg;
  143.     aboutDlg.DoModal();
  144. }
  145.  
  146. /////////////////////////////////////////////////////////////////////////////
  147. // CDaoViewApp commands
  148.  
  149. BOOL CAboutDlg::OnInitDialog()
  150. {
  151.     CDialog::OnInitDialog();
  152.  
  153.     CDaoWorkspace ws;
  154.     try
  155.     {
  156.         ws.Create(_T("VersionWorkspace"),_T("Admin"),_T(""));
  157.         GetDlgItem(IDC_VERSION)->SetWindowText(ws.GetVersion());
  158.     }
  159.     catch (CDaoException* e)
  160.     {
  161.         e->ReportError();
  162.         e->Delete();
  163.     }
  164.     return TRUE;  // return TRUE unless you set the focus to a control
  165.                   // EXCEPTION: OCX Property Pages should return FALSE
  166. }
  167.  
  168. /////////////////////////////////////////////////////////////////////////////
  169. // CDaoViewApp commands
  170.  
  171. void DisplayDaoException(CDaoException* e)
  172. {
  173.     CString strMsg;
  174.     if (e->m_pErrorInfo!=NULL)
  175.     {
  176.         strMsg.Format(
  177.             _T("%s   (%d)\n\n")
  178.             _T("Would you like to see help?"),
  179.             (LPCTSTR)e->m_pErrorInfo->m_strDescription,
  180.             e->m_pErrorInfo->m_lErrorCode);
  181.  
  182.         if (AfxMessageBox(strMsg, MB_YESNO) == IDYES)
  183.         {
  184.             WinHelp(GetDesktopWindow(),
  185.                     e->m_pErrorInfo->m_strHelpFile,
  186.                     HELP_CONTEXT,
  187.                     e->m_pErrorInfo->m_lHelpContext);
  188.         }
  189.     }
  190.     else
  191.     {
  192.         strMsg.Format(
  193.             _T("ERROR:CDaoException\n\n")
  194.             _T("SCODE_CODE      =%d\n")
  195.             _T("SCODE_FACILITY  =%d\n")
  196.             _T("SCODE_SEVERITY  =%d\n")
  197.             _T("ResultFromScode =%d\n"),
  198.             SCODE_CODE      (e->m_scode),
  199.             SCODE_FACILITY  (e->m_scode),
  200.             SCODE_SEVERITY  (e->m_scode),
  201.             ResultFromScode (e->m_scode));
  202.         AfxMessageBox(strMsg);
  203.     }
  204. }
  205.