Important noteUnfortunately, the customization approach, that I have originally used in this article, is not suitable for MFC applications (see the "Important Notice" message thread for more) and you should ignore the sections 4 and 6 of my article. On the contrary, section 5 is still 100% valid and can still be quite useful in the customization of the WebBrowser control context menus. The revised sample projects are using a new, much better customization approach that is going to be comprehensively discussed in the next update of this article, which will hopefully be ready in a couple of weeks. I am publishing this semi-documented and not fully-tested code, because I am having indications that some developers may need to have this code much sooner than the day of my next update. For each revised sample there is also a Readme.htm file that briefly describes how the sample works. Table of contents1. Why do we need to customize the context menus of the WebBrowser control (WBC)?
2. The basic customization techniques that can be used.
4. Implementation of the preliminary stuff.
7. Code listings.
8. References.
1. Why do we need to customize the context menus of the WebBrowser control (WBC)? The WebBrowser control (WBC) is a very powerful ActiveX control equipped with many useful capabilities, such as HTML, XML and text data viewing, web browsing, downloading and document viewing (it can display PDF, Word, Excel, PowerPoint and other documents). A description of its capabilities and its usefulness already exists in the MSDN site [1,2,3,4] and is out of the scope of this article. This article is going to deal only with the context menus, which WebBrowser control provides when it displays HTML, XML or text data and we will particularly discuss the customization of these context menus. When the WebBrowser control displays HTML, XML or text data, it provides by default, a powerful set of context menus that can be used to manipulate its content. Hence, significant control over its content is automatically being granted to the end-user. For instance, the end-user will be able to navigate forward and back whenever he chooses, to change the current encoding, to print/export/reload the content and he can also view the source data. By default the WebBrowser control does not need any assistance or approval from the application to do any of these. In fact, the application might not even know that these actions ever occur! Obviously, the fact that end-user has so much control over the content of our WebBrowser control is not always desirable and can introduce severe difficulties in our application design. If this is the case, then we have to customize the default context menus of the WebBrowser control and accommodate them to the specific needs of our application. Read more: Codeproject
2. The basic customization techniques that can be used.
2.1. Overriding the CWinApp::PreTranslateMessage() method.3. The objective of this article.
2.2. Implementing the IDocHostUIHandler interface.
4. Implementation of the preliminary stuff.
4.1. The CWebCtrlInterFace class declaration.5. Implementation of the IDocHostUIHandler::ShowContextMenu() method.
4.2. Implementation of the IUnknown interface methods.
4.3. Implementing the "neutral" behavior in the IOleClientSite and IDocHostUIHandler methods.
5.1. Vital technical information about the context menus of the WBC.6. The sample application.
5.2. Introducing the CWebCtrlInterFace customization modes.
5.3. Implementation of the kDefaultMenuSupport and kNoContextMenu modes.
5.4. Implementation of the kTextSelectionOnly mode.
5.5. Implementation of the kCustomMenuSupport mode.
5.6. Implementation of the kAllowAllButViewSourcemode mode.
7. Code listings.
8. References.
1. Why do we need to customize the context menus of the WebBrowser control (WBC)? The WebBrowser control (WBC) is a very powerful ActiveX control equipped with many useful capabilities, such as HTML, XML and text data viewing, web browsing, downloading and document viewing (it can display PDF, Word, Excel, PowerPoint and other documents). A description of its capabilities and its usefulness already exists in the MSDN site [1,2,3,4] and is out of the scope of this article. This article is going to deal only with the context menus, which WebBrowser control provides when it displays HTML, XML or text data and we will particularly discuss the customization of these context menus. When the WebBrowser control displays HTML, XML or text data, it provides by default, a powerful set of context menus that can be used to manipulate its content. Hence, significant control over its content is automatically being granted to the end-user. For instance, the end-user will be able to navigate forward and back whenever he chooses, to change the current encoding, to print/export/reload the content and he can also view the source data. By default the WebBrowser control does not need any assistance or approval from the application to do any of these. In fact, the application might not even know that these actions ever occur! Obviously, the fact that end-user has so much control over the content of our WebBrowser control is not always desirable and can introduce severe difficulties in our application design. If this is the case, then we have to customize the default context menus of the WebBrowser control and accommodate them to the specific needs of our application. Read more: Codeproject
0 comments:
Post a Comment