我正在嘗試爲Internet Explorer 7.0實現自定義菜單。爲此,我只能使用IDocHostUIHandler::ShowContextMenu
。直到現在我能夠實現一個基本的上下文菜單有兩個選項。問題是它們默認是禁用的。對於相同的示例代碼:如何使用IDocHostUIHandler :: ShowContextMenu修改Internet Explorer的上下文菜單?
HRESULT CWebEventHandler::ShowContextMenu(DWORD dwID,POINT *ppt, IUnknown *pcmdTarget, IDispatch *pdispObject)
{
if (false) // I will put some guard code here. as of now do not consider it
return S_FALSE; // Show standard context menus.
else
{
IOleWindow* pWnd = NULL;
HRESULT hr = pcmdTarget->QueryInterface(IID_IOleWindow,
(void**) &pWnd);
if (SUCCEEDED(hr))
{
HWND hwnd;
if (SUCCEEDED(pWnd->GetWindow(&hwnd)))
{
HMENU menu = ::CreatePopupMenu();
::AppendMenu(menu, MF_STRING, ID_HELLO, L"&Hello"); // ID_HELLO & ID_WORLD are two menu resource items
::AppendMenu(menu, MF_STRING, ID_WORLD, L"&World");
long myRetVal = ::TrackPopupMenu(menu,
TPM_RIGHTBUTTON | TPM_LEFTALIGN | TPM_RETURNCMD,
ppt->x, ppt->y, NULL, hwnd, NULL);
// Send the command to the browser.
//
LRESULT myResult = ::SendMessage(hwnd, WM_COMMAND,
myRetVal, NULL);
}
pWnd->Release();
}
}
return S_OK;
}
請建議什麼不對這個代碼&爲什麼我的菜單項將被禁用?
感謝
編輯