📄 index189.htm
字号:
<html>
<style type="text/css"><!--
.p9 { font-family: "宋体"; font-size: 9pt}a {text-transform: none; text-decoration: none;}
a:hover {text-decoration: underline; color: #FF0000;}
--></style>
<body background="../di2001.jpg">
<h3 align="center"><font COLOR="#AOAO99"></font></h3>
<table width="100%" border="1" cellspacing="1">
<tr><td><p align="center"><font color="#FF0000">怎样取消一个弹出式菜单</font></td></tr>
<tr><td><p>
</Br>
我有一个应用程序不显示窗口(建立窗口时使用了SW_HIDE参数),它只在任务条显示一个图标,我是这样做的:<Br>
NOTIFYICONDATA tnid;<Br>
</Br>
tnid.cbSize = sizeof(NOTIFYICONDATA);<Br>
tnid.hWnd = m_hWnd;<Br>
tnid.uID = 1;<Br>
tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;<Br>
tnid.uCallbackMessage = MYWM_NOTIFYICON;<Br>
tnid.hIcon = AfxGetApp()->LoadIcon( IDI_ICON1 );<Br>
lstrcpyn(tnid.szTip, "Giroimag Image Mail Exchange", strlen("Giroimag Image Mail Exchange")+1);<Br>
</Br>
Shell_NotifyIcon(NIM_ADD, &tnid);<Br>
当我点击任务条时,程序会显示一个弹出菜单:<Br>
CMenu m_Menu;<Br>
</Br>
m_Menu.CreatePopupMenu();<Br>
</Br>
m_Menu.AppendMenu( MF_STRING, IDM_ABOUT, "Op&1" );<Br>
m_Menu.AppendMenu( MF_SEPARATOR, 0 );<Br>
m_Menu.AppendMenu( MF_STRING, IDM_CONFIG, "Op&2" );<Br>
m_Menu.AppendMenu( MF_STRING, IDM_STATUS, ""Op&3" );<Br>
m_Menu.AppendMenu( MF_SEPARATOR, 0 );<Br>
m_Menu.AppendMenu( MF_STRING, IDM_SEND, "Op&4" );<Br>
m_Menu.AppendMenu( MF_STRING, IDM_RECEIVE, "Op&5" );<Br>
m_Menu.AppendMenu( MF_SEPARATOR, 0 );<Br>
m_Menu.AppendMenu( MF_STRING, IDM_CLOSE, "Op&6" );<Br>
</Br>
POINT p;<Br>
GetCursorPos( & p );<Br>
</Br>
m_Menu.TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON, p.x, p.y, this );<Br>
到这为止,程序运行很正常,问题在于如果我不选择任何菜单该怎样取消它?我以为按ESC或者在菜单外面点击就可以取消,但事实并不是这样。我也试过用WIN32API中的TrackPopupMenuEx函数但没有用,到底我该怎么做?<Br>
</Br>
1)最简单的方法在消息映象中加"Cancel Menu"命令即可。<Br>
2)尽管你的主窗口不可见,但在你可以在调用m_Menu.TrackPopupMenu();时将其置为最前。<Br>
3)在你弹出菜单之前,设置你的窗口为最前窗口,调用下面的代码,问题就会迎刃而解。<Br>
</Br>
POINT p;<Br>
GetCursorPos( & p );<Br>
</Br>
// Increase the thread priority by invoking SetForegroundWindow.<Br>
SetForegroundWindow();<Br>
</Br>
m_Menu.TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON, p.x, p.y, this );<Br>
4)调用TrackPopupMenu()之前,你必须先调用SetForegroundWindow( m_hWnd ),然后调用PostMessage( m_hWnd, WM_NULL, 0, 0 ):<Br>
</Br>
POINT point;<Br>
GetCursorPos( &point );<Br>
SetForegroundWindow( m_hWnd );<Br>
TrackPopupMenu( hPopup,<Br>
TPM_RIGHTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,<Br>
point.x,<Br>
point.y,<Br>
0,<Br>
m_hWnd, 0 );<Br>
PostMessage( m_hWnd, WM_NULL, 0, 0 );<Br>
</p></td></tr>
</table>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -