| HRESULT CBrowserHost::ShowContextMenu(DWORD dwID, POINT *ppt,IUnknown *pcmdTarget,IDispatch *pdispObject) { #define IDR_BROWSE_CONTEXT_MENU 24641 #define IDR_FORM_CONTEXT_MENU 24640 #define SHDVID_GETMIMECSETMENU 27 #define SHDVID_ADDMENUEXTENSIONS 53 HRESULT hr; HINSTANCE hinstSHDOCLC; HWND hwnd; HMENU hMenu; CComPtr<IOleCommandTarget> spCT; CComPtr<IOleWindow> spWnd; MENUITEMINFO mii = {0}; CComVariant var, var1, var2; hr = pcmdTarget->QueryInterface(IID_IOleCommandTarget, (void**)&spCT); hr = pcmdTarget->QueryInterface(IID_IOleWindow, (void**)&spWnd); hr = spWnd->GetWindow(&hwnd);//取得浏览器窗口句柄 hinstSHDOCLC = LoadLibrary(TEXT("SHDOCLC.DLL")); if (hinstSHDOCLC == NULL) { // Error loading module -- fail as securely as possible return; } hMenu = LoadMenu(hinstSHDOCLC, MAKEINTRESOURCE(IDR_BROWSE_CONTEXT_MENU)); hMenu = GetSubMenu(hMenu, dwID); // Get the language submenu hr = spCT->Exec(&CGID_ShellDocView, SHDVID_GETMIMECSETMENU, 0, NULL, &var); mii.cbSize = sizeof(mii); mii.fMask = MIIM_SUBMENU; mii.hSubMenu = (HMENU) var.byref; // Add language submenu to Encoding context item SetMenuItemInfo(hMenu, IDM_LANGUAGE, FALSE, &mii); // Insert Shortcut Menu Extensions from registry V_VT(&var1) = VT_INT_PTR; V_BYREF(&var1) = hMenu; |