| if (wParam == (WPARAM) g_hPubMenu) { ::EnableMenuItem( 自定义的菜单命令ID, MF_ENABLED | MF_BYCOMMAND ); ::CheckMenuItem( 自定义的菜单命令ID, MF_BYCOMMAND); return 0; } } return CallWindowProc(g_lpPrevWndProc, hwnd, uMsg, wParam, lParam); } HRESULT CMyHtmlView::OnShowContextMenu(DWORD dwID, LPPOINT ppt, LPUNKNOWN pcmdtReserved, LPDISPATCH pdispReserved) { //浏览器菜单句柄保存在g_hPubMenu中 ...... // subclass浏览器窗口 g_lpPrevWndProc = (WNDPROC)::SetWindowLong(hwnd, GWL_WNDPROC, (LONG)CustomMenuWndProc); //m_SubclassWnd.SubclassWindow( hwnd );//MFC中用此方法更简便 // Show shortcut menu int iSelection = ::TrackPopupMenu(hSubMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, ppt->x, ppt->y, 0, hwnd, (RECT*)NULL); // Unsubclass浏览器窗口 ::SetWindowLong(hwnd, GWL_WNDPROC, (LONG)g_lpPrevWndProc); g_lpPrevWndProc = NULL; //m_SubclassWnd.UnsubclassWindow(); if (iSelection == 自定义的菜单命令ID ) { ::SendMessage( ::AfxGetMainWnd()->m_hWnd, WM_COMMAND, MAKEWPARAM(LOWORD(lResult), 0x0), 0 ); } else { LRESULT lr = ::SendMessage(hwnd, WM_COMMAND, iSelection, NULL); } ...... } |