1. Introduction
How to realize the operation of the object in IE browser is a very practical problem, through and IE-bound dll we can record IE browsed the page order, analysis of user behavior and patterns. We can filter the content of the Web page and translation, you can automatically fill in the page often need to fill in the form of the user, and so on, all of our example code is expressed through VC, the principle is to use the interface with IE objects to achieve access to IE. In fact, using COM technology, we know that COM is a language-independent binary object interaction pattern, so in fact we describe the following can be implemented in other languages, such as vb,delphi,c++ builder and so on.
2. IE Instance Traversal implementation
First, let's look at how the system knows how many instances of IE are currently running.
We know that under Windows architecture, an application can interact with instances of these applications through the operating system's running object table. However, the current implementation of IE is not registered in the running Object table, so other methods need to be adopted. We know that the Shellwindows collection can represent a collection of currently open windows that belong to the shell, and IE is an application that belongs to the shell.
Below we describe the use of VC to achieve the current IE instance of the traversal method. Ishellwindows is an interface to the system shell, and we can define an interface variable as follows:
Shdocvw::ishellwindowsptr M_spshwinds;
Then create an instance of the variable:
M_spshwinds.createinstance
(__uuidof (shdocvw::shellwindows));
Through the Ishellwindows interface method GetCount
You can get the number of current instances:
Long ncount = m_spshwinds->getcount ();
Method item through the Ishellwindows interface
You can get each instance object
Idispatchptr Spdisp;
_variant_t va (i, VT_I4);
Spdisp = M_spshwinds->item (VA);