none
Unexpected category retrieved

    Question

  • I created a button of ID_FILE_SAVE under "Home" category on the ribbon of CMFCRibbonBar  type, I tried to get the category containing this button using pButton->GetParentCategory(), which should be the category with m_strName of "Home", however an unexpected category was retrieved, whose m_strName is "Category1".

    Actually the category with the name "Category1" is the last category on the ribbon, which is empty and doesn't show in running the application, but I cannot removed it in the ribbon design mode. How to remove it?

    Could you please let me know how to get the correct category "Home" containing the button ID_FILE_SAVE?

    Thanks in advance.

    Monday, February 11, 2019 3:39 PM

Answers

  • Thanks for your suggestion.

    I need to change the name of the ID from ID_FILE_SAVE to another name, then expected category can be retrieved. It seems to me ID_FILE_SAVE is used by system.

    • Marked as answer by Yan Yang Thursday, February 14, 2019 8:54 AM
    Wednesday, February 13, 2019 6:11 PM

All replies

  • Following snippet returned the proper name of a Tab in response to a button click -

    CMFCRibbonButton *pButton = (CMFCRibbonButton *)m_wndRibbonBar.FindByID(ID_BUTTON2);
    CMFCRibbonCategory *pCategory = pButton->GetParentCategory();
    AfxMessageBox(pCategory->GetName());
    

    To delete a category in the resource editor select the category in the ribbon editor and press the delete key or right click and select delete from the context menu.

    Monday, February 11, 2019 4:47 PM
  • Thanks very much for your suggestion.

    I tried implementing your code, the displayed name in the message box is "Category1", not the expected name "Home".

    I also tried deleting tab "Category1", the "delete" command on the context menu is greyed out.

    Monday, February 11, 2019 5:19 PM
  • I suggest you try creating a new MFC ribbon project to see if it exhibits this unusual behavior.
    Monday, February 11, 2019 6:49 PM
  • Thanks for your suggestion.

    I need to change the name of the ID from ID_FILE_SAVE to another name, then expected category can be retrieved. It seems to me ID_FILE_SAVE is used by system.

    • Marked as answer by Yan Yang Thursday, February 14, 2019 8:54 AM
    Wednesday, February 13, 2019 6:11 PM
  • Hi,

    I am glad you have got your solution and thanks for your sharing, I would appreciate it if you mark them as answer and this will be beneficial to other community.

    Best Regards,

    Jeanine Zhang

    Thursday, February 14, 2019 8:37 AM