Following the step by step instructions (they are excellent) and downloading the sample code I find that when the Show Codeguru Favorites context menu item is selected the context menu closes leaving the popup menu hanging in space. The popup menu functions correctly. How do I get the context menu to remain visible until the submenu item has been selected. By watching messages go by in SubclassWndProc it appears that the context menu is closed as a result of the WM_INITMENUPOPUP message.
I now see what you both are saying. Unfortunately, with the approach taken here, the menu will go away since, the script method is called as response to the menu and it returns immediately.
ReplyWell, its like gcage writes. The "Show Codeguru Favorites" menu entry does not contain submenus. Only when you click it, the original IE context menu disappears and the Codeguru Favorites menu with its subentries appears. Please see this screencast: http://screencast.com/t/dHHFW4wUWT
ReplyHello, sorry for the delay. I am not clear on your findings. Could you please elaborate? Also, if you could turn on allowing me to contact you via email private messaging, that would help speed up communication. What IE version are you using , by the way ?
ReplyHow can i use javascript to open a program? I want to create a new entry in the context menu that opens a program and passes the right clicked url as an argument. Is that possible? regards Jimmie
I am assuming you have read through the article on the basics of adding a context menu entry ( simply using the registry and adding a html file in a fixed folder location ). If you have done that and are able to get at least the message box, you can follow these steps.
For the Contexts entry, use hex 20 value. This means, to show the context menu when right clicked on an anchor tag. When this is done, and you select your menu item, the URL will can be extracted and passed on to an application ( using firefox for e.g.) like below for the javascript code:
var parentwin = external.menuArguments;
var doc = parentwin.document;
var str = new String(parentwin.event.srcElement.href);
v = new ActiveXObject("Shell.Application");
v.ShellExecute("firefox.exe", str, "", "open", 10);
Reply
Hi, is there any possibility e.g. to navigate to a website instead of pasting the text? I tried using pSp->Navigate(L"www.myurl.com", ...); instead of pSp->ExecWB(OLECMDID_PASTE, ...); but it does not work. All IWebBrowser2 members which use navigation don't work (which are GoBack, GoForward, GoHome, Navigate, and Navigate2). There are no errors, just nothing happens. Any ideas? Thanks in advance, Peter
Replyi read it i read it... oho it's done .. i am very delightful to say that it is wonderful and remarkable work dingo
.. for your nice words. I am glad you found it interesting
ReplyHi there, I apply the code to the IE component at edit mode, when I click the item on encode menu, it clear the page!?
ReplyThis is no file named "shdoclc.dll" in vista.
Updated, actually re-architected , so should work on Vista now. Please let me know if you see a problem still
ReplyHaven't tried it on Vista yet. Will do so and add comment. Thanks for pointing it out.
ReplyMicrosoft says "The IDocHostUIHandler interface is designed to be overridden by applications that host the WebBrowser control. It is not intended for use by Browser Helper Objects (BHOs) because, in addition to the problem of appending items to the standard menu discussed below, only one add-on at a time can override IDocHostUIHandler and multiple add-ons can easily conflict with each other." http://msdn2.microsoft.com/en-us/library/aa770042.aspx So how can this be done without overriding IDocHostUIHandler. Thanks, Murphy
Updated article per recommendation. The new architecture doesn't even need to be a BHO implementation. Simple javascript and an activex component do the job. Thanks mcrosby. Appreciate your comments.
Reply"In Windows Internet Explorer 7, the technique for overriding the context menu from a DocObject host is the same as Internet Explorer 6; however, the host must implement its own menu resources. The internal resources of Internet Explorer should not be used as they may change or move (as has been done in Internet Explorer 7)." I ran into this when I was displaying the Anchor menu item and "Open in New Tab" was not there. I am still trying to solve both of these problems. Thanks, Murphy
ReplyInstead of adding codeguru page favorites, can this context menu invoking do something else? Like say, if I click on the menu item, can I open microsoft word or any other program on my machine? I think this can be easily done, but do not know how [not a ATL/COM guru and never used them :-( ]
The way to do this is to launch the process using a. ShellExecute b. CreateProcess
ReplyI recently happend to read your article on codeguru about customizing the context menu. It is great. I want to know one thing. Can we use the same or similar code for creating extension for context menu on IE when a word/sentence or a part of text is blocked/selected? It means when I want to copy one word or sentence, I block it using mouse and then want to have the context menu show the new item you described? Google has some such thing currently and uses it for searching depending on word selected. Thanks a lot in advance. Sam
thanks for your nice words about article. Am glad it would be of help to you. I think I know the answer to your question , if I understand you right. When you say text is blocked, do you mean the text has been selected ? If so, you should try this ( I haven't done this myself, but I guess that is the way ). In CCGFavorites::ShowContextMenu, the first thing I do is check for the dwID. The dwID will be different for different items and is listed in mshtmhst.h like below: #define CONTEXT_MENU_DEFAULT 0 #define CONTEXT_MENU_IMAGE 1 #define CONTEXT_MENU_CONTROL 2 #define CONTEXT_MENU_TABLE 3 // in browse mode #define CONTEXT_MENU_TEXTSELECT 4 #define CONTEXT_MENU_ANCHOR 5 #define CONTEXT_MENU_UNKNOWN 6 What I suggest is for you to handle the case where dwID is CONTEXT_MENU_TEXTSELECT , instead of CONTEXT_MENU_CONTROL like I am doing now.Reply
When I open a html ,which has a Applet, by the WebBrowser Control (the Control is hosted in a Dialog-based Application ) ,I got some error ("Free block 0x**** modified after it was freed") What's the reason ?
1. Does this happen only if the CGFavorites extension is installed ? 2. What version of IE is used ?
Reply