IE Spy is a tool I wrote some time ago. This tool enumerates all the windows of the WebBrowser control (including instances of Internet Explorer), and executes a set of standard commands on them, like View Source, Save, Refresh, Print, etc. This tool may be useful to you for your special needs. For example, suppose a program shows an HTML dialog and you want to see the HTML source of the page the dialog is displaying. One way would be digging into the EXE resources and/or finding the page being displayed, using a Win32 Resource Editor utility (if necessary), and see its source code. But this is tedious. You can just use IE Spy plus Spy++ to obtain the source code instantly. You should just use Spy++ to obtain the window handle of the WebBrowser control embedded inside the dialog, and use IE Spy to grab its HTML source.
When playing with IE Spy, you can find other useful things it can do as well. But maybe the biggest advantage of IE Spy is using it as a sample application.
IE Spy mostly demonstrates two things. The first thing it demonstrates is enumerating all windows (including both parent and child windows) that exist inside the current Windows session. This is done using two API functions: ::EnumWindows( ) and ::EnumChildWindows( ). Study the source code inside the file IESpyView.h to see how it’s implemented (Did I mention that the sample application can be downloaded from the link at the bottom of this article?).
The next thing that IE Spy demonstrates is clearly sending commands to the WebBrowser control. Contrary to what you might think, this is very easy to do. You just need to know how to do it. All you need to do is to post a WM_COMMAND message to the window of the WebBrowser (of which you get the HWND by calls to ::EnumWindows( ) and ::EnumChildWindows( )), set the WPARAM’s lower WORD to an appropriate command ID, the higher word of it to 0, and the LPARAM value to 0. And if you think those command IDs are some undocumented numbers you must find out about the hard way (I mean, running Internet Explorer under a debugger, and watching the asm code for weeks and weeks), well, you’ll be glad to know that you are wrong! All possible command ID’s are defined inside mshtmcid.h. Of course, those command IDs are not documented inside the MSDN, but it’s not a hard task to guess what they do if you have ever worked with Internet Explorer. After all, what could IDM_VIEWSOURCE mean except the command ID to invoke the View Source command?!
Of course, the catch here is that almost all of those command IDs are applicable only when you use the WebBrowser control in Editor mode (like what Outlook Express does, when composing HTML email messages). And for some of them I could not find any actions at all (before you ask, their names did not indicate their action clearly). But the most common commands are shown in the IE Spy application.
So, using a set of basic tasks, I have written an application that may surprise many programmers at the first glance. Just to give you some quick hints on how to use it, please read on. You should first open an instance of the application (uh!), from the Spy menu, click Begin. This begins enumerating all the WebBrowser windows in the system. According to the number of windows (which varies all the time) and the speed of your machine, this might take a moment to complete. Then, inside the big list view, you’ll see a list of HWND values. These are useless by themselves (what can you understand from 0x0012E049?!). At this time, you must invoke Spy++ (which comes with VC++ as a Tool), and use its Find Window tool to get the HWND of the WebBrowser control instance you’re curious about. Then, you must find the entry inside the list view (the list view is sorted, so it shouldn’t be a hard task) and either right click on it, or click the Spy menu again, and begin your espionage! The items inside that (well, lengthy) menu are self explanatory, and if you didn’t figure out what a certain item does, look at the status bar which shows a brief help message about it. If you didn’t figure out the action again, try to test it on the WebBrowser control instance you have selected, since this will be your last resort!
If you are one of those people who are always curious about different things (and hence need nice espionage utilities!) I think you’ll like IE Spy. Anyway, hope you find it useful.