1、对话框中添加pic control
2、对话框类头文件中声明:
void InitRibbonBar();
CStatic m_wndRibbonPlaceHolder;
CBCGPRibbonBar m_wndRibbonBar;
CBCGPRibbonMainButton m_MainButton;
3、实现文件中:
BOOL CRibbonDialogDlg::OnInitDialog()
{
CBCGPDialog::OnInitDialog();
{
CRect rectRibbon;
m_wndRibbonPlaceHolder.GetWindowRect(rectRibbon);
ScreenToClient(rectRibbon);
m_wndRibbonBar.Create(this);
m_wndRibbonBar.SetWindowPos(NULL, rectRibbon.left, rectRibbon.top, rectRibbon.Width(), m_wndRibbonBar.GetDefaultHeight(), SWP_NOZORDER | SWP_NOACTIVATE);
m_wndRibbonBar.SetOwner(this);
m_wndRibbonBar.ModifyStyle(0, WS_TABSTOP);
InitRibbonBar();
CBCGPStaticLayout* pLayout = (CBCGPStaticLayout*)GetLayout();
if (pLayout != NULL)
{
pLayout->AddAnchor(m_wndRibbonBar.GetSafeHwnd(), CBCGPStaticLayout::e_MoveTypeNone, CBCGPStaticLayout::e_SizeTypeHorz);
pLayout->AddAnchor(IDOK, CBCGPStaticLayout::e_MoveTypeBoth, CBCGPStaticLayout::e_SizeTypeNone);
pLayout->AddAnchor(IDCANCEL, CBCGPStaticLayout::e_MoveTypeBoth, CBCGPStaticLayout::e_SizeTypeNone);
}
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CRibbonDialogDlg::InitRibbonBar()
{
m_MainButton.SetToolTipText(_T("File"));
m_MainButton.SetText(_T("\nf"));
m_MainButton.SetScenicText(_T("File"));
m_wndRibbonBar.SetMainButton(&m_MainButton, CSize(0, 0));
m_wndRibbonBar.SetScenicLook();
CBCGPRibbonMainPanel* pFile1 = m_wndRibbonBar.AddMainCategory(_T("File"), IDB_RIBBON_FILE_SMALL, IDB_RIBBON_FILE_LARGE);
pFile1->Add(new CBCGPRibbonButton(ID_FILE_NEW, _T("New\n"), 0, 0));
CBCGPRibbonCategory* pTest = m_wndRibbonBar.AddCategory(_T("test"), IDB_RIBBON_FILE_SMALL, IDB_RIBBON_FILE_LARGE);
CBCGPRibbonPanel* pPanelClipboard = pTest->AddPanel(_T("test"));
pPanelClipboard->Add(new CBCGPRibbonButton(ID_FILE_NEW, _T("New\n"), 0, 0));
pPanelClipboard->Add(new CBCGPRibbonButton(ID_EDIT_COPY, _T("Cut\n"), 0, 0));
CBCGPRibbonCategory* pHome = m_wndRibbonBar.AddCategory(_T("home"), IDB_RIBBON_FILE_SMALL, IDB_RIBBON_FILE_LARGE);
m_wndRibbonBar.ForceRecalcLayout();
}
实现的效果图如下所示: