MainFrm.cpp
上传用户:shilei2004
上传日期:2020-07-18
资源大小:83k
文件大小:8k
源码类别:

RichEdit

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. // Download by http://www.codefans.net
  3. #include "stdafx.h"
  4. #include "Edit.h"
  5. #include "MainFrm.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CMainFrame
  13. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  14. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  15. //{{AFX_MSG_MAP(CMainFrame)
  16. ON_WM_CREATE()
  17. ON_NOTIFY(TBN_DROPDOWN, AFX_IDW_TOOLBAR, OnToolbarDropDown)
  18. ON_COMMAND(ID_VIEW_FORMAT_BAR, OnViewFormatBar)
  19. ON_UPDATE_COMMAND_UI(ID_VIEW_FORMAT_BAR, OnUpdateViewFormatBar)
  20. ON_WM_DESTROY()
  21. ON_COMMAND(ID_VIEW_FULL_SCREEN, OnViewFullScreen)
  22. ON_UPDATE_COMMAND_UI(ID_VIEW_FULL_SCREEN, OnUpdateViewFullScreen)
  23. ON_WM_CLOSE()
  24. //}}AFX_MSG_MAP
  25. END_MESSAGE_MAP()
  26. static UINT indicators[] =
  27. {
  28. ID_SEPARATOR,           // status line indicator
  29. ID_INDICATOR_CAPS,
  30. ID_INDICATOR_NUM,
  31. ID_INDICATOR_SCRL,
  32. };
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CMainFrame construction/destruction
  35. CMainFrame::CMainFrame()
  36. {
  37. // TODO: add member initialization code here
  38. m_bFullScreenMode=false;
  39. }
  40. CMainFrame::~CMainFrame()
  41. {
  42. }
  43. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  44. {
  45. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  46. return -1;
  47. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  48. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY) ||
  49. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  50. {
  51. TRACE0("Failed to create toolbarn");
  52. return -1;      // fail to create
  53. }
  54. m_wndToolBar.SetWindowText("Standard");
  55. DWORD dwExStyle = TBSTYLE_EX_DRAWDDARROWS;
  56. m_wndToolBar.GetToolBarCtrl().SendMessage(TB_SETEXTENDEDSTYLE, 0, (LPARAM)dwExStyle);
  57. DWORD dwStyle = m_wndToolBar.GetButtonStyle(m_wndToolBar.CommandToIndex(ID_FILE_OPEN));
  58. dwStyle |= TBSTYLE_DROPDOWN;
  59. m_wndToolBar.SetButtonStyle(m_wndToolBar.CommandToIndex(ID_FILE_OPEN), dwStyle);
  60. if (!m_wndFormatBar.Create(this, WS_CHILD | WS_VISIBLE |
  61. CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_GRIPPER | CBRS_SIZE_DYNAMIC,
  62. IDR_FORMATBAR) )
  63. {
  64. TRACE0("Failed to create FormatBarn");
  65. return -1;      // fail to create
  66. }
  67. m_wndFormatBar.GetToolBarCtrl().ModifyStyle(0, TBSTYLE_FLAT);
  68. m_wndFormatBar.SetWindowText("Formatting");
  69. if (!m_wndStatusBar.Create(this) ||
  70. !m_wndStatusBar.SetIndicators(indicators,
  71.   sizeof(indicators)/sizeof(UINT)))
  72. {
  73. TRACE0("Failed to create status barn");
  74. return -1;      // fail to create
  75. }
  76.  
  77. CStatusBarCtrl& sb = m_wndStatusBar.GetStatusBarCtrl();
  78. sb.SetIcon(0, (HICON)::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME), IMAGE_ICON, 16, 16, 0));
  79.   
  80. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  81. FrameEnableDocking(this,CBRS_ALIGN_ANY);
  82. DockControlBar(&m_wndToolBar);
  83. m_wndFormatBar.EnableDocking(CBRS_ALIGN_ANY);
  84. FrameEnableDocking(this,CBRS_ALIGN_ANY);
  85. DockControlBar(&m_wndFormatBar);
  86. m_coolmenu.Install(this);
  87. static UINT toolbars[] = {IDR_MAINFRAME2 ,IDR_EDITTYPE, IDR_FULLSCREEN}; 
  88. m_coolmenu.LoadToolbars(toolbars, 3);
  89. LoadBarState("SameerToolBar");
  90. m_wndMDITabs.Create(this, MT_BOTTOM|MT_IMAGES);
  91. return 0;
  92. }
  93. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  94. {
  95. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  96. return FALSE;
  97. // TODO: Modify the Window class or styles here by modifying
  98. //  the CREATESTRUCT cs
  99. cs.style = WS_CAPTION | FWS_ADDTOTITLE
  100. | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
  101. return TRUE;
  102. }
  103. /////////////////////////////////////////////////////////////////////////////
  104. // CMainFrame diagnostics
  105. #ifdef _DEBUG
  106. void CMainFrame::AssertValid() const
  107. {
  108. CMDIFrameWnd::AssertValid();
  109. }
  110. void CMainFrame::Dump(CDumpContext& dc) const
  111. {
  112. CMDIFrameWnd::Dump(dc);
  113. }
  114. #endif //_DEBUG
  115. /////////////////////////////////////////////////////////////////////////////
  116. // CMainFrame message handlers
  117. void CMainFrame::OnToolbarDropDown(NMTOOLBAR* pnmtb, LRESULT *plr)
  118. {
  119. CWnd *pWnd;
  120. UINT nID;
  121. switch (pnmtb->iItem)
  122. {
  123. case ID_FILE_OPEN:
  124. pWnd = &m_wndToolBar;
  125. nID  = IDR_DROPDOWN;
  126. break;
  127. default:
  128. return;
  129. }
  130. CMenu menu;
  131. menu.LoadMenu(nID);
  132. CMenu* pPopup = menu.GetSubMenu(0);
  133. VERIFY(pPopup);
  134. CRect rc;
  135. pWnd->SendMessage(TB_GETRECT, pnmtb->iItem, (LPARAM)&rc);
  136. pWnd->ClientToScreen(&rc);
  137. pPopup->TrackPopupMenu( TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_VERTICAL,
  138. rc.left, rc.bottom, this, &rc);
  139. }
  140. void CMainFrame::OnViewFormatBar() 
  141. {
  142. CMainFrame* pFrame = (CMainFrame *)GetTopLevelFrame();
  143. CControlBar* pBar = pFrame->GetFormatBar();
  144. if (pBar)
  145. pFrame->ShowControlBar(pBar, (pBar->GetStyle() & WS_VISIBLE) == 0, FALSE);
  146. }
  147. void CMainFrame::OnUpdateViewFormatBar(CCmdUI* pCmdUI) 
  148. {
  149. CMainFrame* pFrame = (CMainFrame *)GetTopLevelFrame(); 
  150. CControlBar* pBar = pFrame->GetFormatBar();      
  151. if (pBar != NULL)
  152. {
  153. pCmdUI->SetCheck((pBar->GetStyle() & WS_VISIBLE) != 0);
  154. return;
  155. }
  156. pCmdUI->ContinueRouting();
  157. }
  158. void CMainFrame::OnDestroy() 
  159. {
  160. SaveBarState("SameerToolBar");
  161. CMDIFrameWnd::OnDestroy();
  162. }
  163. void CMainFrame::OnUpdateFrameTitle(BOOL bAddToTitle)
  164. {
  165.   CMDIFrameWnd::OnUpdateFrameTitle(bAddToTitle);
  166.   m_wndMDITabs.Update();
  167. }
  168. void CMainFrame::FullScreenModeOn()
  169. {
  170. CMDIChildWnd* pChild=MDIGetActive();
  171. if(!pChild) return;
  172. m_bToolBarWasVisible=(m_wndToolBar.IsWindowVisible()!=0);
  173. m_wndToolBar.ShowWindow(SW_HIDE);
  174. m_bFormatBarWasVisible=(m_wndFormatBar.IsWindowVisible()!=0);
  175. m_wndFormatBar.ShowWindow(SW_HIDE);
  176. m_bStatusBarWasVisible=(m_wndStatusBar.IsWindowVisible()!=0);
  177. m_wndStatusBar.ShowWindow(SW_HIDE);
  178. m_pwndFullScreenBar=new CToolBar;
  179. m_pwndFullScreenBar->Create(this);
  180. m_pwndFullScreenBar->LoadToolBar(IDR_FULLSCREEN);
  181. m_pwndFullScreenBar->SetBarStyle(m_pwndFullScreenBar->GetBarStyle() |
  182. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  183. m_pwndFullScreenBar->ModifyStyle(0, TBSTYLE_FLAT);
  184. m_pwndFullScreenBar->EnableDocking(0);
  185. CPoint pt(300,200);
  186. FloatControlBar(m_pwndFullScreenBar,pt);
  187. GetWindowRect(&m_mainRect);
  188. LONG style=::GetWindowLong(m_hWnd,GWL_STYLE);
  189. style&=~WS_CAPTION;
  190. ::SetWindowLong(m_hWnd,GWL_STYLE,style);
  191. int screenx=GetSystemMetrics(SM_CXSCREEN);
  192. int screeny=GetSystemMetrics(SM_CYSCREEN);
  193. SetWindowPos(NULL,-4,-4,screenx+8,screeny+8,SWP_NOZORDER);
  194. style=::GetWindowLong(pChild->m_hWnd,GWL_STYLE);
  195. m_bChildMax=(style & WS_MAXIMIZE)?true:false;
  196. pChild->ShowWindow(SW_SHOWMAXIMIZED);
  197. RecalcLayout();
  198. m_bFullScreenMode=true;
  199. }
  200. void CMainFrame::FullScreenModeOff()
  201. {
  202. delete m_pwndFullScreenBar;
  203. LONG style=::GetWindowLong(m_hWnd,GWL_STYLE);
  204. style|=WS_CAPTION;
  205. ::SetWindowLong(m_hWnd,GWL_STYLE,style);
  206. if(m_bToolBarWasVisible)
  207. m_wndToolBar.ShowWindow(SW_SHOW);
  208. if(m_bFormatBarWasVisible)
  209. m_wndFormatBar.ShowWindow(SW_SHOW);
  210. if(m_bStatusBarWasVisible)
  211. m_wndStatusBar.ShowWindow(SW_SHOW);
  212. MoveWindow(&m_mainRect);
  213. RecalcLayout();
  214. CMDIChildWnd* pChild=MDIGetActive();
  215. if(pChild){
  216. if(m_bChildMax)
  217. MDIMaximize(pChild);
  218. else MDIRestore(pChild);
  219. }
  220. m_bFullScreenMode=false;
  221. }
  222. void CMainFrame::OnViewFullScreen() 
  223. {
  224. if(m_bFullScreenMode)
  225. FullScreenModeOff();
  226. else FullScreenModeOn();
  227. }
  228. void CMainFrame::OnUpdateViewFullScreen(CCmdUI* pCmdUI) 
  229. {
  230. pCmdUI->SetCheck(m_bFullScreenMode);
  231. }
  232. void CMainFrame::OnClose() 
  233. {
  234. CEditApp *app=(CEditApp *)AfxGetApp();
  235. WINDOWPLACEMENT wp;
  236. this->GetWindowPlacement(&wp);
  237. app->PutWP(wp);
  238. CMDIFrameWnd::OnClose();
  239. }