一、主要用到了COM组件提供的接口实现,几个接口包括:
1、IUrlHistoryStg、IUrlHistoryStg2(IUrlHistoryStg2接口继承自IUrlHistoryStg)
2、IEnumSTATURL
下面接口信息摘自MSDN
IUrlHistoryStg Interface
IUrlHistoryStg2 Interface
IEnumSTATURL Interface
1、IUrlHistoryStg、IUrlHistoryStg2(IUrlHistoryStg2接口继承自IUrlHistoryStg)
2、IEnumSTATURL
下面接口信息摘自MSDN
IUrlHistoryStg Interface
This interface manages Microsoft Internet Explorer history for the current user.
IUrlHistoryStg Members
AddUrl Places the specified URL into the history. If the URL does not exist in the history, an entry is created in the history. If the URL does exist in the history, it is overwritten. BindToObject Not currently implemented. DeleteUrl Deletes all instances of the specified URL from the history. EnumUrls Returns an interface to an enumerator of the history's visited links. QueryUrl Queries the history and reports whether the URL passed as thepocsUrlparameter has been visited by the current user.
InterfaceInformation
Stock Implementation shdocvw.dll Custom Implementation No Inherits from IUnknown Header and IDL files urlhist.h,urlhist.idl Minimum availability Internet Explorer 5.5 Minimum operating systems Millennium, Windows2000
This interface provides additional features for managing the user's history.
IUrlHistoryStg2 Members
AddUrlAndNotify Provides an advanced method of adding a URL to the history. ClearHistory Clears history on a per-user basis.
InterfaceInformation
Stock Implementation shdocvw.dll Custom Implementation No Inherits from IUrlHistoryStg Header and IDL files urlhist.h,urlhist.idl Minimum availability Internet Explorer 5.5 Minimum operating systems Millennium, Windows2000
This interface enumerates the items in the history cache.
IEnumSTATURL Members
Clone Not currently implemented. Next Searches the history for any URL that matches the search pattern and copies it to the specified buffer. Reset Resets the enumerator interface so that it begins enumerating at the beginning of the history. SetFilter IEnumSTATURL::Nextcompares the specified URL with each URL in the history list to find matches.IEnumSTATURL::Nextthen copies the list of matches to a buffer. This method is used to specify the URL to compare. Skip Not currently implemented.
InterfaceInformation
Stock Implementation shdocvw.dll Custom Implementation No Inherits from IUnknown Header and IDL files urlhist.h,urlhist.idl Minimum availability Internet Explorer 5.5 Minimum operating systems Millennium, Windows2000
二、用到的接口中的相关方法:
1、IUrlHistoryStg::EnumUrls
IUrlHistoryStg::EnumUrlsMethod
Returnsan interface toanenumeratorofthehistory ' svisitedlinks.
Syntax
HRESULTEnumUrls(IEnumSTATURL ** ppEnum);
Parameters
ppEnum:[ out ]Pointerthatreceivesapointertothe interface toahistoryenumerator.
ReturnValue
ReturnsS_OK if successful,oranerrorvalueotherwise.
Returnsan interface toanenumeratorofthehistory ' svisitedlinks.
Syntax
HRESULTEnumUrls(IEnumSTATURL ** ppEnum);
Parameters
ppEnum:[ out ]Pointerthatreceivesapointertothe interface toahistoryenumerator.
ReturnValue
ReturnsS_OK if successful,oranerrorvalueotherwise.
2、IEnumSTATURL::Next
LRESULTIEnumSTATURL::Next(ULONGcelt,LPSTATURLrgelt,ULONG
*
pceltFetched)
参数说明:
celt意义不明,不能为0,可以将其设为1。
Rgelt是STATURL结构指针,该结构由MS - IE填充。
PceltFetched由方法返回,返回1表示rgelt结构被成功填充了。若要用到第二参数内的数据,应该判断该值是否为1。
参数说明:
celt意义不明,不能为0,可以将其设为1。
Rgelt是STATURL结构指针,该结构由MS - IE填充。
PceltFetched由方法返回,返回1表示rgelt结构被成功填充了。若要用到第二参数内的数据,应该判断该值是否为1。
其中结构STATURL定义如下
STATURLStructure
ContainsstatisticsaboutaURL.Thisstructure is filledbyMicrosoftInternetExplorerduringcallstoIUrlHistoryStg::QueryUrlandIEnumSTATURL::Next.
Syntax
typedef struct _STATURL...{
DWORDcbSize;
LPWSTRpwcsUrl;
LPWSTRpwcsTitle;
FILETIMEftLastVisited;
FILETIMEftLastUpdated;
FILETIMEftExpires;
DWORDdwFlags;
}STATURL, * LPSTATURL;
Members
cbSize
DWORDthatshouldbe set to sizeof (STATURL).
pwcsUrl
ThespecifiedURL.Thecallingfunctionmustfree this parameter.Set this parametertoSTATURL_QUERYFLAG_NOURL if noURL is specified.
pwcsTitle
ThetitleoftheWebpage, as contained in thetitletags.Thiscallingapplicationmustfree this parameter.Set this parametertoSTATURL_QUERYFLAG_NOTITLE if noWebpage is specified.
ftLastVisited
Thelasttimetheuservisited this page.
ftLastUpdated
Thelasttimethepagewasupdated.
ftExpires
TheexpirydateoftheWebpage ' scontent.
dwFlags
DWORDthatcanbeeitherSTATURL_QUERYFLAG_ISCACHEDorSTATURL_QUERYFLAG_TOPLEVEL.
ContainsstatisticsaboutaURL.Thisstructure is filledbyMicrosoftInternetExplorerduringcallstoIUrlHistoryStg::QueryUrlandIEnumSTATURL::Next.
Syntax
typedef struct _STATURL...{
DWORDcbSize;
LPWSTRpwcsUrl;
LPWSTRpwcsTitle;
FILETIMEftLastVisited;
FILETIMEftLastUpdated;
FILETIMEftExpires;
DWORDdwFlags;
}STATURL, * LPSTATURL;
Members
cbSize
DWORDthatshouldbe set to sizeof (STATURL).
pwcsUrl
ThespecifiedURL.Thecallingfunctionmustfree this parameter.Set this parametertoSTATURL_QUERYFLAG_NOURL if noURL is specified.
pwcsTitle
ThetitleoftheWebpage, as contained in thetitletags.Thiscallingapplicationmustfree this parameter.Set this parametertoSTATURL_QUERYFLAG_NOTITLE if noWebpage is specified.
ftLastVisited
Thelasttimetheuservisited this page.
ftLastUpdated
Thelasttimethepagewasupdated.
ftExpires
TheexpirydateoftheWebpage ' scontent.
dwFlags
DWORDthatcanbeeitherSTATURL_QUERYFLAG_ISCACHEDorSTATURL_QUERYFLAG_TOPLEVEL.
三、代码实现(VC6.0+Windows XP)
#include
<
stdio.h
>
#include < windows.h >
#include < UrlHist.h > // IUrlHistoryStg2
#include < shlobj.h > // CLSID_CUrlHistory,SHAddToRecentDocs
#include < atlbase.h > // USES_CONVERSION;
void GetIEHistory()
... {
USES_CONVERSION;//Unicode转Ansi用
CoInitialize(NULL);//初始化
IUrlHistoryStg2*pUrlHistoryStg2=NULL;
HRESULThr=CoCreateInstance(CLSID_CUrlHistory,
NULL,CLSCTX_INPROC,IID_IUrlHistoryStg2,
(void**)&pUrlHistoryStg2);
/**//*if(SUCCEEDED(hr))
{
hr=pUrlHistoryStg2->ClearHistory();
pUrlHistoryStg2->Release();
}*/
IEnumSTATURL*pEnumURL;
hr=pUrlHistoryStg2->EnumUrls(&pEnumURL);
STATURLsuURL;
ULONGpceltFetched;
suURL.cbSize=sizeof(suURL);
hr=pEnumURL->Reset();
while((hr=pEnumURL->Next(1,&suURL,&pceltFetched))==S_OK)
...{
//hr=pUrlHistoryStg2->DeleteUrl(suURL.pwcsUrl,0);
printf("%s",W2T(suURL.pwcsUrl));
}
pEnumURL->Release();
pUrlHistoryStg2->Release();
CoUninitialize();
}
#include < windows.h >
#include < UrlHist.h > // IUrlHistoryStg2
#include < shlobj.h > // CLSID_CUrlHistory,SHAddToRecentDocs
#include < atlbase.h > // USES_CONVERSION;
void GetIEHistory()
... {
USES_CONVERSION;//Unicode转Ansi用
CoInitialize(NULL);//初始化
IUrlHistoryStg2*pUrlHistoryStg2=NULL;
HRESULThr=CoCreateInstance(CLSID_CUrlHistory,
NULL,CLSCTX_INPROC,IID_IUrlHistoryStg2,
(void**)&pUrlHistoryStg2);
/**//*if(SUCCEEDED(hr))
{
hr=pUrlHistoryStg2->ClearHistory();
pUrlHistoryStg2->Release();
}*/
IEnumSTATURL*pEnumURL;
hr=pUrlHistoryStg2->EnumUrls(&pEnumURL);
STATURLsuURL;
ULONGpceltFetched;
suURL.cbSize=sizeof(suURL);
hr=pEnumURL->Reset();
while((hr=pEnumURL->Next(1,&suURL,&pceltFetched))==S_OK)
...{
//hr=pUrlHistoryStg2->DeleteUrl(suURL.pwcsUrl,0);
printf("%s",W2T(suURL.pwcsUrl));
}
pEnumURL->Release();
pUrlHistoryStg2->Release();
CoUninitialize();
}