Author: Wuhuan
Test environment: Windows XP
Development Environment: Visual Studio 2010
To change the height of cmfcribbonbar, You need to reload the calcfixedlayout function, for example:
Header file:
#pragma once//////////////////////////////////////////////////////////////////////////// CKofMFCRibbonQuickAccessToolBarclass CKofMFCRibbonQuickAccessToolBar : public CMFCRibbonQuickAccessToolBar{friend class CKofMFCRibbonBar;};//////////////////////////////////////////////////////////////////////////// CKofMFCRibbonBarclass CKofMFCRibbonBar : public CMFCRibbonBar{DECLARE_DYNAMIC(CKofMFCRibbonBar)public:CKofMFCRibbonBar(BOOL bReplaceFrameCaption = TRUE);virtual ~CKofMFCRibbonBar();protected:virtual CSize CalcFixedLayout(BOOL bStretch, BOOL bHorz);DECLARE_MESSAGE_MAP()};
Implementation file:
# Include "stdafx. H "# include" kofmfcribbonbar. H "static const int nxtabmargin = 14; static const int nytabmargin = 5; static const int nxmargin = 2; static const int nymargin = 2; //////////////////////////////////////// //// // ckofmfcribbonbarimplement_dynamic (ckofmfcribbonbar, cmfcribbonbar) ckofmfcribbonbar: ckofmfcribbonbar (bool breplaceframecaption/* = true */): cmfcribbon Bar (breplaceframecaption) {} ckofmfcribbonbar ::~ Callback () {} callback (callback, cmfcribbonbar) end_message_map () csize layout: calcfixedlayout (bool bstretch, bool bhorz) {assert_valid (this); cclientdc (this ); cfont * poldfont = dc. selectObject (getfont (); Ensure (poldfont! = NULL); textmetric TM; DC. gettextmetrics (& TM); // "title" height m_ncaptionheight = 0; If (m_breplaceframecaption) {m_ncaptionheight = getsystemmetrics (sm_cycaption) + 1; if (afxglobaldata. dwmiscompositionenabled () {m_ncaptionheight + = getsystemmetrics (sm_cysizeframe) ;}} int Cy = 0; csize sizemainbutton = m_sizemainbutton; double scale = afxglobaldata. getribbonimagescale (); If (scale> 1 .) {sizemainbutton. cx = (INT )(. 5 + scale * sizemainbutton. CX); sizemainbutton. cy = (INT )(. 5 + scale * sizemainbutton. cy);} If (m_dwhideflags & tags) {Cy = m_ncaptionheight;} else {If (m_brecalccategoryheight) {m_ncategoryheight = 0;} // The height of the "tab" m_ntabsheight = TM. tmheight + 2 * nytabmargin; If (m_brecalccategoryheight) {for (INT I = 0; I <m_arcategories.getsize (); I ++) {cmfcribboncategory * pcategory = m_arcategories [I ]; Assert_valid (pcategory); m_ncategoryheight = max (m_ncategoryheight, pcategory-> getmaxheight (& DC);} rows = false;} Comment * pqatoolbar = (comment *) & m_qatoolbar; const csize sizeaqtoolbar = pqatoolbar-> getregularsize (& DC); If (isquickaccesstoolbarontop () {m_ncaptionheight = max (m_ncaptionheight, sizeaqtoolbar. cy + (iswindows7look ()? 0: (2 * nymargin);} // const int nquickaceestoolbarheight = isquickaccesstoolbarontop () on the "quick access toolbar ()? 0: sizeaqtoolbar. Cy; // height of the "classification" const int ncategoryheight = (m_dwhideflags & afx_ribbonbar_hide_elements )? 0: m_ncategoryheight; Cy = nquickaceestoolbarheight + ncategoryheight + max (m_ncaptionheight + m_ntabsheight, m_sizemainbutton.cy + nymargin);} If (afxglobaldata. dwmiscompositionenabled () {If (getparent ()-> iszoomed () & m_breplaceframecaption) {Cy + =: getsystemmetrics (sm_cysizeframe)-2 ;}} DC. selectObject (poldfont); Return csize (32767, CY );}
Modify the mainfrm. h file as follows:
#include "KofMFCRibbonBar.h"class CMainFrame : public CMDIFrameWndEx{//...protected: //CMFCRibbonBar m_wndRibbonBar;CKofMFCRibbonBar m_wndRibbonBar;}
In this way, the running result is as is, as shown in:
Now try to change the height and modify the above Code. The act of modifying 82 is as follows:
| M_ncategoryheight = max (m_ncategoryheight, pcategory-> getmaxheight (& DC) + 80 ); |
Change 98 as follows:
| Const int ncategoryheight = (m_dwhideflags & afx_ribbonbar_hide_elements )? 0: m_ncategoryheight + 20; |
Re-compile and run, as shown in the following figure: