30433

Updating CMFCRibbonBar elements from document

Question:

I would like to update the ribbon from the CDocument derived class because the information relevant for ribbon's status is stored there. The was created by the Wizard and edited in resource manager

Some elements (Buttons, checkboxes) can be updated with ON_UPDATE_COMMAND_UI macro.

But I have a headache with update other things like CMFCRibbonComboBox or CMFCRibbonProgressBar because CCmdUI doesn't provide suitable functions to deal with them (ie AddItem)

Other option using GetDlgItem doesn't work, because neither CDocument nor RibbonBar elements are derived from CWnd.

So what is the way to update CMFCRibbonComboBox and others?

Answer1:

I faced a similar problem with combo boxes on a toolbar. The combo box was used to display the current mouse coordinates of a point in "world coordinate" space while the mouse was moved. I derived my own class for the combo and exposed some methods that would update its contents. I then picked the most appropriate point in the code to make the appropriate calls to those methods. That may be during the paint cycle (eg. OnDraw), or, during idle time. A similar approach of deriving and exposing methods should work for you. The only caveat is to pick the correct location to inject your calls to perform the update.

Answer2:

I first tried RogerRowland's solution, but it soon became annoying to add a function to MainFrame for every trifle , then to call AfxGetMainWnd() from document and apply static_cast on it.

Instead I now store pointers to the ProgressBar and the combobox inside the document. I added the methods to CMainFrame to get them and removed the rest.

The only dificulty with it is the fact that the document is constructed before the main window. So I have to delay the initialisation of the mentioned pointers. I solved it by adding setRibbonBarPointers() to the document and calling it from OnInitialUpdate() of the view

Recommend

  • How to choose the right buffer to draw and stop it from swapping continuously
  • c++ Template error in main function?
  • Resurrecting MFC/Visual Studio 6.0 project in VS2010
  • How to detect whether a control is standard or active-x control?
  • Using Oozie ssh action with private key
  • Automata with kleene star
  • How define differents stores for each cell combobox editor in a grid?
  • How to integrate a custom GraphicsItem into a QML scene?
  • “Big” scrollbar for spinner
  • Get back anonymous type [duplicate]
  • Is it safe to cast void pointer to char pointer pointer
  • How to correctly append dynamic GetUIKit accordions?
  • How can I organize this data into the objects I want with LINQ?
  • Detecting a shift + click with Jquery on Chrome
  • getFinancials (quantmod) and tq_get (tidy quant) not working?
  • OpenCV Python: Draw minAreaRect ( RotatedRect not implemented)
  • WP7 difficulties binding data to listbox itemssource - won't refresh
  • XNU incudes in Kext
  • Most efficient way to replace lowest list values in dataframe in R
  • Detecting # in Scheme list
  • How can I mock ui-router's resolve values when testing a state's configuration?
  • Combining two different ActiveRecord collections into one
  • Using Sax parsing to edit and write XML in VB6
  • C++ pointer value changes with static_cast
  • how to avoid repetitive constructor in children
  • How integrated is Collada to OpenGL ES
  • debug library loaded with ctypes using gdb
  • Admob requires api-13 or later can I not deploy on old API-8 phones?
  • Spark fat jar to run multiple versions on YARN
  • output of program is not same as passed argument
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Join two tables and save into third-sql
  • How to model a transition system with SPIN
  • ActionScript 2 vs ActionScript 3 performance
  • Statically linking a C++ library to a C# process using CLI or any other way
  • ORA-29908: missing primary invocation for ancillary operator
  • Google cloud sdk not working when python points python3
  • Why winpcap requires both .lib and .dll to run?
  • json Serialization in asp
  • Converting MP3 duration time