Office 2010 frame caption buttons
Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=19550
Printed Date: 19 June 2025 at 1:27am Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com
Topic: Office 2010 frame caption buttons
Posted By: Fredrik
Subject: Office 2010 frame caption buttons
Date Posted: 06 March 2012 at 11:44am
Hi,
How do I get the frame caption buttons look like Office 2010 when the MDI child window is maximized?
Thanks, Fredrik
------------- Windows 10, Visual Studio 20157, Toolkit Pro 18.3.0
|
Replies:
Posted By: TimurA
Date Posted: 15 March 2012 at 6:51am
Hi,
same problem in blue and silver office 2010 themes. In the black theme, the buttons are seen better, but their appearance is not exactly like in MSOffice 2010.
Is there a solution?
Regards, Timur
Windows 7, VS 2005, Toolkit Pro 15.0.1 and 15.2.1
|
Posted By: TimurA
Date Posted: 15 March 2012 at 10:55am
It seems to work for me with a workaround like this.
Derive the ribbonbar and override RefreshSysButtons(). Instead of CControlMDIButton, created in the CXTPMenuBar::RefreshSysButtons(), create your own buttons, which are a mix of CControlMDIButton and CXTPRibbonBarControlCaptionButton.
CControlMDIButton is used by Toolkit to draw mdi buttons in menubar, they aren't overridden in CXTPRibbonBar, therefore we are getting the appearance which is not conform to office 2010.
CXTPRibbonBarControlCaptionButton is used by Toolkit to draw frame buttons (right images on a false background).
The Draw() method of my button combines both drawing methods.
The code may be not optimal and not tested well, but I've got the desired appearance in the MDIRibbonSample.
@Codejock: is there a better way?
CXTPRibbonBar* pRibbonBar = (CXTPRibbonBar*)pCommandBars->Add(_T("The Ribbon"), xtpBarTop, RUNTIME_CLASS(CHypRibbonBar));
#pragma once
class CHypRibbonBar : public CXTPRibbonBar { DECLARE_XTP_COMMANDBAR(CHypRibbonBar)
public: CHypRibbonBar(); ~CHypRibbonBar();
virtual void RefreshSysButtons();
protected: void AddSysButtonEx(int nId); };
//______________________________________________________________________________________
#include "stdafx.h" #include "HypRibbonBar.h"
//______________________________________________________________________________________
class CHypControlMDIButton : public CXTPControlButton { public: CHypControlMDIButton(CXTPCommandBarsFrameHook* pFrame) { m_pFrame = pFrame; m_dwFlags |= xtpFlagRightAlign | xtpFlagSkipFocus | xtpFlagManualUpdate | xtpFlagNoMovable; } CSize GetSize(CDC* pDC) { CSize sz = __super::GetSize(pDC); int nSize = sz.cy;
//return CSize(16, 16); return CSize(nSize, nSize); }; void SetBeginGroup(BOOL /*bBeginGroup*/) { } void Draw(CDC* pDC) { //GetPaintManager()->DrawControlMDIButton(pDC, this); // background of MDIButton GetPaintManager()->DrawControlEntry(pDC, this);
// icon of CaptionButton, but without background! ((CXTPRibbonBar*)GetParent())->GetPaintManager()->GetFramePaintManager()-> DrawFrameCaptionButton(pDC, GetRect(), GetStdId(), FALSE/*GetSelected()*/, FALSE/*GetPressed()*/, m_bEnabled && m_pFrame->IsFrameActive()); } void OnExecute() { // we'll use some protected members class _MenuBar : public CXTPMenuBar { friend class CHypControlMDIButton; };
HWND hWndChild = ((_MenuBar*)(CXTPMenuBar*)m_pParent)->GetActiveMdiChildWnd(); ASSERT(hWndChild);
UINT nId = GetStdId();
::PostMessage(hWndChild, WM_SYSCOMMAND, nId, 0); }
UINT GetStdId() const { UINT nId = m_nId == XTP_ID_MENUBAR_CLOSE ? SC_CLOSE : m_nId == XTP_ID_MENUBAR_RESTORE ? SC_RESTORE : SC_MINIMIZE; return nId; }
protected: CXTPCommandBarsFrameHook* m_pFrame; };
//______________________________________________________________________________________
IMPLEMENT_XTP_COMMANDBAR(CHypRibbonBar, CXTPRibbonBar)
//______________________________________________________________________________________
CHypRibbonBar::CHypRibbonBar() { }
//______________________________________________________________________________________
CHypRibbonBar::~CHypRibbonBar() { }
//______________________________________________________________________________________
void CHypRibbonBar::RefreshSysButtons() { //CXTPMenuBar::RefreshSysButtons();
BOOL bMax = FALSE; HWND hWndActiveChild = GetActiveMdiChildWnd(&bMax); DWORD dwStyle = hWndActiveChild ? GetWindowLong(hWndActiveChild, GWL_STYLE) : 0;
CXTPControl* pButton = m_pControls->FindControl(XTP_ID_MENUBAR_SYSMENU);
/* if (bMax && (m_dwFlags & xtpFlagAddMDISysPopup)) { HMENU hDocMenuButton = pButton ? ((CControlMDISysMenuPopup*)pButton)->m_hDocMenu : 0;
HMENU hDocMenu = ::GetSystemMenu(hWndActiveChild, FALSE); if (hDocMenu && ::IsMenu(hDocMenu)) { if (hDocMenuButton != hDocMenu) { if (pButton) { ((CControlMDISysMenuPopup*)pButton)->SetMDISysMenu(hWndActiveChild, hDocMenu); DelayRedraw(); } else { AddSysButton(new CControlMDISysMenuPopup(hWndActiveChild, hDocMenu), XTP_ID_MENUBAR_SYSMENU, _T(""), 0); } } } else { if (pButton) m_pControls->Remove(pButton); } } else */if (pButton) m_pControls->Remove(pButton);
pButton = m_pControls->FindControl(XTP_ID_MENUBAR_MINIMIZE); if (!pButton && bMax && (dwStyle & WS_MINIMIZEBOX) && (dwStyle & WS_SYSMENU) && (!(m_dwFlags & xtpFlagHideMinimizeBox))) //AddSysButton(new CHypControlMDIButton(), XTP_ID_MENUBAR_MINIMIZE, _T("0")); AddSysButtonEx(XTP_ID_MENUBAR_MINIMIZE); else if (pButton && !bMax) m_pControls->Remove(pButton);
pButton = m_pControls->FindControl(XTP_ID_MENUBAR_RESTORE); if (!pButton && bMax && (dwStyle & WS_MAXIMIZEBOX) && (dwStyle & WS_SYSMENU) && (!(m_dwFlags & xtpFlagHideMaximizeBox))) //AddSysButton(new CHypControlMDIButton(), XTP_ID_MENUBAR_RESTORE, _T("2")); AddSysButtonEx(XTP_ID_MENUBAR_RESTORE); else if (pButton && !bMax) m_pControls->Remove(pButton);
pButton = m_pControls->FindControl(XTP_ID_MENUBAR_CLOSE); if (!pButton && bMax && (dwStyle & WS_SYSMENU) && (!(m_dwFlags & xtpFlagHideClose))) //AddSysButton(new CHypControlMDIButton(), XTP_ID_MENUBAR_CLOSE, _T("r")); AddSysButtonEx(XTP_ID_MENUBAR_CLOSE); else if (pButton && !bMax) m_pControls->Remove(pButton);
if (IsFrameThemeEnabled()) { CString strWindowText; GetSite()->GetWindowText(strWindowText);
if (strWindowText != m_strCaptionText) DelayLayout(); } }
//______________________________________________________________________________________
void CHypRibbonBar::AddSysButtonEx(int nId) { CHypControlMDIButton* pButton = new CHypControlMDIButton(GetFrameHook()); m_pControls->Add(pButton, nId);
UINT nStdId = pButton->GetStdId(); // XTP_ID_MENUBAR_CLOSE -> SC_CLOSE
CString strCaption; CMenu* pMenu = GetSite()->GetSystemMenu(FALSE); if (pMenu) { pMenu->GetMenuString(nStdId, strCaption, MF_BYCOMMAND); int nIndex = strCaption.Find(_T('\t')); if (nIndex > 0) { strCaption = strCaption.Left(nIndex); } } if (pButton->GetAction()) { pButton->GetAction()->SetCaption(_T("")); pButton->GetAction()->SetDescription(NULL); }
pButton->SetDescription(NULL); pButton->SetCaption(_T("")); pButton->SetTooltip(strCaption); }
//______________________________________________________________________________________
|
|