MainFrm.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:4k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "MarkupPad.h"
  5. #include "MarkupPadEdit.h"
  6. #include "MainFrm.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CMainFrame
  14. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  15. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  16. //{{AFX_MSG_MAP(CMainFrame)
  17. // NOTE - the ClassWizard will add and remove mapping macros here.
  18. //    DO NOT EDIT what you see in these blocks of generated code !
  19. ON_WM_CREATE()
  20. //}}AFX_MSG_MAP
  21. ON_MESSAGE(XTPWM_DOCKINGPANE_NOTIFY, OnDockingPaneNotify)
  22. END_MESSAGE_MAP()
  23. static UINT indicators[] =
  24. {
  25. ID_SEPARATOR,           // status line indicator
  26. ID_INDICATOR_CAPS,
  27. ID_INDICATOR_NUM,
  28. ID_INDICATOR_SCRL,
  29. };
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CMainFrame construction/destruction
  32. CMainFrame::CMainFrame()
  33. {
  34. // TODO: add member initialization code here
  35. }
  36. CMainFrame::~CMainFrame()
  37. {
  38. }
  39. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  40. {
  41. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  42. return -1;
  43. // Create Status bar.
  44. // Important: All control bars including the Status Bar
  45. // must be created before CommandBars....
  46. if (!m_wndStatusBar.Create(this) ||
  47. !m_wndStatusBar.SetIndicators(indicators,
  48. sizeof(indicators)/sizeof(UINT)))
  49. {
  50. TRACE0("Failed to create status barn");
  51. return -1;      // fail to create
  52. }
  53. m_wndStatusBar.EnableMarkup();
  54. // Initialize the command bars
  55. if (!InitCommandBars())
  56. return -1;
  57. // Get a pointer to the command bars object.
  58. CXTPCommandBars* pCommandBars = GetCommandBars();
  59. if(pCommandBars == NULL)
  60. {
  61. TRACE0("Failed to create command bars object.n");
  62. return -1;      // fail to create
  63. }
  64. // Add the menu bar
  65. CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(
  66. _T("Menu Bar"), IDR_MAINFRAME);
  67. if(pMenuBar == NULL)
  68. {
  69. TRACE0("Failed to create menu bar.n");
  70. return -1;      // fail to create
  71. }
  72. // Create ToolBar
  73. CXTPToolBar* pToolBar = (CXTPToolBar*)
  74. pCommandBars->Add(_T("Standard"), xtpBarTop);
  75. if (!pToolBar || !pToolBar->LoadToolBar(IDR_MAINFRAME))
  76. {
  77. TRACE0("Failed to create toolbarn");
  78. return -1;
  79. }
  80. pCommandBars->GetCommandBarsOptions()->ShowKeyboardCues(xtpKeyboardCuesShowWindowsDefault);
  81. // Set Office 2003 Theme
  82. CXTPPaintManager::SetTheme(xtpThemeWhidbey);
  83. m_paneManager.InstallDockingPanes(this);
  84. m_paneManager.SetTheme(xtpPaneThemeVisualStudio2005);
  85. CXTPDockingPane* pPaneEdit = m_paneManager.CreatePane(
  86. 1, CRect(0, 0,200, 200), xtpPaneDockBottom);
  87. pPaneEdit->SetTitle(_T("Markup"));
  88. pPaneEdit->SetOptions(xtpPaneNoCloseable);
  89. return 0;
  90. }
  91. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  92. {
  93. if (!CFrameWnd::PreCreateWindow(cs) )
  94. return FALSE;
  95. cs.lpszClass = _T("XTPMainFrame");
  96. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  97. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  98. return TRUE;
  99. }
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CMainFrame diagnostics
  102. #ifdef _DEBUG
  103. void CMainFrame::AssertValid() const
  104. {
  105. CFrameWnd::AssertValid();
  106. }
  107. void CMainFrame::Dump(CDumpContext& dc) const
  108. {
  109. CFrameWnd::Dump(dc);
  110. }
  111. #endif //_DEBUG
  112. /////////////////////////////////////////////////////////////////////////////
  113. // CMainFrame message handlers
  114. LRESULT CMainFrame::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam)
  115. {
  116. if (wParam == XTP_DPN_SHOWWINDOW)
  117. {
  118. // get a pointer to the docking pane being shown.
  119. CXTPDockingPane* pPane = (CXTPDockingPane*)lParam;
  120. if (!pPane->IsValid())
  121. {
  122. pPane->Attach(m_pEditView);
  123. }
  124. return TRUE; // handled
  125. }
  126. return FALSE;
  127. }
  128. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
  129. {
  130. if (!CFrameWnd::OnCreateClient(lpcs, pContext))
  131. return FALSE;
  132. pContext->m_pNewViewClass = RUNTIME_CLASS(CMarkupPadEdit);
  133. m_pEditView = (CView*)CreateView(pContext);
  134. m_pEditView->SetDlgCtrlID(0);
  135. return TRUE;
  136. }
  137. void CMainFrame::OnSetPreviewMode(BOOL bPreview, CPrintPreviewState* pState)
  138. {
  139. // Toggle CommandBars
  140. GetCommandBars()->OnSetPreviewMode(bPreview);
  141. // Toggle Docking Panes.
  142. m_paneManager.OnSetPreviewMode(bPreview);
  143. CFrameWnd::OnSetPreviewMode(bPreview, pState);
  144. }