Liam P
Liam P

Reputation: 217

Add functions to the Main Menu at the top of a window

I would like to add sub options to the Main Menu at the top of a main frame window in MFC.

For example; File>Open, or Edit>Undo.

Top ToolBar

Is this possible to do at all? My intention is to replace the function of some buttons in my program with options typically found in the drop down menus

Also after adding an item to the Main Menu how would you use it to call a function?

Upvotes: 0

Views: 2194

Answers (1)

Andrew Truckle
Andrew Truckle

Reputation: 19197

Here I have added an entry to the View menu called Test:

Add menu item

When I build and runt he program it shows disabled:

Disabled

This is because I still have to create an event handler. In the resource editor you right-click the menu item and select Add Event handler:

Add

This brings up the class wizard:

Class wizard

On the dialogue there are a couple of menu event handlers to choose from. Select the one you need (as in the screen shot) but don't forget to choose the right class on the right. Then click Add and Edit.

Now you can add your event handler functionality. Example:

void CMainFrame::OnViewTest()
{
    AfxMessageBox(_T("Hello!"), MB_OK | MB_ICONINFORMATION);
}

When I compile and run this:

Popup message

Hopefully this will help you get up and running.

Upvotes: 1

Related Questions