MainFrm.cpp
上传用户:hzwailv
上传日期:2010-01-09
资源大小:405k
文件大小:5k
源码类别:

GIS编程

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "MapDemo.h"
  5. #include "MapDemoDoc.h"
  6. #include "MapView.h"
  7. #include "MapFormView.h"
  8. #include "MainFrm.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CMainFrame
  16. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  17. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  18. //{{AFX_MSG_MAP(CMainFrame)
  19. ON_WM_CREATE()
  20. ON_WM_PALETTECHANGED()
  21. ON_WM_QUERYNEWPALETTE()
  22. ON_COMMAND(ID_WINDOW_FROMVIEW, OnWindowFromview)
  23. ON_COMMAND(ID_WINDOW_MAPVIEW, OnWindowMapview)
  24. //}}AFX_MSG_MAP
  25. // Global help commands
  26. ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
  27. ON_COMMAND(ID_HELP, CMDIFrameWnd::OnHelp)
  28. ON_COMMAND(ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp)
  29. ON_COMMAND(ID_DEFAULT_HELP, CMDIFrameWnd::OnHelpFinder)
  30. END_MESSAGE_MAP()
  31. static UINT indicators[] =
  32. {
  33. ID_SEPARATOR,           // status line indicator
  34. ID_INDICATOR_CAPS,
  35. ID_INDICATOR_NUM,
  36. ID_INDICATOR_SCRL,
  37. };
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CMainFrame construction/destruction
  40. CMainFrame::CMainFrame()
  41. {
  42.   m_pMapView=NULL;
  43.   m_pFormView=NULL;
  44. }
  45. CMainFrame::~CMainFrame()
  46. {
  47. }
  48. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  49. {
  50. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  51. return -1;
  52. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  53. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  54. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  55. {
  56. TRACE0("Failed to create toolbarn");
  57. return -1;      // fail to create
  58. }
  59. if (!m_wndToolBarMap.Create(this) ||
  60. !m_wndToolBarMap.LoadToolBar(IDR_TOOLBARMAP))
  61. {
  62. TRACE0("Failed to create toolbarn");
  63. return -1;      // fail to create
  64. }
  65. if (!m_wndStatusBar.Create(this) ||
  66. !m_wndStatusBar.SetIndicators(indicators,
  67.   sizeof(indicators)/sizeof(UINT)))
  68. {
  69. TRACE0("Failed to create status barn");
  70. return -1;      // fail to create
  71. }
  72. // TODO: Delete these three lines if you don't want the toolbar to
  73. //  be dockable
  74. EnableDocking(CBRS_ALIGN_ANY);
  75.     m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  76. m_wndToolBarMap.EnableDocking(CBRS_ALIGN_ANY);
  77. DockControlBar(&m_wndToolBar);
  78. DockControlBar(&m_wndToolBarMap, AFX_IDW_DOCKBAR_LEFT);
  79. return 0;
  80. }
  81. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  82. {
  83. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  84. return FALSE;
  85. // TODO: Modify the Window class or styles here by modifying
  86. //  the CREATESTRUCT cs
  87. cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
  88. | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;
  89. return TRUE;
  90. }
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CMainFrame diagnostics
  93. #ifdef _DEBUG
  94. void CMainFrame::AssertValid() const
  95. {
  96. CMDIFrameWnd::AssertValid();
  97. }
  98. void CMainFrame::Dump(CDumpContext& dc) const
  99. {
  100. CMDIFrameWnd::Dump(dc);
  101. }
  102. #endif //_DEBUG
  103. /////////////////////////////////////////////////////////////////////////////
  104. // CMainFrame message handlers
  105. void CMainFrame::OnPaletteChanged(CWnd* pFocusWnd) 
  106. {
  107. CMapDemoApp::GetApp()->NotifyPaletteChanged(pFocusWnd);
  108. CMDIFrameWnd::OnPaletteChanged(pFocusWnd);
  109. // TODO: Add your message handler code here
  110. }
  111. BOOL CMainFrame::OnQueryNewPalette() 
  112. {
  113. CMDIChildWnd* pChildView = MDIGetActive();
  114. if( pChildView ) {
  115. CMapView* pView = (CMapView*) pChildView->GetActiveView();
  116. if( pView ) {
  117. pView->NotifyQueryNewPalette();
  118. }
  119. }
  120. return CMDIFrameWnd::OnQueryNewPalette();
  121. }
  122. void CMainFrame::OnWindowFromview() 
  123. if(m_pFormView==NULL) 
  124. {
  125. CMDIChildWnd* pActiveChild=MDIGetActive();
  126. CDocument* pDocument;
  127. if(pActiveChild!=NULL&&(pDocument=pActiveChild->GetActiveDocument())!=NULL)
  128. {
  129. CDocTemplate* pTemplate=((CMapDemoApp*)AfxGetApp())->pFormTemplate;
  130. CFrameWnd* pFrame=pTemplate->CreateNewFrame(pDocument,pActiveChild);
  131. pTemplate->InitialUpdateFrame(pFrame,pDocument);
  132.         }
  133.     }
  134. else{
  135. SetActiveView(m_pFormView);
  136. m_pFormView->ShowWindow(SW_SHOW);
  137. }
  138. }
  139. void CMainFrame::OnWindowMapview() 
  140. {
  141. if(m_pMapView==NULL) 
  142. {
  143. CMDIChildWnd* pActiveChild=MDIGetActive();
  144. CDocument* pDocument;
  145. if(pActiveChild!=NULL&&(pDocument=pActiveChild->GetActiveDocument())!=NULL)
  146. {
  147. CDocTemplate* pTemplate=((CMapDemoApp*)AfxGetApp())->pDocTemplate;
  148. CFrameWnd* pFrame=pTemplate->CreateNewFrame(pDocument,pActiveChild);
  149. pTemplate->InitialUpdateFrame(pFrame,pDocument);
  150.         }
  151.     }
  152. else{
  153. SetActiveView(m_pMapView);
  154. m_pMapView->ShowWindow(SW_SHOW);
  155. }
  156. }