如何在SDI应用程序中以编程方式添加菜单? [英] How to add Menu programmatically in SDI application??

查看:92
本文介绍了如何在SDI应用程序中以编程方式添加菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以编程方式添加菜单.并想向其中添加一些菜单项,并将处理程序附加到菜单项中.

i need to add Menu programmatically. and want to add some menu item to it and append a handler to the menuitems.

Can you help me how it can be done??

推荐答案

POINT point;
CMenu menuHelp;

GetCursorPos(&point);
menuHelp.LoadMenu(IDR_MENU_SYSTRAY);
CMenu*pSubMenu = menuHelp.GetSubMenu(0);
pSubMenu->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this);



如您所见,这段代码在光标位置创建了菜单,您可能需要更改菜单,但是原理是相同的.

同样,当您为菜单创建资源时,您应该知道该代码显示的是第一个子菜单而不是主菜单本身!
例如,如果您传递主程序菜单IDR_MAINFRAME的ID,则上面的代码将显示文件菜单而不是主菜单的内容(文件|编辑|查看...")

将处理程序添加到以这种方式创建的菜单的菜单项中,与通常情况没有有所不同.您可以转到菜单资源,右键单击一个项目并添加事件处理程序.

附加菜单项:
您可以在新创建的基于对话框的应用程序的OnInitDialog函数中查看其操作方式.看看他们如何将关于..."项附加到系统菜单



As you can see this piece of code creates the menu at the cursor position, you may have to change that, but the principle is the same.

Also you should know when you create the resource for the menu, that this code shows the first submenu not the primary menu itself!
For example if you pass the ID of the main program menu IDR_MAINFRAME the code above will show the content of the File menu not the main menu ("File | Edit | View ...")

appending handlers to the menuitems of a menu created that way is no different than usual. you go to the menu resource, right click on an item and add event handler that''s it.

Appending menu items:
You can see how it''s done in a newly created dialog based application''s OnInitDialog function. see how they append the "About..." item to the system menu


这篇关于如何在SDI应用程序中以编程方式添加菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