技术开发 频道

Visual C++ 2010创建Ribbon界面(下)

// 添加“上一步”按钮
CMFCRibbonPanel
* pPanel1 = pCategory->AddPanel(_T("Undo"));

CMFCRibbonUndoButton
* pBtn1 = new CMFCRibbonUndoButton(ID_RIBBON_OBTN_1, _T("Undo"), 0, 0);
// 为返回按钮添加可以返回的动作
for (int i = 0; i < 10; i++)
{
    CString str;
    str.Format(_T(
"Action %d"), i + 1);
    pBtn1
->AddUndoAction(str);
}
pPanel1
->Add(pBtn1);

// 添加文本标签
CMFCRibbonPanel
* pPanel2 = pCategory->AddPanel(_T("Label"));

pPanel2
->Add(new CMFCRibbonLabel(_T("Label 1")));
pPanel2
->Add(new CMFCRibbonLabel(_T("Label 2")));
pPanel2
->Add(new CMFCRibbonLabel(_T("Label 3")));

// 在面板中添加一个分隔符
pPanel2
->Add(new CMFCRibbonSeparator());

// 多行文本标签
pPanel2
->Add(new CMFCRibbonLabel(_T("This is a multi-line label"), TRUE));

// 添加超链标签
CMFCRibbonPanel
* pPanel3 = pCategory->AddPanel(_T("Hyperlink"));

// 写mail给我啊
pPanel3
->Add(new CMFCRibbonLinkCtrl(ID_RIBBON_OBTN_2, _T("Send e-mail"), _T("mailto:chenlq@live.com")));
// 欢迎访问我的blog
pPanel3
->Add(new CMFCRibbonLinkCtrl(ID_RIBBON_OBTN_3, _T("Visit site"), _T("http://space.itpub.net/17237043/")));
pPanel3
->Add(new CMFCRibbonLinkCtrl(ID_RIBBON_OBTN_4, _T("Launch Notepad"), _T("notepad")));

// 滑动条
CMFCRibbonPanel
* pPanel4 = pCategory->AddPanel(_T("Sliders"));
pPanel4
->SetCenterColumnVert();

pPanel4
->Add(new CMFCRibbonLabel(_T("Simple Slider:")));
pPanel4
->Add(new CMFCRibbonSlider(ID_RIBBON_OBTN_5, 70 /* Slider width */));

pPanel4
->Add(new CMFCRibbonSeparator());

pPanel4
->Add(new CMFCRibbonLabel(_T("Slider with Buttons:")));
CMFCRibbonSlider
* pBtn6 = new CMFCRibbonSlider(ID_RIBBON_OBTN_6, 70 /* Slider width */);
// 设置缩放按钮
pBtn6
->SetZoomButtons();
pBtn6
->SetRange(0, 100);
pBtn6
->SetPos(50);
pPanel4
->Add(pBtn6);

// 进度条
CMFCRibbonPanel
* pPanel5 = pCategory->AddPanel(_T("Progress Bars"));
pPanel5
->SetCenterColumnVert();

// 简单进度条
pPanel5
->Add(new CMFCRibbonLabel(_T("Simple Progress:")));
pPanel5
->Add(new CMFCRibbonProgressBar(ID_RIBBON_OBTN_7, 100 /* Bar width */));
pPanel5
->Add(new CMFCRibbonButton(ID_RIBBON_OBTN_8, _T("Show Progress 1")));

pPanel5
->Add(new CMFCRibbonSeparator());

pPanel5
->Add(new CMFCRibbonLabel(_T("Infinite Progress:")));
CMFCRibbonProgressBar
* pBtn9 = new CMFCRibbonProgressBar(ID_RIBBON_OBTN_9, 100 /* Bar width */);
// 设置为无限模式,表示动作在进行,但是没有明确的进度
pBtn9
->SetInfiniteMode();
pPanel5
->Add(pBtn9);

pPanel5
->Add(new CMFCRibbonButton(ID_RIBBON_OBTN_10, _T("Show Progress 2")));

  到此为止,我们已经演练了Ribbon界面的大多数控件。通过这些实际代码的演练,我相信大家现在都可以自信地说:

  “I can Ribbon now!”

0
相关文章