Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Using Ribbon in a dialog
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Using Ribbon in a dialog

 Post Reply Post Reply
Author
Message
yves View Drop Down
Newbie
Newbie


Joined: 05 June 2017
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote yves Quote  Post ReplyReply Direct Link To This Post Topic: Using Ribbon in a dialog
    Posted: 05 June 2017 at 6:38pm
Hello. Is this possible to use Ribbon in a dialog? Does anyone have an example? Thanks.
Back to Top
Alex H. View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 February 2004
Status: Offline
Points: 266
Post Options Post Options   Thanks (1) Thanks(1)   Quote Alex H. Quote  Post ReplyReply Direct Link To This Post Posted: 12 June 2017 at 9:23am
Hi!
Yes it works :-)

Have a look at:
Samples\CommandBars\DialogSample\DialogSampleDlg.cpp(197)

I can send you some snippets :-)

derive your dialog from
CXTPDialogBase<CXTResizeDialog>

in OnInitDialog create your commandbars

// Initialize the command bars if(!InitCommandBars()) { return -1; } // Get a pointer to the command bars object. CXTPCommandBars* pCommandBars = GetCommandBars(); if(pCommandBars == NULL) { return -1;      // fail to create }
 then create your ribbon:

CXTPRibbonBar* pRibbonBar = (CXTPRibbonBar*)pCommandBars->Add(_T(""), xtpBarTopRUNTIME_CLASS(CXTPRibbonBar)); if (!pRibbonBar) { return FALSE; }
pRibbonBar->EnableDocking(0); pRibbonBar->EnableCustomization(FALSE);
...

CXTPRibbonTab* pTabBase = pRibbonBar->AddTab( CMfxString(IDS_RIBBON_START) );
...

you will nedd a helper

//---------------------------------------------------------------------------------------  void CDlgMailNew::RepositionControls() //---------------------------------------------------------------------------------------  { if (m_bInRepositionControls) return; CRect rcClientStart; GetClientRect(rcClientStart); if ((GetStyle() & WS_MINIMIZE) || (rcClientStart.IsRectEmpty())) return; m_bInRepositionControls = TRUE; CRect rcClientNow; RepositionBars(AFX_IDW_CONTROLBAR_FIRSTAFX_IDW_CONTROLBAR_LAST, 0, reposQuery, rcClientNow); CRect rcBorders(rcClientNow.left - rcClientStart.left, rcClientNow.top - rcClientStart.top,  rcClientStart.right - rcClientNow.right,  rcClientStart.bottom - rcClientNow.bottom); if (rcBorders != m_rcBorders) { CPoint ptOffset(rcBorders.left - m_rcBorders.left, rcBorders.top - m_rcBorders.top); CSize szOffset(rcBorders.left + rcBorders.right - m_rcBorders.left - m_rcBorders.right, rcBorders.top + rcBorders.bottom - m_rcBorders.top - m_rcBorders.bottom); m_ptRepositionOffset = ptOffset; CRect rcWindow; GetWindowRect(rcWindow); rcWindow.BottomRight() += szOffset; Offset(ptOffset); m_szWindow += szOffset; m_szMin += szOffset; MoveWindow(rcWindow, TRUE); } m_rcBorders = rcBorders; RepositionBars(AFX_IDW_CONTROLBAR_FIRSTAFX_IDW_CONTROLBAR_LAST, 0); m_bInRepositionControls = FALSE; }

----

call this helper in OnSize and in OnInitDialog

:-)


Back to Top
cpede View Drop Down
Senior Member
Senior Member


Joined: 13 August 2004
Location: Denmark
Status: Offline
Points: 668
Post Options Post Options   Thanks (0) Thanks(0)   Quote cpede Quote  Post ReplyReply Direct Link To This Post Posted: 10 June 2020 at 2:48am
This was very useful for displaying Ribbons in a dialog.

But how do I remove/delete the Ribbon bar runtime from code in the dialog.

1) Using Remove on the Toolbar does not fully do the trick, since there still is an empty window/background in the ribbon area left?
2) SetVisible(FALSE) hides the toolbar but also leaves an empty window/background.
3) delete CommandBars is virtual and cannot be called

There is missing the opposite to InitCommandBars to fully remove the ribbon?

-cpede
Product: Xtreme ToolkitPro (24.0.0)
Platform: Windows 10 (x64)
Language: Visual Studio 2017 (C++)
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.203 seconds.