win7上使用TrackPopupMenu的问题
我试图在我的应用程序中使用 TrackPopupMenu 函数创建上下文菜单,我在其中使用的代码如下所示:
CMenu menu;
if (menu.LoadMenu(IDR_MENU_TRAY))
{
CMenu* pSubMenu = menu.GetSubMenu(0);
if (pSubMenu != NULL)
{
pSubMenu->ModifyMenu(IDM_CLOSE,MF_BYCOMMAND,IDM_CLOSE ,g_cfg->GetLang(TEXT_MAIN_CLOSE,"Exit(&X)"));
pSubMenu->ModifyMenu(IDM_SHOW,MF_BYCOMMAND,IDM_SHOW ,g_cfg->GetLang(TEXT_MAIN_OPEN_SHUTTER,"Open(&O)"));
CPoint point;
GetCursorPos(&point);
SetForegroundWindow();
pSubMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, messageOnlyWnd);
}
}
该代码在 WinXP 上运行完美,而在 win7 和 vista 上则不然。 win7和vista上的问题是弹出菜单需要相当长的时间,可能1分钟或更长时间。但是如果我在win7或vista上关闭Aero,它会像在winXP上一样顺利运行,所以我猜代码中肯定有什么东西与Aero冲突,但我只是不知道如何修复它。有人可以帮我吗?如果有人帮助我,我将非常感激。
I'm trying to create context menu using TrackPopupMenu function in my application, the code I use in it is like the following:
CMenu menu;
if (menu.LoadMenu(IDR_MENU_TRAY))
{
CMenu* pSubMenu = menu.GetSubMenu(0);
if (pSubMenu != NULL)
{
pSubMenu->ModifyMenu(IDM_CLOSE,MF_BYCOMMAND,IDM_CLOSE ,g_cfg->GetLang(TEXT_MAIN_CLOSE,"Exit(&X)"));
pSubMenu->ModifyMenu(IDM_SHOW,MF_BYCOMMAND,IDM_SHOW ,g_cfg->GetLang(TEXT_MAIN_OPEN_SHUTTER,"Open(&O)"));
CPoint point;
GetCursorPos(&point);
SetForegroundWindow();
pSubMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, messageOnlyWnd);
}
}
The code runs perfect on WinXP, while on win7 and vista it doesn't. The Problem on win7 and vista is that it takes a fairly long time to pop up the menu, maybe 1 min or more. But if I turn off the Aero on win7 or vista, it runs smoothly just like on winXP, so I guess somethin must be conflicted with Aero in the code, but I just don't know how to fix it. Is there anyone can help me with that? I will appreciate it a lot if anybody helps me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有看到这段代码有什么问题。我在 Vista 上使用
TrackPopupMenu
没有任何问题。问题的根源可能在其他地方。尝试删除对SetForegroundWindow
的调用。如果这不起作用,请尝试仅使用弹出菜单代码创建一个空项目。I don't see anything wrong with this code. I've used
TrackPopupMenu
on Vista without any problems. The source of the problem might lie elsewhere. Try removing the call toSetForegroundWindow
. If that doesn't work, try creating an empty project with just the popup menu code.