0

I'm upgrading an old MFC project to use the MFC Feature Pack and Ribbon. I changed a pane derived from CControlBar to be derived from CDockablePane and it works great, however it still looks old and does not blend with the ribbon look and theme. The Pane also has buttons that still look old.

How do I change the look, feel or theme of a CDockablePane derived object and buttons derived from CButton?

I'm using the following code to draw the button, is the best way to simply change the background?

void CFolderButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{   
    UINT uState=DFCS_BUTTONPUSH;
    if( lpDrawItemStruct->itemState & ODS_SELECTED )
    {
        uState|=DFCS_PUSHED;
    }

    //CDC dc;
    CDC* dc = CDC::FromHandle(lpDrawItemStruct->hDC);


    dc->DrawFrameControl(&lpDrawItemStruct->rcItem,DFC_BUTTON,uState);
    if( !IsWindowEnabled() )
    {
        dc->SetTextColor(::GetSysColor(COLOR_3DSHADOW));        
    }

    CString csText;
    GetWindowText(csText);

    if (m_iDisplayType != 2 || !m_hIcon)
    {
        LOGFONT lf;
        memset(&lf, 0, sizeof(LOGFONT)); 
        lf.lfHeight = m_iFontSize;                      
        strcpy(lf.lfFaceName, "Tahoma Bold");       
        VERIFY(font.CreateFontIndirect(&lf));  

        CFont* def_font = dc->SelectObject(&font);

        RECT buttonRect = lpDrawItemStruct->rcItem;
        buttonRect.left += 10;
        buttonRect.right += 10;

        if (m_iDisplayType != 1 || !m_hIcon) //text & Icon
        {
            buttonRect.left += 30;
            buttonRect.right += 30;
        }   
        dc->DrawText(csText,&buttonRect,DT_LEFT|DT_SINGLELINE|DT_VCENTER);  

        dc->SelectObject(def_font);

        font.DeleteObject();
    }


    if (m_hIcon && m_iDisplayType != 1)
    {   
        CSize czText = dc->GetTextExtent(csText);
        dc->DrawIcon(0,0,m_hIcon);
    }
}

The following image shows the contrast between the buttons and the ribbon:

DockablePane contrast to ribbon

Jak
  • 471
  • 5
  • 20

1 Answers1

1

The new MFC uses a CMFCVisualManager. And drawing using the current styles isn't easy.

This class is virtual and used for all drawings in the specific style of the application.

Just look into the source of CMFCToolBarButton::OnDraw and see how all kinds of Buttons and text are drawn.

PS: May be it is easier to create a new CMFCToolBar if there are just Buttons and controls in it. PPS: Or embed a new CMFCToolBar in the CDockingPane.

xMRi
  • 14,982
  • 3
  • 26
  • 59
  • The buttons open up to allow a CTreeCtrl object to be displayed, so I don't think a toolbar would be useful, thanks for the input, I'll look into it. – Jak Oct 08 '14 at 09:04
  • OK, than add a CMFCToolBar to your docking pane... this Control knows how to draw itself ;) – xMRi Oct 08 '14 at 09:24
  • I'd really like to not redo all the code... I am using CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows7)); in CMainFrame::OnCreate but the panes don't change, do I need to add it to the OnCreate for the Panes? – Jak Oct 08 '14 at 09:42
  • Just setting this manager is not sufficient. You Need to use it. Look into the function I mentioned in my answer. – xMRi Oct 08 '14 at 10:14