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 "collect.h"
  14. #include "mainfrm.h"
  15. #include "colledoc.h"
  16. #include "strlstvw.h"
  17. #include "typlstvw.h"
  18. #include "intlstvw.h"
  19. #include "dwarryvw.h"
  20. #include "typaryvw.h"
  21. #include "ptarryvw.h"
  22. #include "mapssvw.h"
  23. #include "typtrmap.h"
  24. #include "mapdwvw.h"
  25. #ifdef _DEBUG
  26. #undef THIS_FILE
  27. static char BASED_CODE THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CMainFrame
  31. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  32. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  33. ON_COMMAND_RANGE(ID_STRINGLIST, ID_MAP, OnExample)
  34. ON_UPDATE_COMMAND_UI_RANGE(ID_STRINGLIST, ID_MAP, OnUpdateExampleUI)
  35. //{{AFX_MSG_MAP(CMainFrame)
  36. ON_WM_CREATE()
  37. //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. // arrays of IDs used to initialize control bars
  41. // toolbar buttons - IDs are command buttons
  42. static UINT BASED_CODE buttons[] =
  43. {
  44. // same order as in the bitmap 'toolbar.bmp'
  45. ID_FILE_NEW,
  46. ID_FILE_OPEN,
  47. ID_FILE_SAVE,
  48. ID_SEPARATOR,
  49. ID_EDIT_CUT,
  50. ID_EDIT_COPY,
  51. ID_EDIT_PASTE,
  52. ID_SEPARATOR,
  53. ID_FILE_PRINT,
  54. ID_APP_ABOUT,
  55. };
  56. static UINT BASED_CODE indicators[] =
  57. {
  58. ID_SEPARATOR,           // status line indicator
  59. ID_INDICATOR_CAPS,
  60. ID_INDICATOR_NUM,
  61. ID_INDICATOR_SCRL,
  62. };
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CMainFrame construction/destruction
  65. CMainFrame::CMainFrame()
  66. {
  67. m_nCurrentExample = ID_STRINGLIST;
  68. }
  69. CMainFrame::~CMainFrame()
  70. {
  71. }
  72. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  73. {
  74. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  75. return -1;
  76. if (!m_wndToolBar.Create(this) ||
  77. !m_wndToolBar.LoadBitmap(IDR_MAINFRAME) ||
  78. !m_wndToolBar.SetButtons(buttons,
  79.   sizeof(buttons)/sizeof(UINT)))
  80. {
  81. TRACE0("Failed to create toolbarn");
  82. return -1;      // fail to create
  83. }
  84. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  85. EnableDocking(CBRS_ALIGN_ANY);
  86. DockControlBar(&m_wndToolBar);
  87. if (!m_wndStatusBar.Create(this) ||
  88. !m_wndStatusBar.SetIndicators(indicators,
  89.   sizeof(indicators)/sizeof(UINT)))
  90. {
  91. TRACE0("Failed to create status barn");
  92. return -1;      // fail to create
  93. }
  94. return 0;
  95. }
  96. /////////////////////////////////////////////////////////////////////////////
  97. // CMainFrame diagnostics
  98. #ifdef _DEBUG
  99. void CMainFrame::AssertValid() const
  100. {
  101. CFrameWnd::AssertValid();
  102. }
  103. void CMainFrame::Dump(CDumpContext& dc) const
  104. {
  105. CFrameWnd::Dump(dc);
  106. }
  107. #endif //_DEBUG
  108. /////////////////////////////////////////////////////////////////////////////
  109. // CMainFrame message handlers
  110. void CMainFrame::OnExample(UINT nCmdID)
  111. {
  112. if (nCmdID == m_nCurrentExample)
  113. return;  // already selected
  114. // Set the child window ID of the active view to AFX_IDW_PANE_FIRST.
  115. // This is necessary so that CFrameWnd::RecalcLayout will allocate
  116. // this "first pane" to that portion of the frame window's client
  117. // area not allocated to control bars.  Set the child ID of
  118. // the previously active view to some other ID; we will use the
  119. // command ID as the child ID.
  120. CView* pOldActiveView = GetActiveView();
  121. ::SetWindowLong(pOldActiveView->m_hWnd, GWL_ID, m_nCurrentExample);
  122. CRuntimeClass* pNewViewClass;
  123. switch (nCmdID)
  124. {
  125. case ID_STRINGLIST:
  126. pNewViewClass = RUNTIME_CLASS(CStringListView);
  127. break;
  128. case ID_TYPEDLIST:
  129. pNewViewClass = RUNTIME_CLASS(CTypedPtrListView);
  130. break;
  131. case ID_INTLIST:
  132. pNewViewClass = RUNTIME_CLASS(CIntListView);
  133. break;
  134. case ID_DWORDARRAY:
  135. pNewViewClass = RUNTIME_CLASS(CDWordArrayView);
  136. break;
  137. case ID_TYPEDPTRARRAY:
  138. pNewViewClass = RUNTIME_CLASS(CTypedPtrArrayView);
  139. break;
  140. case ID_POINTARRAY:
  141. pNewViewClass = RUNTIME_CLASS(CPointArrayView);
  142. break;
  143. case ID_MAPSTRINGTOSTRING:
  144. pNewViewClass = RUNTIME_CLASS(CMapStringToStringView);
  145. break;
  146. case ID_TYPEDPTRMAP:
  147. pNewViewClass = RUNTIME_CLASS(CTypedPtrMapView);
  148. break;
  149. case ID_MAPDWORDTOMYSTRUCT:
  150. pNewViewClass = RUNTIME_CLASS(CMapDWordToMyStructView);
  151. break;
  152. default:
  153. ASSERT(0);
  154. return;
  155. }
  156. // create the new view
  157. CCreateContext context;
  158. context.m_pNewViewClass = pNewViewClass;
  159. context.m_pCurrentDoc = GetActiveDocument();
  160. CView* pNewView = STATIC_DOWNCAST(CView, CreateView(&context));
  161. if (pNewView != NULL)
  162. {
  163. // the new view is there, but invisible and not active...
  164. pNewView->ShowWindow(SW_SHOW);
  165. pNewView->OnInitialUpdate();
  166. SetActiveView(pNewView);
  167. RecalcLayout();
  168. m_nCurrentExample = nCmdID;
  169. // finally destroy the old view...
  170. pOldActiveView->DestroyWindow();
  171. }
  172. }
  173. void CMainFrame::OnUpdateExampleUI(CCmdUI* pCmdUI)
  174. {
  175. pCmdUI->SetCheck(pCmdUI->m_nID == m_nCurrentExample);
  176. }