using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices; //命名空間
using System.Reflection; //提供加載類型 Pointer指針
using Microsoft.Win32; //RegistryKeynamespace GetIE
{#region COM接口實現(xiàn)獲取IE歷史記錄//自定義結(jié)構(gòu) IUrlHistorypublic struct STATURL{public static uint SIZEOF_STATURL =(uint)Marshal.SizeOf(typeof(STATURL));public uint cbSize; //網(wǎng)頁大小[MarshalAs(UnmanagedType.LPWStr)] //網(wǎng)頁Urlpublic string pwcsUrl;[MarshalAs(UnmanagedType.LPWStr)] //網(wǎng)頁標(biāo)題public string pwcsTitle;public System.Runtime.InteropServices.ComTypes.FILETIMEftLastVisited, //網(wǎng)頁最近訪問時間ftLastUpdated, //網(wǎng)頁最近更新時間ftExpires;public uint dwFlags;}//ComImport屬性通過guid調(diào)用com組件[ComImport, Guid("3C374A42-BAE4-11CF-BF7D-00AA006946EE"),InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]interface IEnumSTATURL{[PreserveSig]//搜索IE歷史記錄匹配的搜索模式并復(fù)制到指定緩沖區(qū)uint Next(uint celt, out STATURL rgelt, out uint pceltFetched);void Skip(uint celt);void Reset();void Clone(out IEnumSTATURL ppenum);void SetFilter([MarshalAs(UnmanagedType.LPWStr)] string poszFilter,uint dwFlags);}[ComImport, Guid("AFA0DC11-C313-11d0-831A-00C04FD5AE38"),InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]interface IUrlHistoryStg2{#region IUrlHistoryStg methodsvoid AddUrl([MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,[MarshalAs(UnmanagedType.LPWStr)] string pocsTitle,uint dwFlags);void DeleteUrl([MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,uint dwFlags);void QueryUrl([MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,uint dwFlags,ref STATURL lpSTATURL);void BindToObject([MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,ref Guid riid,[MarshalAs(UnmanagedType.IUnknown)] out object ppvOut);IEnumSTATURL EnumUrls();#endregionvoid AddUrlAndNotify([MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,[MarshalAs(UnmanagedType.LPWStr)] string pocsTitle,uint dwFlags,[MarshalAs(UnmanagedType.Bool)] bool fWriteHistory,[MarshalAs(UnmanagedType.IUnknown)] object /*IOleCommandTarget*/poctNotify,[MarshalAs(UnmanagedType.IUnknown)] object punkISFolder);void ClearHistory(); //清除歷史記錄}[ComImport, Guid("3C374A40-BAE4-11CF-BF7D-00AA006946EE")]class UrlHistory /* : IUrlHistoryStg[2] */ { }#endregion//調(diào)用COM接口IUrHistory方法實現(xiàn)public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){IUrlHistoryStg2 vUrlHistoryStg2 = (IUrlHistoryStg2)new UrlHistory();IEnumSTATURL vEnumSTATURL = vUrlHistoryStg2.EnumUrls();STATURL vSTATURL;uint vFectched;while (vEnumSTATURL.Next(1, out vSTATURL, out vFectched) == 0){ richTextBox1.AppendText(string.Format("{0}\r\n{1}\r\n",vSTATURL.pwcsTitle, vSTATURL.pwcsUrl));}}}
}
經(jīng)過我的處理后運(yùn)行結(jié)果如下圖所示: ?
這里也提供他的一篇文章,采用另外一種方法調(diào)用IE的API函數(shù)實現(xiàn) http://blog.sina.com.cn/s/blog_589d32f5010007xf.html 但是我也遇到了一個問題,就是它的ftLastVisited(The last time the user visited this page)存儲該網(wǎng)頁最后訪問時間,想通過該時間進(jìn)行獲取今天訪問的或排序輸出前100.但是獲取該時間時總輸出錯誤,同時將FILETIME轉(zhuǎn)換成SYSTEMTIME或time_t都沒成功.希望以后能解決. 最后該文章主要是結(jié)合自己的實際東西講解,如果你剛好遇到類似的問題就可能對你有所幫助.同時如果在文章中遇到錯誤或不足的地方,請海涵!最重要的是感謝上面提到的博主.希望能把獲取時間等問題也解決.請尊重作者的勞動果實,勿噴!!! (By:Eastmount 2014-4-3 夜2點半 原創(chuàng)CSDNhttp://blog.csdn.net/eastmount/)