Internet Explorer programming brief (8) Implement browsing history menu

xiaoxiao2021-03-06  38

Keywords: Itravellogstg, IenumTravelLogentry, ItravelLoGentry

1 Overview

Internet Explorer's browsing historical menu starts in version 4.0, but until 5.5, Microsoft did not publish COM interfaces used to access the browsing history. Now it is an era of IE6.0, which is used to access the history of visiting history. Many, this paper is to try to throw the jade, briefly introduce the Travel log interface for visiting the browsing history, and use a small class CietravelLog to implement the TRAVEL LOG package.

2, Iomhistory interface

In the MSDN earlier, we can access the interface about the history of browsing only iomhistory, and the interface actually corresponds to the "History" object that can be accessed through the browser. For the "History" object, MSDN said this:

For security reasons, the history object does not expose the actual URLs in the browser history. It does allow navigation through the browser history by exposing the back, forward, and go methods. A particular document in the browser history can be identified as an index ............................ ...CRIPLILE, RAILWAY TECHNOLOGIC. OF SOIL AND WATER CONSERVATION.

This Object Is Available In Script As Of Microsoft Internet Explorer 3.0.

That is, for safety, the iomhistory interface provides only a limited number of methods to complete the ability to move forward and backward in the browser, and do not provide the ability to access histori list URLs. This is no wonder that the interface already exists in the IE 3.0 era, and IE is not mature, and the programmable ability is not very powerful. Until IE 4.0 After selling a uniform world with Windows 98, the relevant documentation is gradually enriched, and the Internet Explorer / WebBrowser Control-based application is also covered. However, before IE 5.5 interface, it is not easy to simulate the Travel Log behavior of IE. The easiest way is to record / modify the URL when BeforenaviGate, DocumentComplete, etc. (I have done this earlier), but the effect is not ideal, especially when browsing the web page containing Frame, processing It is even more trouble. Of course, it is necessary to completely simulate it, but developers know that Microsoft's announcement interface is a morning and evening, so no one spends great efforts to simulate the Travel log behavior of IE.

3, Travel Log Introduction

After Internet Explorer 5.5, the Travel log interface began to appear in the MSDN, which is designed for applications that embed WebBrowser Control for OLE, and its purpose is to "improve and strengthen the user's access log experience" (IMPROVE AND ENHANCE THE USER's Travel log experience). In fact, I will mention later, Travel log interface is increasingly one of the important interfaces in the application. Microsoft published Travel logs contains three interfaces: Itravellogstg, IEnumTravelLoGentry and ItravelLoGentry.

ItravelLogSTG - This interface provides methods for adding, deleting, enumerating logs (browsing history) in Travel log, and several methods for this article are listed below:

Method

ENUMENTRIES Create an enumerator (IEnumTravelLoGentry interface pointer) for access log entry

GetReLATINTRY returns a log entry

TravelTo Access a log entry

IEnumTravelLoGentry - This interface provides the method necessary for enumerating log entries, this article only uses a method:

Method

Next enumerates a log entry (return to the ItravelLoGentry interface pointer)

ItRavelLoGentry - This interface has only two ways, which are used to return the Title and URL of the log entry:

Method

GetTitle returns the Title of the log entry

GetURL returns the URL of the log entry

The interface is ready, and we can easily learn about the relationships between them:

To get a list of log items relative to the current page, you should first create an enumerator (IenumTravelLoGEntry interface) through the ItravelLogSTG interface. A NEXT method (ITRAVELLOGENTRE interface) is enumerated by the NexT method of the IenumTravelLoGentry enumerator. Title and URLs of the web page represented by the ITRAVELOGENTRY interface and processed. When visiting a log entry for the current page, you first get a ItraveEntry interface based on the distance from the current page, then incorporate the latter to the TRAVELLOGSTG TRAVELTO method to achieve the purpose of accessing the log entry (such as forward and backward) ).

Maybe not too appropriate, I am not familiar with UML, borrowing a pseudo UML sequence diagram, indicating that its relationship is as follows:

4, encapsulation travel log

Next, we use a simple class to complete the package of Travel Log. As shown below, TlogStg.h contains the related interface declaration of 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 * PwebBBBBBBBBBBBROWSER);

Void BuildhistoryMenu (cmenu * pmenu, unsigned char ncount, bool bforward); void travelto (int nposition);

}

Cietravellog :: CietravelLog (void)

