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 / mainfrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  5.1 KB  |  200 lines

  1. // MainFrm.cpp : implementation of the CMainFrame class
  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. #include "optionsd.h"
  16.  
  17. #include "MainFrm.h"
  18.  
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CMainFrame
  26.  
  27. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  28.  
  29. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  30.     //{{AFX_MSG_MAP(CMainFrame)
  31.     ON_WM_CREATE()
  32.     ON_COMMAND(ID_VIEW_OPTIONS, OnViewOptions)
  33.     ON_COMMAND(ID_APP_CLONE, OnAppClone)
  34.     //}}AFX_MSG_MAP
  35. END_MESSAGE_MAP()
  36.  
  37. static UINT indicators[] =
  38. {
  39.     ID_SEPARATOR,           // status line indicator
  40.     ID_INDICATOR_CAPS,
  41.     ID_INDICATOR_NUM,
  42.     ID_INDICATOR_SCRL,
  43. };
  44.  
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CMainFrame construction/destruction
  47.  
  48. CMainFrame::CMainFrame()
  49. {
  50. }
  51.  
  52. CMainFrame::~CMainFrame()
  53. {
  54. }
  55.  
  56. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  57. {
  58.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  59.         return -1;
  60.  
  61.     if (!m_wndToolBar.Create(this) ||
  62.         !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  63.     {
  64.         TRACE0("Failed to create toolbar\n");
  65.         return -1;      // fail to create
  66.     }
  67.  
  68.     if (!m_wndStatusBar.Create(this) ||
  69.         !m_wndStatusBar.SetIndicators(indicators,
  70.           sizeof(indicators)/sizeof(UINT)))
  71.     {
  72.         TRACE0("Failed to create status bar\n");
  73.         return -1;      // fail to create
  74.     }
  75.  
  76.     // TODO: Delete these three lines if you don't want the toolbar to
  77.     //  be dockable
  78.     m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  79.     EnableDocking(CBRS_ALIGN_ANY);
  80.     DockControlBar(&m_wndToolBar);
  81.  
  82.     // TODO: Remove this if you don't want tool tips
  83.     m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  84.         CBRS_TOOLTIPS | CBRS_FLYBY);
  85.  
  86.     return 0;
  87. }
  88.  
  89. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  90. {
  91.     // TODO: Modify the Window class or styles here by modifying
  92.     //  the CREATESTRUCT cs
  93.  
  94.     return CFrameWnd::PreCreateWindow(cs);
  95. }
  96.  
  97. /////////////////////////////////////////////////////////////////////////////
  98. // CMainFrame diagnostics
  99.  
  100. #ifdef _DEBUG
  101. void CMainFrame::AssertValid() const
  102. {
  103.     CFrameWnd::AssertValid();
  104. }
  105.  
  106. void CMainFrame::Dump(CDumpContext& dc) const
  107. {
  108.     CFrameWnd::Dump(dc);
  109. }
  110.  
  111. #endif //_DEBUG
  112.  
  113. /////////////////////////////////////////////////////////////////////////////
  114. // CMainFrame message handlers
  115.  
  116. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
  117. {
  118.     // create a splitter with 1 row, 2 columns
  119.     if (!m_Splitter.CreateStatic(this, 1, 2))
  120.     {
  121.         TRACE0("Failed to CreateStaticSplitter\n");
  122.         return FALSE;
  123.     }
  124.  
  125.     // add the first splitter pane - the default view in column 0
  126.     if (!m_Splitter.CreateView(0, 0,
  127.         pContext->m_pNewViewClass, CSize(200, 50), pContext))
  128.     {
  129.         TRACE0("Failed to create first pane\n");
  130.         return FALSE;
  131.     }
  132.  
  133.     // add the second splitter pane - an input view in column 1
  134.     if (!m_Splitter.CreateView(0, 1,
  135.         RUNTIME_CLASS(CDaoListView), CSize(0, 0), pContext))
  136.     {
  137.         TRACE0("Failed to create second pane\n");
  138.         return FALSE;
  139.     }
  140.  
  141.     // activate the input view
  142.     SetActiveView((CView*)m_Splitter.GetPane(0,1));
  143.  
  144.     return TRUE;
  145. }
  146.  
  147. void CMainFrame::OnViewOptions()
  148. {
  149.     CPropertySheet propSheet(_T("DaoView - Options"));
  150.     COptionsDlg pageOptions;
  151.     propSheet.AddPage(&pageOptions);
  152.  
  153.     CDaoViewApp* pApp = (CDaoViewApp *)AfxGetApp();
  154.  
  155.     pageOptions.m_bShowWarnings = pApp->m_bShowWarnings;
  156.     pageOptions.m_bShowSystemObjects = pApp->m_bShowSystemObjects;
  157.     pageOptions.m_bOpenODBC= pApp->m_bOpenODBC;
  158.     pageOptions.m_nMaxRecords= pApp->m_nMaxRecords;
  159.  
  160.     if (propSheet.DoModal() == IDOK)
  161.     {
  162.         BOOL bRebuildList = FALSE;
  163.         if (pApp->m_bShowSystemObjects != pageOptions.m_bShowSystemObjects)
  164.             bRebuildList = TRUE;
  165.  
  166.         pApp->m_bShowSystemObjects = pageOptions.m_bShowSystemObjects;
  167.  
  168.         if (bRebuildList)
  169.             ((CDaoViewDoc*) GetActiveDocument())->RefreshViews();
  170.  
  171.         pApp->m_bShowWarnings = pageOptions.m_bShowWarnings;
  172.         pApp->m_bOpenODBC = pageOptions.m_bOpenODBC;
  173.         pApp->m_nMaxRecords = pageOptions.m_nMaxRecords;
  174.     }
  175. }
  176.  
  177.  
  178. void CMainFrame::OnAppClone()
  179. {
  180.     STARTUPINFO si;
  181.     PROCESS_INFORMATION pi;
  182.  
  183.     // Initialize the STARTUPINFO structure.
  184.     memset(&si, 0, sizeof(si));
  185.     si.cb = sizeof(si);
  186.  
  187.     CreateProcess(
  188.         NULL,   // pointer to name of executable module
  189.         (LPTSTR) AfxGetApp()->m_pszAppName, // pointer to command line string
  190.         NULL,   // pointer to process security attributes
  191.         NULL,   // pointer to thread security attributes
  192.         FALSE,  // handle inheritance flag
  193.         0,      // creation flags
  194.         NULL,   // pointer to new environment block
  195.         NULL,   // pointer to current directory name
  196.         &si,    // pointer to STARTUPINFO
  197.         &pi     // pointer to PROCESS_INFORMATION
  198.        );
  199. }
  200.