1、根据新建向导创建一个项目,然后清空MainFrm某些内容,留下简单的几个方法:
头文件中剩余:
// MainFrm.h : interface of the CMainFrame class
//
#pragma once
class CMainFrame : public CBCGPMDIFrameWnd
{
DECLARE_DYNAMIC(CMainFrame)
public:
CMainFrame();
// Attributes
public:
// Operations
public:
// Overrides
public:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
// Implementation
public:
virtual ~CMainFrame();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected: // control bar embedded members
CBCGPStatusBar m_wndStatusBar;
CBCGPMenuBar m_wndMenuBar;
CBCGPToolBar m_wndToolBar;
CBCGPRibbonDialogBar m_wndPane;
// Generated message map functions
protected:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnClose();
DECLARE_MESSAGE_MAP()
};
2、实现文件中剩余:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "ribbonSample1.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CBCGPMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CBCGPMDIFrameWnd)
ON_WM_CREATE()
ON_WM_CLOSE()
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 (CBCGPMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CBCGPMDIFrameWnd::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
{
CBCGPMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CBCGPMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
// CMainFrame message handlers
void CMainFrame::OnClose()
{
SaveMDIState(theApp.GetRegSectionPath());
CBCGPMDIFrameWnd::OnClose();
}
接下来向方法里面添加内容:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CBCGPMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
//这里清空整个菜单
CBCGPToolBar::EnableQuickCustomization();
if (!m_wndMenuBar.Create(this))
{
TRACE0("Failed to create menubar\n");
return -1; // fail to create
}
return ;
}
效果如下: