重载一个类 // MFCRibbonChsPanel.h #pragma once // CMFCRibbonChsPanel 命令目标 class CMFCRibbonChsPanel : public CMFCRibbonPanel { DECLARE_DYNCREATE(CMFCRibbonChsPanel) public: CMFCRibbonChsPanel(LPCTSTR lpszName = NULL, HICON hIcon = NULL); CMFCRibbonChsPanel(CMFCRibbonGallery* pPaletteButton); //CMFCRibbonChsPanel(); virtual ~CMFCRibbonChsPanel(); void SetYMargin(int _nYMargin){m_nYMargin = _nYMargin;} }; // MFCRibbonChsPanel.cpp #include "stdafx.h" #include "MFCRibbonChsPanel.h" // CMFCRibbonChsPanel IMPLEMENT_DYNCREATE(CMFCRibbonChsPanel, CMFCRibbonPanel) CMFCRibbonChsPanel::CMFCRibbonChsPanel(LPCTSTR lpszName /*= NULL*/, HICON hIcon /*= NULL*/) : CMFCRibbonPanel(lpszName, hIcon) { } CMFCRibbonChsPanel::CMFCRibbonChsPanel(CMFCRibbonGallery* pPaletteButton) : CMFCRibbonPanel(pPaletteButton) { } CMFCRibbonChsPanel::~CMFCRibbonChsPanel() { } 使用方法: CMFCRibbonChsPanel* pPanelClipboard = (CMFCRibbonChsPanel*)pCategoryHome->AddPanel(strTemp, m_PanelImages.ExtractIcon(27), RUNTIME_CLASS(CMFCRibbonChsPanel)); pPanelClipboard->SetYMargin(6); //设置间距为6