VC++2008 初体验(-)
突然发现VC++2008 Feature Pack 的Release版本已经发布了,Beta版的早已经安装,不过没有用过。。。Release版本的要比Beta的容易安装的多,而且还快。。
呵,现在开始体验一下新功能,主要参照帮助文档.
一
1,打开VC2008,新建MFC Application工程 输入名称SuFirstDay,点OK,
2,再点一下Application Type 。
MFC默认已经给你选择了新的功能,像Office2007 类型什么的。既然我们要体验新功能,那么咱们就得恢复到只有最普通功能的界面。
所以把Project style 选MFC Standard选项
Visual style and colors -> Windows Native/Default
去掉Enable visual style switching
最终如下图一
图表 1
3,点击User Interface Features
Command bars 选择 Use a classic menu并且选择Use a classic docking toolbar.
如图表2
图表 2
4, 其它一切默认, 点Finish
点Debug开始运行,让我们先看一下最初的界面样子(呵,老样子)
图表 3
二, 好了,接下来我们可以开始新的征程了,相信大家都很急吧…,不用着急,慢慢来
心急吃不了热豆腐.
1, 在stdafx.h 中加入下句,原因看注释
#include
<
afxcontrolbars.h
>
//
MFC support for ribbons and control bars
2, 打开ChildFrm.h 和ChildFrm.cpp文件
将CChildFrame的父类CMDIChildWnd改成CMDIChildWndEx,同理将ChildFrm.cpp中的出现的CMDIChildWnd都改成CMDIChildWndEx.
3,打开SuFirstDay.h和SuFirstDay.cpp文件
a ,将CSuFirstDayApp的父类CWinApp改成CWinAppEx,同理修改SuFirstDay.cpp文件中出现的CWinApp改为CWinAppEx(看仔细了,别少修改了);
b, 将 BOOL CSuFirstDayApp::InitInstance()中的
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
改为
SetRegistryKey(_T(
"
MFCNext/Samples/Scribble2
"
));
SetRegistryBase (_T(
"
Settings
"
));
4,打开MainFrm.h和MainFrm.cpp文件
一,同上面一样把出现的CMDIFrameWnd 都改为 CMDIFrameWndEx
二,在MainFrm.h中增加三个成员变量
//
Ribbon bar for the application
CMFCRibbonBar m_wndRibbonBar;
//
The application button for the ribbon
CMFCRibbonApplicationButton m_MainButton;
//
Ribbon panel icons
CMFCToolBarImages m_PanelImages;
并且修改原来的
CToolBar 和CStatusBar 类为
CMFCToolBar 和 CMFCStatusBar
三,修改CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)函数
最终函数代码如下
int
CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
...
{
if (CMDIFrameWndEx::OnCreate(lpCreateStruct) == -1)
return -1;
CMFCVisualManager::SetDefaultManager (RUNTIME_CLASS (CMFCVisualManagerOffice2007));
CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_LunaBlue);
if (!m_wndRibbonBar.Create(this))
...{
return -1; //Failed to create ribbon bar
}
m_PanelImages.SetImageSize(CSize(16,16));
m_PanelImages.Load(IDB_BITMAP3);
// Initialize the application button
m_MainButton.SetImage (IDB_BITMAP4);
m_MainButton.SetToolTipText (_T("File"));
m_MainButton.SetText (_T(" f"));
// Attach the application button to the ribbon
m_wndRibbonBar.SetApplicationButton(&m_MainButton, CSize(45,45));
CMFCRibbonMainPanel* pMainPanel = NULL;
pMainPanel = m_wndRibbonBar.AddMainCategory (_T("File"), IDB_BITMAP2, IDB_BITMAP1);
pMainPanel->Add (new CMFCRibbonButton (
ID_FILE_NEW, _T("&New"), 0, 0));
pMainPanel->Add (new CMFCRibbonButton (ID_FILE_OPEN, _T("&Open..."), 1, 1));
pMainPanel->Add (new CMFCRibbonButton (ID_FILE_CLOSE, _T("&Close"), 5, 5));
pMainPanel->Add (new CMFCRibbonButton (ID_FILE_SAVE, _T("&Save"), 2, 2));
pMainPanel->Add (new CMFCRibbonButton (ID_FILE_SAVE_AS, _T("Save &As..."), 3, 3));
CMFCRibbonButton* pBtnPrint = new CMFCRibbonButton (ID_FILE_PRINT, _T("&Print"), 4, 4);
pBtnPrint->AddSubItem (new CMFCRibbonLabel (_T("Preview and print the document")));
pBtnPrint->AddSubItem (new CMFCRibbonButton (ID_FILE_PRINT, _T("&Print"), 4, 4, TRUE));
pBtnPrint->AddSubItem (new CMFCRibbonButton (ID_FILE_PRINT_DIRECT, _T("&Quick Print"), 7, 7, TRUE));
pBtnPrint->AddSubItem (new CMFCRibbonButton (ID_FILE_PRINT_PREVIEW, _T("Print Pre&view"), 6, 6, TRUE));
pBtnPrint->SetKeys (_T("p"), _T("w"));
pMainPanel->Add (pBtnPrint);
pMainPanel->Add (new CMFCRibbonSeparator (TRUE));
pMainPanel->Add (new CMFCRibbonButton (ID_FILE_CLOSE, _T("&Close"), 5, 5));
pMainPanel->AddRecentFilesList (_T("Recent Documents"));
pMainPanel->AddToBottom (new CMFCRibbonMainPanelButton (ID_APP_EXIT, _T("E&xit"), 8));
// Add a "Home" category to the ribbonbar
CMFCRibbonCategory* pCategory = m_wndRibbonBar.AddCategory(
_T("&Home"), // Category name
IDB_BITMAP2, // Category small images (16 x 16)
IDB_BITMAP1); // Category large images (32 x 32)
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 toolbar ");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this))
...{
TRACE0("Failed to create status bar ");
return -1; // fail to create
}
m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));
// 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);
DockPane(&m_wndToolBar);//注意这也是修改的,原来是DockToolBar
return 0;
}
图表 4
IDB_BITMAP2, IDB_BITMAP1
是大小为16*16 和32*32的bmp图片
IDB_BITMAP3, IDB_BITMAP4也是。
千万不要用ico图片哦。。(一开始我用了ico的,运行的时候出现错误对话框了)
今天就先到这里吧,对新功能有个新的认识。。。。改天继续学习学习。