MSDN 上的例子程序 lz 可以试一下if (lEvent==WM_RBUTTONUP) { // Make first menu item the default (bold font) ::SetMenuDefaultItem(pSubMenu->m_hMenu, 0, TRUE); // Display the menu at the current mouse location. A "bug" in // Windows 95 that requires calling SetForegroundWindow. To find // out more, read Q135788 in MSDN. CPoint mouse; GetCursorPos(&mouse); ::SetForegroundWindow(m_nid.hWnd); ::TrackPopupMenu(pSubMenu->m_hMenu, 0, mouse.x, mouse.y, 0, m_nid.hWnd, NULL); ::PostMessage(m_nid.hWnd, WM_NULL, 0, 0);
但是为什么你不可以用SetForegroundWindow()呢
这个的确是Windows系统的一个bug,还可以给你的主窗口发送
PostMessage(hWnd, WM_NULL, 0, 0)
来解决/
lz 可以试一下if (lEvent==WM_RBUTTONUP) { // Make first menu item the default (bold font)
::SetMenuDefaultItem(pSubMenu->m_hMenu, 0, TRUE); // Display the menu at the current mouse location. A "bug" in
// Windows 95 that requires calling SetForegroundWindow. To find
// out more, read Q135788 in MSDN.
CPoint mouse;
GetCursorPos(&mouse);
::SetForegroundWindow(m_nid.hWnd);
::TrackPopupMenu(pSubMenu->m_hMenu, 0, mouse.x, mouse.y, 0,
m_nid.hWnd, NULL);
::PostMessage(m_nid.hWnd, WM_NULL, 0, 0);