Skip to content

Example code for manual main app button entry #4252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/mfc/how-to-customize-the-application-button.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,27 @@ The Application menu does not appear on the design surface. To view it, you must
#### To preview the ribbon control

- On the **Ribbon Editor Toolbar**, click **Test Ribbon**.
## Example
```
int MainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWndEx::OnCreate(lpCreateStruct) == -1)
return -1;

m_wndRibbonBar.Create(this);
m_wndRibbonBar.LoadFromResource(IDR_RIBBON);

// Customize the main button collection of elements by adding fx an Inventory button. Using the Resource Editor open the Ribbon Editor and insert a new button giving it fx ID_INVENTORY as its id. The Ribbon Editor enters it into the Resoure.h file. Unlike the other items in this page (Open, Save, Print and Exit), the new Inventory item has to be manually provisioned with key, tooltip and description.
CArray<CMFCRibbonBaseElement*, CMFCRibbonBaseElement*> inventoryButton;
m_wndRibbonBar.GetElementsByID( ID_INVENTORY, inventoryButton ); // retrieve the inventory ribbon element that the ribbon editor created
auto inventoryButtonData = inventoryButton.GetData(); // gets the new ribbon element's data
if( *inventoryButtonData != nullptr ) // could be null
{
( *inventoryButtonData )->SetKeys( L"i" );
( *inventoryButtonData )->SetToolTipText( L"Items for sale" );
( *inventoryButtonData )->SetDescription( L"Lists inventory of sales items." );
}
```
## See also

[Ribbon Designer (MFC)](ribbon-designer-mfc.md)