MAINFRM.CPP
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:5k
源码类别:

Windows编程

开发平台:

Visual C++

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