简体   繁体   中英

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.

顶部工具栏

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?

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

添加菜单项

When I build and runt he program it shows 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 :

加

This brings up the 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:

弹出消息

Hopefully this will help you get up and running.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM