• VC++ 2010 创建高级Ribbon界面详解(3)


    3、工具栏

     

    在传统的菜单式界面中,工具栏作为菜单的有益补充,被广泛使用。我们通过将一些常用命令放置到工具栏上,可以让用户直观而快速地访问到常用功能,提高了效率。在Ribbon界面中,工具栏得到了进一步的加强。除了具备原来的工具栏功能外,因为使用命令按钮实现,还使得工具栏具备了下拉菜单等扩展功能。

    工具栏
    图7 工具栏

    如下的代码演示了如何创建Ribbon界面中的工具栏控件:

    <!-- 
    code by 'http://www.desteps.com' 
     -->以下为引用内容: 
    CMFCRibbonPanel* pPanel1 = pCategory->AddPanel(_T("From Toolbar"));
    // 最简单的,通过AddToolBar()函数,指定一个工具栏资源而创建工具栏
    pPanel1->AddToolBar(IDR_TOOLBAR);
    // 手动创建工具栏
    CMFCRibbonPanel* pPanel2 = pCategory->AddPanel(_T("Manual"));
    // 创建一个按钮组
    CMFCRibbonButtonsGroup* pButtonsGroup1 = new CMFCRibbonButtonsGroup;
    // 将新的按钮添加到按钮组中
    pButtonsGroup1->AddButton(new CMFCRibbonButton(ID_RIBBON_GBTN_1, _T(""), 0));
    pButtonsGroup1->AddButton(new CMFCRibbonButton(ID_RIBBON_GBTN_2, _T(""), 1));
    // 创建一个编辑框控件
    CMFCRibbonEdit* pEdit = new CMFCRibbonEdit(ID_RIBBON_GBTN_3, 65);
    // 设置默认文本
    pEdit->SetEditText(_T("Edit"));
    pButtonsGroup1->AddButton(pEdit);
    pButtonsGroup1->AddButton(new CMFCRibbonButton(ID_RIBBON_GBTN_4, _T(""), 2));
    pButtonsGroup1->AddButton(new CMFCRibbonButton(ID_RIBBON_GBTN_5, _T(""), 3));
    // 将按钮组添加到面板中
    pPanel2->Add(pButtonsGroup1);
    // 添加新的按钮组和按钮
    CMFCRibbonButtonsGroup* pButtonsGroup2 = new CMFCRibbonButtonsGroup;
    pButtonsGroup2->AddButton(new CMFCRibbonButton(ID_RIBBON_GBTN_6, _T(""), 4));
    pButtonsGroup2->AddButton(new CMFCRibbonButton(ID_RIBBON_GBTN_7, _T(""), 5));
    pButtonsGroup2->AddButton(new CMFCRibbonButton(ID_RIBBON_GBTN_8, _T(""), 6));
    pButtonsGroup2->AddButton(new CMFCRibbonButton(ID_RIBBON_GBTN_9, _T(""), 7));
    pPanel2->Add(pButtonsGroup2);
    CMFCRibbonButtonsGroup* pButtonsGroup3 = new CMFCRibbonButtonsGroup;
    CMFCRibbonButton* pBtn10 = new CMFCRibbonButton(ID_RIBBON_GBTN_10, _T(""), 8);
    pBtn10->SetMenu(IDR_RIBBON_MENU_1);
    pButtonsGroup3->AddButton(pBtn10);
    CMFCRibbonButton* pBtn11 = new CMFCRibbonButton(ID_RIBBON_GBTN_11, _T(""), 9);
    // 为按钮指定一个子菜单
    pBtn11->SetMenu(IDR_RIBBON_MENU_1, TRUE);
    pButtonsGroup3->AddButton(pBtn11);
    pPanel2->Add(pButtonsGroup3);

    4、编辑框

    在传统的软件界面中,我们都是通过点击菜单项,或者工具栏上的按钮来简单执行某个命令。在新的Ribbon界面中,我们不仅可以点击按钮,还可以通过编辑框输入数据或者通过ComboBox快速地选择数据等等,完成更加复杂的交互。

    编辑框
    图8 编辑框

    如下的代码演示了Ribbon编辑框的创建过程:

    <!-- 
    code by 'http://www.desteps.com' 
     -->以下为引用内容: 
    CMFCRibbonPanel* pPanel1 = pCategory->AddPanel(_T(“Standard"));
    // 创建简单编辑框
    CMFCRibbonEdit* pBtn1 = new CMFCRibbonEdit(ID_RIBBON_EBTN_1, 90);
    pBtn1->SetEditText(_T("Edit"));
    pPanel1->Add(pBtn1);
    // 创建可调编辑框
    CMFCRibbonEdit* pBtn2 = new CMFCRibbonEdit(ID_RIBBON_EBTN_2, 90);
    pBtn2->EnableSpinButtons(0, 99);
    pBtn2->SetEditText(_T("0"));
    pPanel1->Add(pBtn2);
    // 创建ComboBox
    CMFCRibbonComboBox* pBtn3 = new CMFCRibbonComboBox(ID_RIBBON_EBTN_3, TRUE, 74);
    // 添加下拉选项
    pBtn3->AddItem(_T("Combo Box"));
    for (i = 0; i < 20; i++)
    {
    CString str;
    str.Format(_T("Item %d"), i + 1);
    pBtn3->AddItem(str);
    }
    pBtn3->SelectItem(0);
    pPanel1->Add(pBtn3);
    CMFCRibbonPanel* pPanel2 = pCategory->AddPanel(_T("With Icons and Labels"));
    // 创建带图标的编辑框
    CMFCRibbonEdit* pBtn4 = new CMFCRibbonEdit(ID_RIBBON_EBTN_4, 90, _T("Label:"), 0);
    pBtn4->SetEditText(_T("Edit"));
    pPanel2->Add(pBtn4);
    CMFCRibbonEdit* pBtn5 = new CMFCRibbonEdit(ID_RIBBON_EBTN_5, 90, _T("Label:"), 1);
    pBtn5->EnableSpinButtons(0, 99);
    pBtn5->SetEditText(_T("0"));
    pPanel2->Add(pBtn5);
    CMFCRibbonComboBox* pBtn6 = new CMFCRibbonComboBox(ID_RIBBON_EBTN_6, TRUE, 74, _T("Label:"), 2);
    pBtn6->AddItem(_T("Combo Box"));
    for (i = 0; i < 20; i++){
    CString str;
    str.Format(_T("Item %d"), i + 1);
    pBtn6->AddItem(str);
    }
    pBtn6->SelectItem(0);
    pPanel2->Add(pBtn6);
    CMFCRibbonPanel* pPanel3 = pCategory->AddPanel(_T("Font"));
    // 创建字体选择ComboBox
    CMFCRibbonFontComboBox::m_bDrawUsingFont = TRUE;
    CMFCRibbonFontComboBox* pBtn7 = new CMFCRibbonFontComboBox(ID_RIBBON_EBTN_7);
    pBtn7->SelectItem(_T("Arial"));
    pPanel3->Add(pBtn7);
  • 相关阅读:
    JAVA实验3 类与对象
    多种排序功能的实现
    (数据结构)HashTable的实现
    对string型变量的频率统计(文章单词检索)
    对int型变量的频率统计
    二叉搜索树中序迭代器的实现
    二叉搜索树的实现
    Prim最小生成树
    Kruscal最小生成树
    算法分析实践大作业
  • 原文地址:https://www.cnblogs.com/oneway1990/p/7603202.html
Copyright © 2020-2023  润新知