Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Office 2010 frame caption buttons
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Office 2010 frame caption buttons

 Post Reply Post Reply
Author
Message
Fredrik View Drop Down
Senior Member
Senior Member


Joined: 22 June 2005
Status: Offline
Points: 235
Post Options Post Options   Thanks (0) Thanks(0)   Quote Fredrik Quote  Post ReplyReply Direct Link To This Post Topic: Office 2010 frame caption buttons
    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
Back to Top
TimurA View Drop Down
Newbie
Newbie


Joined: 15 March 2012
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote TimurA Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
TimurA View Drop Down
Newbie
Newbie


Joined: 15 March 2012
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote TimurA Quote  Post ReplyReply Direct Link To This Post 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);
}

//______________________________________________________________________________________
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.063 seconds.