Invoke Hidden Commands in Your Web Browser

Introduction

Generally, when hosting the WebBrowser Control in an MFC application, we call ExecWB method of m_pBrowserApp (IWebBrowser2 interface) to invoke common Web browser commands (zoom the browser, select all text in the browser, and so forth.).

We also invoke queryInterface to get an IDispatch pointer for the IOleCommandTarget interface and call its Exec method to invoke the "Find in This Page" dialog or "View Source" command. But, some dialogs we CAN'T invoke still exist; for example, the "Add To Favorite" dialog and the "Import/Export Wizard" dialog.

We can invoke the "AddFavorite" command and "ImportExportFavorites" command through IShellUIHelper interface, but the former command results in a modeless "Add To Favorite" dialog independent from the application mainframe, while the latter command results in a quit simple consequence.

This article will introduce an innovative but simple way to invoke the MODAL "Add To Favorite" dialog and MODAL "Import/Export Wizard" dialog in your own Web browser.

Background

The idea comes from the IDocHostUIHandler::ShowContextMenu demo of "WebBrowser Customization" in the MSDN. The IDocHostUIHandler::ShowContextMenu demo presents us the way to manually build IE's context menu from correlative resource file "SHDOCLC.DLL" and remove "View Source" from it. The key point of the code is that, after popping up the context menu, it calls a SendMessage() API to send the MenuItem ID returned by TrackPopupMenu() to the "Internet Explorer_Server" window through WM_COMMAND message. So, if we get the MenuItem ID of the "Add To Favorite" command or the "Import/Export Wizard" command, we probably can solve the problems stated above.

Using the Code

Some command mesages are handled by the "Internet Explorer_Server" window while some others are handled by its parent "Shell DocObject View" window. Therefore, the fisrt thing is get the Window Handle of the two windows from your CHtmlView. To simple the resolution, I borrow the cute class CFindWnd below from Paul DiLascia.

About the Command IDs

As I stated above, the IDocHostUIHandler::ShowContextMenu demo of "WebBrowser Customization" in the MSDN shows a way to manually build IE's context menu from correlative resource file "SHDOCLC.DLL". So, open the file "SHDOCLC.DLL" by using some resource explorer software such as "eXeScope", we can find all the Command IDs (also menu item IDs) used by the WebBrowser Control under menu resources, and all of them are the same in IE 4.x/5.x/6.x according to my tesing.

Top White Papers and Webcasts

The 2014 State of DevOps Report — based on a survey of 9,200+ people in IT operations, software development and technology management roles in 110 countries — reveals:
Companies with high-performing IT organizations are twice as likely to exceed their profitability, market share and productivity goals.
IT performance improves with DevOps maturity, and strongly correlates with well-known DevOps practices.
Job satisfaction is the No. 1 predictor of performance against organizational …

As virtualization becomes the norm throughout organizations of nearly all sizes, and as more organizations look to private cloud solutions, IT decision makers are increasingly in need of ways to keep storage costs and complexity under control in the face of often-runaway virtual machine (VM) sprawl. Application-aware storage is designed to help achieve these important goals. Read this white paper to learn how application-aware storage allows you to gain VM-level visibility into application performance and …