MainFrm.cpp
上传用户:shilei2004
上传日期:2020-07-18
资源大小:83k
文件大小:8k
- // MainFrm.cpp : implementation of the CMainFrame class
- // Download by http://www.codefans.net
- #include "stdafx.h"
- #include "Edit.h"
- #include "MainFrm.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_NOTIFY(TBN_DROPDOWN, AFX_IDW_TOOLBAR, OnToolbarDropDown)
- ON_COMMAND(ID_VIEW_FORMAT_BAR, OnViewFormatBar)
- ON_UPDATE_COMMAND_UI(ID_VIEW_FORMAT_BAR, OnUpdateViewFormatBar)
- ON_WM_DESTROY()
- ON_COMMAND(ID_VIEW_FULL_SCREEN, OnViewFullScreen)
- ON_UPDATE_COMMAND_UI(ID_VIEW_FULL_SCREEN, OnUpdateViewFullScreen)
- ON_WM_CLOSE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- CMainFrame::CMainFrame()
- {
- // TODO: add member initialization code here
- m_bFullScreenMode=false;
- }
- CMainFrame::~CMainFrame()
- {
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbarn");
- return -1; // fail to create
- }
- m_wndToolBar.SetWindowText("Standard");
- DWORD dwExStyle = TBSTYLE_EX_DRAWDDARROWS;
- m_wndToolBar.GetToolBarCtrl().SendMessage(TB_SETEXTENDEDSTYLE, 0, (LPARAM)dwExStyle);
-
- DWORD dwStyle = m_wndToolBar.GetButtonStyle(m_wndToolBar.CommandToIndex(ID_FILE_OPEN));
- dwStyle |= TBSTYLE_DROPDOWN;
- m_wndToolBar.SetButtonStyle(m_wndToolBar.CommandToIndex(ID_FILE_OPEN), dwStyle);
-
- if (!m_wndFormatBar.Create(this, WS_CHILD | WS_VISIBLE |
- CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_GRIPPER | CBRS_SIZE_DYNAMIC,
- IDR_FORMATBAR) )
- {
- TRACE0("Failed to create FormatBarn");
- return -1; // fail to create
- }
- m_wndFormatBar.GetToolBarCtrl().ModifyStyle(0, TBSTYLE_FLAT);
- m_wndFormatBar.SetWindowText("Formatting");
-
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status barn");
- return -1; // fail to create
- }
-
- CStatusBarCtrl& sb = m_wndStatusBar.GetStatusBarCtrl();
- sb.SetIcon(0, (HICON)::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME), IMAGE_ICON, 16, 16, 0));
-
- m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- FrameEnableDocking(this,CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar);
- m_wndFormatBar.EnableDocking(CBRS_ALIGN_ANY);
- FrameEnableDocking(this,CBRS_ALIGN_ANY);
- DockControlBar(&m_wndFormatBar);
- m_coolmenu.Install(this);
- static UINT toolbars[] = {IDR_MAINFRAME2 ,IDR_EDITTYPE, IDR_FULLSCREEN};
- m_coolmenu.LoadToolbars(toolbars, 3);
- LoadBarState("SameerToolBar");
- m_wndMDITabs.Create(this, MT_BOTTOM|MT_IMAGES);
- return 0;
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- if( !CMDIFrameWnd::PreCreateWindow(cs) )
- return FALSE;
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- cs.style = WS_CAPTION | FWS_ADDTOTITLE
- | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CMDIFrameWnd::AssertValid();
- }
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CMDIFrameWnd::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- void CMainFrame::OnToolbarDropDown(NMTOOLBAR* pnmtb, LRESULT *plr)
- {
- CWnd *pWnd;
- UINT nID;
- switch (pnmtb->iItem)
- {
- case ID_FILE_OPEN:
- pWnd = &m_wndToolBar;
- nID = IDR_DROPDOWN;
- break;
- default:
- return;
- }
-
- CMenu menu;
- menu.LoadMenu(nID);
- CMenu* pPopup = menu.GetSubMenu(0);
- VERIFY(pPopup);
-
- CRect rc;
- pWnd->SendMessage(TB_GETRECT, pnmtb->iItem, (LPARAM)&rc);
- pWnd->ClientToScreen(&rc);
-
- pPopup->TrackPopupMenu( TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_VERTICAL,
- rc.left, rc.bottom, this, &rc);
- }
- void CMainFrame::OnViewFormatBar()
- {
- CMainFrame* pFrame = (CMainFrame *)GetTopLevelFrame();
- CControlBar* pBar = pFrame->GetFormatBar();
-
- if (pBar)
- pFrame->ShowControlBar(pBar, (pBar->GetStyle() & WS_VISIBLE) == 0, FALSE);
- }
- void CMainFrame::OnUpdateViewFormatBar(CCmdUI* pCmdUI)
- {
- CMainFrame* pFrame = (CMainFrame *)GetTopLevelFrame();
- CControlBar* pBar = pFrame->GetFormatBar();
-
- if (pBar != NULL)
- {
- pCmdUI->SetCheck((pBar->GetStyle() & WS_VISIBLE) != 0);
- return;
- }
- pCmdUI->ContinueRouting();
- }
- void CMainFrame::OnDestroy()
- {
- SaveBarState("SameerToolBar");
- CMDIFrameWnd::OnDestroy();
- }
- void CMainFrame::OnUpdateFrameTitle(BOOL bAddToTitle)
- {
- CMDIFrameWnd::OnUpdateFrameTitle(bAddToTitle);
- m_wndMDITabs.Update();
- }
- void CMainFrame::FullScreenModeOn()
- {
- CMDIChildWnd* pChild=MDIGetActive();
- if(!pChild) return;
- m_bToolBarWasVisible=(m_wndToolBar.IsWindowVisible()!=0);
- m_wndToolBar.ShowWindow(SW_HIDE);
- m_bFormatBarWasVisible=(m_wndFormatBar.IsWindowVisible()!=0);
- m_wndFormatBar.ShowWindow(SW_HIDE);
- m_bStatusBarWasVisible=(m_wndStatusBar.IsWindowVisible()!=0);
- m_wndStatusBar.ShowWindow(SW_HIDE);
- m_pwndFullScreenBar=new CToolBar;
- m_pwndFullScreenBar->Create(this);
- m_pwndFullScreenBar->LoadToolBar(IDR_FULLSCREEN);
- m_pwndFullScreenBar->SetBarStyle(m_pwndFullScreenBar->GetBarStyle() |
- CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
- m_pwndFullScreenBar->ModifyStyle(0, TBSTYLE_FLAT);
- m_pwndFullScreenBar->EnableDocking(0);
- CPoint pt(300,200);
- FloatControlBar(m_pwndFullScreenBar,pt);
-
- GetWindowRect(&m_mainRect);
- LONG style=::GetWindowLong(m_hWnd,GWL_STYLE);
- style&=~WS_CAPTION;
- ::SetWindowLong(m_hWnd,GWL_STYLE,style);
- int screenx=GetSystemMetrics(SM_CXSCREEN);
- int screeny=GetSystemMetrics(SM_CYSCREEN);
- SetWindowPos(NULL,-4,-4,screenx+8,screeny+8,SWP_NOZORDER);
- style=::GetWindowLong(pChild->m_hWnd,GWL_STYLE);
- m_bChildMax=(style & WS_MAXIMIZE)?true:false;
- pChild->ShowWindow(SW_SHOWMAXIMIZED);
- RecalcLayout();
- m_bFullScreenMode=true;
- }
- void CMainFrame::FullScreenModeOff()
- {
- delete m_pwndFullScreenBar;
- LONG style=::GetWindowLong(m_hWnd,GWL_STYLE);
- style|=WS_CAPTION;
- ::SetWindowLong(m_hWnd,GWL_STYLE,style);
- if(m_bToolBarWasVisible)
- m_wndToolBar.ShowWindow(SW_SHOW);
- if(m_bFormatBarWasVisible)
- m_wndFormatBar.ShowWindow(SW_SHOW);
- if(m_bStatusBarWasVisible)
- m_wndStatusBar.ShowWindow(SW_SHOW);
- MoveWindow(&m_mainRect);
- RecalcLayout();
- CMDIChildWnd* pChild=MDIGetActive();
- if(pChild){
- if(m_bChildMax)
- MDIMaximize(pChild);
- else MDIRestore(pChild);
- }
- m_bFullScreenMode=false;
- }
- void CMainFrame::OnViewFullScreen()
- {
- if(m_bFullScreenMode)
- FullScreenModeOff();
- else FullScreenModeOn();
- }
- void CMainFrame::OnUpdateViewFullScreen(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_bFullScreenMode);
- }
- void CMainFrame::OnClose()
- {
- CEditApp *app=(CEditApp *)AfxGetApp();
- WINDOWPLACEMENT wp;
-
- this->GetWindowPlacement(&wp);
- app->PutWP(wp);
- CMDIFrameWnd::OnClose();
- }