MainFrm.cpp
上传用户:aokegd
上传日期:2009-12-14
资源大小:1276k
文件大小:4k
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- #include "stdafx.h"
- #include "BmpMenu.h"
- #include "MainFrm.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_WM_MEASUREITEM()
- ON_WM_MENUCHAR()
- ON_WM_INITMENUPOPUP()
- //}}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
-
- }
- CMainFrame::~CMainFrame()
- {
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbarn");
- return -1; // fail to create
- }
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status barn");
- return -1; // fail to create
- }
- // TODO: Delete these three lines if you don't want the toolbar to
- // be dockable
- m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar);
- return 0;
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- if( !CFrameWnd::PreCreateWindow(cs) )
- return FALSE;
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CFrameWnd::AssertValid();
- }
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CFrameWnd::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- //生成图标菜单
- HMENU CMainFrame::NewMenu()
- {
- m_menu.LoadMenu(IDR_MAINFRAME);
- //将图标加到菜单中
- m_menu.ModifyODMenuA(NULL,ID_FILE_NEW,IDB_FILE_NEW);
- m_menu.ModifyODMenuA(NULL,ID_FILE_OPEN,IDB_FILE_OPEN);
- m_menu.ModifyODMenuA(NULL,ID_FILE_SAVE,IDB_FILE_SAVE);
- m_menu.ModifyODMenuA(NULL,ID_FILE_PRINT,IDB_FILE_PRINT);
- //返回图标菜单的句柄
- return m_menu.Detach();
- }
- void CMainFrame::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
- {
- // TODO: Add your message handler code here and/or call default
- BOOL setflag=FALSE;
- if(lpMeasureItemStruct->CtlType==ODT_MENU){
- if(IsMenu((HMENU)lpMeasureItemStruct->itemID)){
- CMenu* cmenu =
- CMenu::FromHandle((HMENU)lpMeasureItemStruct->itemID);
-
- if(m_menu.IsMenu(cmenu)){
- m_menu.MeasureItem(lpMeasureItemStruct);
- setflag=TRUE;
- }
- }
- }
- if(!setflag)CFrameWnd::OnMeasureItem(nIDCtl,
- lpMeasureItemStruct);
- // CFrameWnd::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
- }
- LRESULT CMainFrame::OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu)
- {
- // TODO: Add your message handler code here and/or call default
- LRESULT lresult;
- if(m_menu.IsMenu(pMenu))
- lresult=BCMenu::FindKeyboardShortcut(nChar, nFlags, pMenu);
- else
- lresult=CFrameWnd::OnMenuChar(nChar, nFlags, pMenu);
- return(lresult);
- // return CFrameWnd::OnMenuChar(nChar, nFlags, pMenu);
- }
- void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
- {
- CFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
- if(!bSysMenu){
- if(m_menu.IsMenu(pPopupMenu))
- BCMenu::UpdateMenu(pPopupMenu);
- }
- // CFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
-
- // TODO: Add your message handler code here
-
- }