c++ - How to modify context menu of internet explorer using IDocHostUIHandler::ShowContextMenu? -
i trying implement custom menu internet explorer 7.0. have use idochostuihandler::showcontextmenu
only. till able implement basic context menu 2 options. problem disabled default. sample code same is:
hresult cwebeventhandler::showcontextmenu(dword dwid,point *ppt, iunknown *pcmdtarget, idispatch *pdispobject) { if (false) // put guard code here. of not consider 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 2 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 command browser. // lresult myresult = ::sendmessage(hwnd, wm_command, myretval, null); } pwnd->release(); } } return s_ok; }
kindly suggest wrong code & why menu entries disabled??
thanks
edit
the same post available on link ( http://social.msdn.microsoft.com/forums/en/ieextensiondevelopment/thread/13584f76-21bd-4764-b5b7-e81932561574 )
i think have solved problem. after getting hwnd object in if (succeeded(pwnd->getwindow(&hwnd)))
install own callback context menu. in callback
if ((umsg == wm_initmenupopup) && (wparam == (wparam) menu)) { return 0; }
otherwise let original handler process it.
once done
long myretval = ::trackpopupmenu(g_hpubmenu,tpm_rightbutton | tpm_leftalign | tpm_returncmd, ppt->x, ppt->y, null, hwnd, null);
revert original proc handler....
sample
wndproc g_lpprevwndproc = null; hresult cwebeventhandler::showcontextmenu(dword dwid, point *ppt, iunknown *pcmdtarget, idispatch *pdispobject) { if (false) 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))) { g_lpprevwndproc = (wndproc)setwindowlong(hwnd, gwl_wndproc, (long)ctxmenuwndproc); if (g_hpubmenu) { destroymenu(g_hpubmenu); g_hpubmenu = null; } g_hpubmenu = ::createpopupmenu(); ::appendmenu(g_hpubmenu, mf_string|mf_enabled , id_hello, l"&hello" ); ::appendmenu(g_hpubmenu, mf_string|mf_enabled , id_world, l"&world" ); long myretval = ::trackpopupmenu(g_hpubmenu, tpm_rightbutton | tpm_leftalign | tpm_returncmd, ppt->x, ppt->y, null, hwnd, null); setwindowlong(hwnd, gwl_wndproc, (long)g_lpprevwndproc); // send command browser. // if (myretval == id_hello) { box(_t("hello")); }else if(myretval == id_world) { box(_t("world")); }else{ lresult myresult = ::sendmessage(hwnd, wm_command,myretval, null); } } pwnd->release(); } } return s_ok; } lresult callback ctxmenuwndproc(hwnd hwnd, uint umsg, wparam wparam, lparam lparam) { if ((umsg == wm_initmenupopup) && (wparam == (wparam) g_hpubmenu)) { return 0; } return callwindowproc(g_lpprevwndproc, hwnd, umsg, wparam, lparam); }
Comments
Post a Comment