不知道大家用过该函数没有:
TrackPopupMenu( UINT nFlags, int x, int y, CWnd* pWnd, LPCRECT lpRect = NULL );在MSDN中对该函数中的第5个参数是这样是说明的:lpRectPoints to a RECT structure or CRect object that contains the screen coordinates of a rectangle within which the user can click without dismissing the pop-up menu. If this parameter is NULL, the pop-up menu is dismissed if the user clicks outside the pop-up menu. This must be NULL for Windows 3.0.我在程序中是这样写的:
switch(uMouseMsg)
{case WM_RBUTTONDOWN:
CMenu menu,*pMenu;
POINT point; if(menu.LoadMenu(IDR_MENU1) && GetCursorPos(&point) )
{
pMenu=menu.GetSubMenu(0);
if(pMenu)
{ pMenu->EnableMenuItem(IDR_MENU1,MF_GRAYED);
pMenu->TrackPopupMenu(TPM_CENTERALIGN,point.x,point.y,this);
}
}
break;
case WM_LBUTTONDOWN:
...
break;}
程序可以运行,点击鼠标右键时能弹出菜单,可是在菜单之外点击时,菜单不消失,这就是我的问题,为什么在菜单之外点击时菜单不消失呢?
TrackPopupMenu( UINT nFlags, int x, int y, CWnd* pWnd, LPCRECT lpRect = NULL );在MSDN中对该函数中的第5个参数是这样是说明的:lpRectPoints to a RECT structure or CRect object that contains the screen coordinates of a rectangle within which the user can click without dismissing the pop-up menu. If this parameter is NULL, the pop-up menu is dismissed if the user clicks outside the pop-up menu. This must be NULL for Windows 3.0.我在程序中是这样写的:
switch(uMouseMsg)
{case WM_RBUTTONDOWN:
CMenu menu,*pMenu;
POINT point; if(menu.LoadMenu(IDR_MENU1) && GetCursorPos(&point) )
{
pMenu=menu.GetSubMenu(0);
if(pMenu)
{ pMenu->EnableMenuItem(IDR_MENU1,MF_GRAYED);
pMenu->TrackPopupMenu(TPM_CENTERALIGN,point.x,point.y,this);
}
}
break;
case WM_LBUTTONDOWN:
...
break;}
程序可以运行,点击鼠标右键时能弹出菜单,可是在菜单之外点击时,菜单不消失,这就是我的问题,为什么在菜单之外点击时菜单不消失呢?
解决方案 »
- 关于MIDI文件播放的问题~~!!
- BYTE 类型的指针怎么初始化啊,牛人帮我看看我的代码
- 一个比较不常见的问题,WinINet能穿透SOCKS5代理吗?
- 怎么办?
- =================请大家来讨论一下 ====================
- PreTranslateMessage(MSG* pMsg) 中,哪位知道+ - 怎么响应的么?如下
- 一个系统文件夹选择对话框的问题?
- 高分求助!!!跟贴有分!!!请大家进来看看!!!!!!!!!
- 怎样把双字节的字符串转化成单字节的字符串?
- 求vc中动态使用.ocx控件例子
- 请教ADO问题
- 怎样理解对话框和文档/视图结构(主要是文档)之间的数据传送
pMenu->TrackPopupMenu(TPM_CENTERALIGN,point.x,point.y,this);
第五个参数我没有写,可是默认参数不就是空吗?
加上SetForegroundWindow()之后,问题搞定。
之前加一句: SetForegroundWindow();
这个函数的功能为: puts the thread that created the specified window into the foreground and activates the window. Keyboard input is directed to the window, and various visual cues are changed for the user.前几天我也是遇到這個問題。 這是別人給我的解釋。我想這是系統的bug. 需要你做一下 setforegroundwindow(),激活你的窗口,這時你再在其它地方點鼠標,windows才會認為那個popmenu失去了焦點,然后把它destroy掉。