I am trying to implement a custom menu for Internet Explorer 7.0. For this i have to use IDocHostUIHandler::ShowContextMenu only. Till now i am able to implement a basic context menu with two options. The problem is that they are disabled by default. The sample code for the same is:
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;
}
Kindly suggest what is wrong with this code & why my menu entries are disabled??
Thanks
EDIT
The same post is available on this link also ( http://social.msdn.microsoft.com/Forums/en/ieextensiondevelopment/thread/13584f76-21bd-4764-b5b7-e81932561574 )
I think i have solved the problem. After getting the hwnd object in
if (SUCCEEDED(pWnd->GetWindow(&hwnd)))install your own CALLBACK for context menu. In the callbackotherwise let the original handler process it.
once done with
revert back to the original proc handler….
Sample