如何从CMFCPopupMenu获取选定的命令ID? [英] How to get selected command ID from CMFCPopupMenu?

查看:66
本文介绍了如何从CMFCPopupMenu获取选定的命令ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从CMFCPopupMenu获取选定的命令ID时遇到麻烦.有一个成员函数:
CMFCToolBarMenuButton * GetSelItem(),该函数应该返回指向当前所选菜单命令的指针,但是,我总是从该函数获取NULL.以下是我使用的代码,请帮忙!

CMFCPopupMenu * pPopupMenu = new CMFCPopupMenu;
if(pPopupMenu-> Create(pWnd,point.x,point.y,hMenu)){
CMFCToolBarMenuButton * button = pPopupMenu-> GetSelItem();
....
}

hMenu是正确的菜单句柄,而pWnd是弹出菜单的父窗口.但是,无论用户选择菜单的哪个命令,按钮始终为NULL.

非常感谢!

Hi, I'm having trouble getting the selected command ID from CMFCPopupMenu. There is a member function:
CMFCToolBarMenuButton *GetSelItem(), which is supposed to return a pointer to the currently selected menu command, however, I always get NULL from this function.  Below is the code I use, Please help!

CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;
if(pPopupMenu->Create(pWnd, point.x, point.y, hMenu)){
   CMFCToolBarMenuButton *button = pPopupMenu->GetSelItem();
   ....
}

hMenu is the proper menu handle and pWnd is the parent window of the popup menu. However button is always NULL, no matter which command of the menu is selected by user.

Thanks a lot!

推荐答案

看以下几点

1)您已经创建了CMFCPopupMenu对象,并将内存分配给了指针
CMFCPopupMenu * pPopupMenu = new CMFCPopupMenu;


2 )现在您已经在某个特定位置创建了菜单

pPopupMenu-> Create(pWnd,point.x,point.y,hMenu)


3)在这里尝试从菜单中获取选定的项目.但是到目前为止,您还没有选择任何菜单项目,因此它只返回NULL在此行之前做一件事,只需从Popup Manu中选择一个菜单项,然后使用GetSelItem()再次尝试即可.确保您将获得正确的结果.

CMFCToolBarMenuButton * button = pPopupMenu-> GetSelItem();

Thanx
Have a look on The Following Point

1) you had create a Object of CMFCPopupMenu and Allocated the memory to your pointer
CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;


2) Now you had Created The menu at some particular Place

   pPopupMenu->Create(pWnd, point.x, point.y, hMenu)


3) Here you are trying to Get selected item from menu .But upto now you had not selected any menu item so it eill return your NULL only Do one thing before this line just select a Menu item from your Popup Manu and then Try once again with GetSelItem() i am sure you will get proper result .

  CMFCToolBarMenuButton *button = pPopupMenu->GetSelItem();

Thanx


这篇关于如何从CMFCPopupMenu获取选定的命令ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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