VC MFC程序,列举浏览器“历史”记录并记录到文件中:
void CMy111Dlg::OnButton1()
{
HRESULT hr;
IUrlHistoryStg2 *puhs;
IEnumSTATURL *pesu;
STATURL su;
ULONG celt;
_bstr_t bstr;
hr = ::CoCreateInstance(CLSID_CUrlHistory, NULL, CLSCTX_INPROC_SERVER, IID_IUrlHistoryStg, (LPVOID*)&puhs);
if(SUCCEEDED(hr))
{
hr = puhs-> EnumUrls(&pesu);
if(SUCCEEDED(hr))
{
CStdioFile file;
if(file.Open("history.txt", CFile::modeCreate | CFile::modeWrite))
{
while(SUCCEEDED(pesu->Next(1, &su, &celt)) && celt > 0)
{
bstr = su.pwcsUrl;
file.WriteString(bstr + "\n");
}
file.Close();
}
puhs-> Release();
}
}
}
千万不要忘了添加头文件:
#include <urlhist.h> // Needed for IUrlHistoryStg2 and IID_IUrlHistoryStg2
#include <COMDEF.H>