: M_PTRAVELOGSTG (NULL), M_PENUMLOGENTRY (NULL), M_PTRAVALLOGENTRY (NULL), M_PWebBrowser (NULL)

{

}

Cietravellog :: ~ CietravelLog (void)

{

IF (M_PTRAVELOGSTG! = 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 ();

}

}

// Give the browser's IWebBrowser2 interface pointer to CietravelLog instance

Void Cietravellog :: SetWebBrowser (iWebBrowser2 * PwebbBBBBBBBBBBBBBBBBBBBROWSER)

{

IF ((m_pwebbrowser == pwebbrowser) || (m_pwebbrowser == null)

{

Return;

}

IF (m_pwebbrowser! = NULL)

{

m_pwebbrowser-> release ();

}

m_pwebbrowser = pwebbrowser;

IServiceProvider * PSP;

HRESULT HR = M_PWebBBBBROWSER-> QueryInterface (IID_ISERVICEPROVIDER, (LPVOID *) & PSP);

m_pwebbrowser-> release ();

En (ac))

{

HR = PSP-> QueryService (SID_STRAVELLOGCURSOR, IID_ID_ID *) & m_ptravellogstg;

PSP-> Release ();

}

}

// Create a browsing history menu, BFORWARD indicates that the forward or back 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 historical menus, which can be modified according to the actual situation {

LpoLESTR PSZTITLE;

m_ptravallogenTry-> GetTitle (& Psztitle);

CString startle = psztitle;

IF (BForward)

{

// id_iehistory_middle is a predefined menu item ID, and 10 menu items can be created from the ID before and after, see the next section.

PMenu-> InsertMenu (0, MF_String, ID_IEHISTORY_MIDDLE I, STRTITLE);

}

Else

{

Pmenu-> InsertMenu (0, MF_String, ID_IEHISTORY_MIDDLE - I, startle);

}

CotaskMemfree (psztitle);

m_ptravallogenTry-> release ();

}

}

}

/ / Visit the historical web page according to the relative distance from 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

Suppose is the use of Travel log in the multi-window browser we have written ourselves. For the sake of simplicity, we declare a global object g_ietravellog of CietravelLog to call anywhere. Then in the appropriate place, such as the CMAINFRAME TBN_DropDown message (Tools Menu drop-down message) to process the following code to create a browse history menu:

// getActiveWebBrowserptr returns a browser IWebBrowser2 interface pointer

IetravelLog.setWebBBBBBBROWSER (GetActiveWebBrowserptr);

// bForward creates a "advance" menu for True, otherwise create a "Back" menu

Ietravellog.BuildhistoryMenu (& Menu, 10, BForward);

The following is defined as the range of the menu item ID, and 10 menu items can be accommodated before and after, and can be modified according to the actual situation.

#define id_iehistory_first 60200

#define id_iehistory_middle 60210

#define id_iehistory_last 60220

Add command handler 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 history to be accessed to the current page

g_ietravellog.travelto (NID - ID_IEHISTORY_MIDDLE);

}

6, talk about Travel log

As I mentioned earlier, "Travel log interface is increasingly one of the important interfaces in the application", which is described here. From the development model and orientation of the Microsoft platform, the application based on Internet Explorer / WebBrowser Control will be mainstream. In the next generation of operating system Longhorn, the description of the application interface will be completely completed by an XML of XML, and XAML resolution will be done by the browser. Microsoft said that the deployment of future applications will be very easy, the difference between local applications and browser-based applications will be gradually diminished, and an important manifestation that achieves this goal is to apply on the future operating system platform. The program actually always runs in Internet Explorer, and Internet Explorer has become a container to some extent. Thus, TRAVEL LOG rooted on Internet Explorer naturally is integrated into our application. I don't see, we have done on the resource manager and browser every day, isn't it to come back and forth in Travel log? If all applications are embedded in Internet Explorer, then our operations made in the application naturally have been recorded, "advancement" and "back" are also very easy.

Many software have more or less starting to use Internet Explorer-based models, such as Microsoft Money, Microsoft Encarta, Visual Studio.Net installer, etc., are well samples. Therefore, in order to now, we write our apps according to this mode (can be referred to "Using the browser to implement the program interface and implementation"), isn't it possible to get a "access log experience" earlier?

Hele is not.

Quote address: "Internet Explorer programming brief description (8) Implement browsing history menu

转载请注明原文地址:https://www.9cbs.com/read-51508.html

New Post(0)