Programming | menu
Keywords: itravellogstg, ienumtravellogentry, Itravellogentry
1. Overview
Internet Explorer's browsing History menu starts appearing in version 4.0, but until 5.5, Microsoft has not published to access the browsing history of the COM interface, now is the IE6.0 of the era, for access to the browsing history of the interface has long been announced, the purpose of this article is to try to introduce a simple introduction to visit the history of the TR Avel log interface and use a small class cietravellog to implement the travel log encapsulation.
2, IOmHistory interface
In earlier MSDN, we were able to see that the interface for browsing history was only iomhistory, and that interface actually corresponded to the "history" object that the browser could access through scripting. For the "History" object, this is what MSDN says:
For security reasons, the history object does not expose the actual URL in the browser. It does allow navigation through the browser history by exposing the "back", forward, and go methods. A particular document in the browser history can is identified as A index relative to the current page. For example, specifying-1 as a parameter for the ' go ' is the equivalent of clicking the ' Back button.
This object is available in script as of Microsoft Internet Explorer 3.0.
For security reasons, the IOmHistory interface provides only a limited number of ways to move forward, back, and so on in the browser, and does not provide access to the History list URL. This is no wonder that the interface in the IE 3.0 era already exists, but at that time IE immature, programmable ability is not very strong. By the time IE 4.0 was bundled with Windows 98 to sell eminence, the relevant documents were becoming richer, as did the use of Internet Explorer/webbrowser control applications such as multiple window browsers. But before the IE 5.5 interface is published, it is not easy to simulate the travel log behavior of IE completely. The easiest way to think about it is to record/modify URLs and save them (as I did earlier) in the event of events like BeforeNavigate, DocumentComplete, but not very well, especially when browsing pages containing frame. Of course, it is not difficult to fully simulate, but developers know that Microsoft is publishing interface is sooner or later, so no one has to spend much effort on the simulation of IE travel log behavior.
3, Travel Log Introduction
When Internet Explorer 5.5 is launched, the Travel log interface begins to appear in MSDN, designed specifically for OLE embedded WebBrowser control applications to "improve and enhance the user's access log experience" (Improve and enhance the user ' s travel log experience). In fact, I'll mention later that the Travel log interface is increasingly becoming one of the important interfaces in the application.
Microsoft's Travel log consists of three interfaces: Itravellogstg, Ienumtravellogentry and Itravellogentry.
itravellogstg--This interface provides a way to add, delete, and enumerate logs (browsing history) in travel log, several methods that need to be used in this article are listed below:
Method name Use
Enumentries Create an enumerator for access log entries (Ienumtravellogentry interface pointers)
Getrelativeentry Returns a log entry
Travelto access to a log entry
ienumtravellogentry--This interface provides the necessary methods for enumerating log entries, this article only uses one method:
Method name Use
Next enumerates the next log entry (returns the Itravellogentry interface pointer)
itravellogentry--This interface has only two methods for returning the title and URL of a log entry:
Method name Use
GetTitle returns the title of the log entry
GetURL returns the URL of a log entry
The interface is ready, and it's easy to know the relationship between them:
To get a list of log entries relative to the current page, first create an enumerator (Ienumtravellogentry interface) through the ITRAVELLOGSTG interface.
The Ienumtravellogentry enumerator's next method is used to enumerate a log entry (Itravellogentry interface).
The Itravellogentry interface gets the title and URL of the page represented by the log entry and processes it.
When accessing a log entry relative to the current page, the first Itravellogstg Getrelativeentry method obtains the Itravellogentry interface based on the distance from the current page. The latter is then passed into the Itravellogstg Travelto method to achieve the purpose of accessing the log entry (such as forward and backward).
Perhaps not too appropriate, I am not familiar with UML, the use of a pseudo-UML sequence diagram to indicate the relationship is as follows:
4, Package Travel Log
Next, we use a simple class to complete the encapsulation of the travel log. As shown below, the tlogstg.h contains the associated interface declaration for travel log, which can be found in the Platform SDK.
#include "Tlogstg.h"
Class Cietravellog
{
Private
ITRAVELLOGSTG *m_ptravellogstg;
Ienumtravellogentry *m_penumlogentry;
Itravellogentry *m_ptravallogentry;
Iwebbrowser2* M_pwebbrowser;
Public
Cietravellog (void);
~cietravellog (void);
void Setwebbrowser (iwebbrowser2* pwebbrowser);
void Buildhistorymenu (CMenu * pmenu, unsigned char ncount, bool bforward);
void Travelto (int nposition);
};
Cietravellog::cietravellog (void)
: M_ptravellogstg (NULL), M_penumlogentry (null), M_ptravallogentry (null), M_pwebbrowser (NULL)
{
}
Cietravellog::~cietravellog (void)
{
if (M_ptravellogstg!= NULL)
{
M_ptravellogstg->release ();
}
if (m_penumlogentry!= NULL)
{
M_penumlogentry->release ();
}
if (m_ptravallogentry!= NULL)
{
M_ptravallogentry->release ();
}
if (M_pwebbrowser!= NULL)
{
M_pwebbrowser->release ();
}
}
Assign the browser's IWebBrowser2 interface pointer to an instance of Cietravellog
void Cietravellog::setwebbrowser (iwebbrowser2* pwebbrowser)
{
if ((M_pwebbrowser = = Pwebbrowser) | | (M_pwebbrowser = NULL))
{
Return
}
if (M_pwebbrowser!= NULL)
{
M_pwebbrowser->release ();
}
M_pwebbrowser = Pwebbrowser;
IServiceProvider *PSP;
HRESULT hr = M_pwebbrowser->queryinterface (Iid_iserviceprovider, (lpvoid*) &PSP);
M_pwebbrowser->release ();
if (SUCCEEDED (HR))
{
hr = Psp->queryservice (Sid_stravellogcursor, Iid_itravellogstg, (lpvoid*) &M_PTRAVELLOGSTG);
Psp->release ();
}
}
Create a browsing History menu, bforward indicate whether to forward or backward menu
void Cietravellog::buildhistorymenu (CMenu * pmenu, unsigned char ncount, bool Bforward)
{
if (M_ptravellogstg = NULL)
{
Return
}
TLENUMF Eflag = Bforward? Tlef_relative_fore:tlef_relative_back;
if (FAILED (M_ptravellogstg->enumentries (Eflag, &m_penumlogentry))
{
Return
}
ULONG ufetched;
int i=0;
if (M_penumlogentry!=null)
{
while (SUCCEEDED (M_penumlogentry->next (1, &m_ptravallogentry, &ufetched)) &&
M_ptravallogentry && i<10)//We only need 10 history menu, can be modified according to the actual situation
{
LPOLESTR Psztitle;
M_ptravallogentry->gettitle (&psztitle);
CString strtitle = Psztitle;
if (Bforward)
{
Id_iehistory_middle is a predefined menu item ID, and you can create 10 menu items before and after the start of the ID, see the next section
Pmenu->insertmenu (0, mf_string, Id_iehistory_middle + ++i, strtitle);
}
Else
{
Pmenu->insertmenu (0, mf_string, Id_iehistory_middle-++i, strtitle);
}
CoTaskMemFree (Psztitle);
M_ptravallogentry->release ();
}
}
}
Access the history page based on the relative distance to the current page
void Cietravellog::travelto (int nposition)
{
if (M_ptravellogstg = NULL)
{
Return
}
If SUCCEEDED (M_ptravellogstg->getrelativeentry (nposition, &m_ptravallogentry))
{
M_ptravellogstg->travelto (M_ptravallogentry);
}
}
5. Use Cietravellog
Let's say we use travel Log in our own multiple-window browser. For the sake of simplicity, we declare a Cietravellog global object G_ietravellog so that it can be called anywhere. Then, in the appropriate place, such as the CMainFrame tbn_dropdown message (Toolbar menu Drop-down message) handler function Ondropdown, add the following code to create the Browse history menu:
GETACTIVEWEBBROWSERPTR returns the active browser IWebBrowser2 interface pointer
Ietravellog.setwebbrowser (GETACTIVEWEBBROWSERPTR);
Bforward true to create the forward menu, otherwise create the back menu
Ietravellog.buildhistorymenu (&menu, Bforward);
The following is defined as the scope of the menu item ID, which can accommodate up to 10 menu items, which can be modified according to the actual situation.
#define Id_iehistory_first 60200
#define Id_iehistory_middle 60210
#define Id_iehistory_last 60220
Add a command handler function Ontravelhistoryurl to respond to menu commands from Id_iehistory_first to Id_iehistory_last.
On_command_range (Id_iehistory_first, Id_iehistory_last, Ontravelhistoryurl)
void Cmainframe::ontravelhistoryurl (UINT nID/* Command ID */)
{
Nid-id_iehistory_middle is the distance to the current page for the browsing history to be accessed
G_ietravellog.travelto (Nid-id_iehistory_middle);
}
6, again talk about travel Log
I mentioned earlier that "the Travel log interface is increasingly becoming one of the important interfaces in the application", as described here. From the development mode and orientation of Microsoft platform, the application of Explorer/webbrowser control based on Internet is bound to become the mainstream. In the next generation of operating system Longhorn, the description of the application interface will be complete by a special--xaml of XML, and XAML parsing will be done by the browser. Microsoft says future deployment of applications will be very easy, the differences between local and browser-based applications will fade, and an important manifestation of this is that applications will actually run in Internet Explorer on future operating system platforms, Internet Explorer has become a container in a way.
As a result, travel log, which is rooted in Internet Explorer, is naturally integrated into our applications. Don't you see, the work we do on the explorer and the browser every day is not just running back and forth in the travel log? If all the applications are embedded in Internet Explorer, then the actions we make in the application are naturally recorded, and "forward" and "back" are easy.
Many of the software have started using Internet Explorer patterns more or less, such as Microsoft Money, Microsoft Encarta, Visual Studio.NET installer, and so on, which is a good example. So, for the time being, write our application in this mode (refer to the "Separation of program interface and implementation using the browser"), can not get the "Access log Experience" earlier? Why