C# 取历史记录 接口方式

fengxiao80444 2008-12-22 03:39:26
rt
...全文
4021 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
李小魂 2011-08-23
  • 打赏
  • 举报
回复
mark一下
chenghu2439 2010-10-29
  • 打赏
  • 举报
回复
Mark
捷哥1999 2010-05-14
  • 打赏
  • 举报
回复

查询了API中FindFirstUrlCacheEntryEx方法的定义,后修改FindFirstUrlCacheEntryEx定义如下:
[DllImport("wininet.dll")]
//Starts a filtered enumeration of the Internet cache.
public static extern IntPtr FindFirstUrlCacheEntryEx(
//A pointer to a string that contains the source name pattern to search for.
//This parameter can only be set to "cookie:", "visited:", or NULL.
//Set this parameter to "cookie:" to enumerate the cookies
//or "visited:" to enumerate the URL History entries in the cache.
//If this parameter is NULL, FindFirstUrlCacheEntryEx returns all content entries in the cache.
string lpszUrlSearchPattern,
//Controls the enumeration. No flags are currently implemented; this parameter must be set to zero.
uint dwFlags,
//A bitmask indicating the type of cache entry and its properties.
//The cache entry types include:
//history entries (URLHISTORY_CACHE_ENTRY),
//cookie entries (COOKIE_CACHE_ENTRY),
//and normal cached content (NORMAL_CACHE_ENTRY).
uint dwFilter,
//ID of the cache group to be enumerated. Set this parameter to zero to enumerate all entries that are not grouped.
Int64 GroupId,
//Pointer to a INTERNET_CACHE_ENTRY_INFO structure to receive the cache entry information.
IntPtr lpFirstCacheEntryInfo,
//Pointer to variable that indicates the size of the structure referenced by the lpFirstCacheEntryInfo parameter, in bytes.
ref uint lpdwFirstCacheEntryInfoBufferSize,
//This parameter is reserved and must be NULL.
IntPtr lpGroupAttributes,
//This parameter is reserved and must be NULL.
IntPtr pcbGroupAttributes,
//his parameter is reserved and must be NULL.
IntPtr lpReserved
);

然后这么调用就可以了:

FindNextUrlCacheEntryEx(vHandle, (IntPtr)null, ref vFirstCacheEntryInfoBufferSize, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
FindNextUrlCacheEntryEx(vHandle, vBuffer, ref vFirstCacheEntryInfoBufferSize, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero)
捷哥1999 2010-05-14
  • 打赏
  • 举报
回复
Pointer 都没有定义,程序还不能用!
优途科技 2008-12-23
  • 打赏
  • 举报
回复
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential)]
public class INTERNET_CACHE_ENTRY_INFOW
{
public uint dwStructSize;
public string lpszSourceUrlName;
public string lpszLocalFileName;
public uint CacheEntryType;
public uint dwUseCount;
public uint dwHitRate;
public uint dwSizeLow;
public uint dwSizeHigh;
public FILETIME LastModifiedTime;
public FILETIME ExpireTime;
public FILETIME LastAccessTime;
public FILETIME LastSyncTime;
public IntPtr lpHeaderInfo;
public uint dwHeaderInfoSize;
public string lpszFileExtension;
public uint dwReserved; //union uint dwExemptDelta;
}

[DllImport("wininet.dll")]
public static extern IntPtr FindFirstUrlCacheEntryEx(

string lpszUrlSearchPattern,
uint dwFlags,
uint dwFilter,
Int64 GroupId,
IntPtr lpFirstCacheEntryInfo,
ref uint lpdwFirstCacheEntryInfoBufferSize,
Pointer lpGroupAttributes,
Pointer pcbGroupAttributes,
Pointer lpReserved
);

[DllImport("wininet.dll")]
public static extern bool FindCloseUrlCache(IntPtr hEnumHandle);

[DllImport("wininet.dll")]
public static extern bool FindNextUrlCacheEntryEx(
IntPtr hEnumHandle,
IntPtr lpFirstCacheEntryInfo,
ref uint lpdwFirstCacheEntryInfoBufferSize,
Pointer lpGroupAttributes,
Pointer pcbGroupAttributes,
Pointer lpReserved);

public uint NORMAL_CACHE_ENTRY = 0x00000001;

private void button1_Click(object sender, EventArgs e)
{
IntPtr vHandle;
INTERNET_CACHE_ENTRY_INFOW vInternetCacheEntryInfo = new INTERNET_CACHE_ENTRY_INFOW();
uint vFirstCacheEntryInfoBufferSize = 0;
FindFirstUrlCacheEntryEx(null, 0, NORMAL_CACHE_ENTRY, 0, (IntPtr)null,
ref vFirstCacheEntryInfoBufferSize, null, null, null);
IntPtr vBuffer = Marshal.AllocHGlobal((int)vFirstCacheEntryInfoBufferSize);
vHandle = FindFirstUrlCacheEntryEx(null, 0, NORMAL_CACHE_ENTRY, 0,
vBuffer, ref vFirstCacheEntryInfoBufferSize,
null, null, null);
while (vHandle != null)
{
Marshal.PtrToStructure(vBuffer, vInternetCacheEntryInfo);
richTextBox1.AppendText(vInternetCacheEntryInfo.lpszSourceUrlName + "\r\n");
Marshal.FreeCoTaskMem(vBuffer);

FindNextUrlCacheEntryEx(vHandle, (IntPtr)null, ref vFirstCacheEntryInfoBufferSize,
null, null, null);
vBuffer = Marshal.AllocHGlobal((int)vFirstCacheEntryInfoBufferSize);
if (!FindNextUrlCacheEntryEx(vHandle, vBuffer,
ref vFirstCacheEntryInfoBufferSize, null, null, null)) break;
}
Marshal.FreeCoTaskMem(vBuffer);
}

//-------接口方式-------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace IEHistory
{
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}:{1}\r\n",
vSTATURL.pwcsTitle, vSTATURL.pwcsUrl));
}
//vUrlHistoryStg2.ClearHistory();//清除历史
}
}

struct STATURL
{
public static uint SIZEOF_STATURL =
(uint)Marshal.SizeOf(typeof(STATURL));

public uint cbSize;
[MarshalAs(UnmanagedType.LPWStr)]
public string pwcsUrl;
[MarshalAs(UnmanagedType.LPWStr)]
public string pwcsTitle;
public FILETIME ftLastVisited,
ftLastUpdated,
ftExpires;
public uint dwFlags;
}

[ComImport, Guid("3C374A42-BAE4-11CF-BF7D-00AA006946EE"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IEnumSTATURL
{
[PreserveSig]
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 methods
void 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();
#endregion

void 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] */ { }
}


------------------
up。强!
sxmonsy 2008-12-23
  • 打赏
  • 举报
回复
学习下.
qiying1988 2008-12-23
  • 打赏
  • 举报
回复
学习
王集鹄 2008-12-23
  • 打赏
  • 举报
回复
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential)]
public class INTERNET_CACHE_ENTRY_INFOW
{
public uint dwStructSize;
public string lpszSourceUrlName;
public string lpszLocalFileName;
public uint CacheEntryType;
public uint dwUseCount;
public uint dwHitRate;
public uint dwSizeLow;
public uint dwSizeHigh;
public FILETIME LastModifiedTime;
public FILETIME ExpireTime;
public FILETIME LastAccessTime;
public FILETIME LastSyncTime;
public IntPtr lpHeaderInfo;
public uint dwHeaderInfoSize;
public string lpszFileExtension;
public uint dwReserved; //union uint dwExemptDelta;
}

[DllImport("wininet.dll")]
public static extern IntPtr FindFirstUrlCacheEntryEx(

string lpszUrlSearchPattern,
uint dwFlags,
uint dwFilter,
Int64 GroupId,
IntPtr lpFirstCacheEntryInfo,
ref uint lpdwFirstCacheEntryInfoBufferSize,
Pointer lpGroupAttributes,
Pointer pcbGroupAttributes,
Pointer lpReserved
);

[DllImport("wininet.dll")]
public static extern bool FindCloseUrlCache(IntPtr hEnumHandle);

[DllImport("wininet.dll")]
public static extern bool FindNextUrlCacheEntryEx(
IntPtr hEnumHandle,
IntPtr lpFirstCacheEntryInfo,
ref uint lpdwFirstCacheEntryInfoBufferSize,
Pointer lpGroupAttributes,
Pointer pcbGroupAttributes,
Pointer lpReserved);

public uint NORMAL_CACHE_ENTRY = 0x00000001;

private void button1_Click(object sender, EventArgs e)
{
IntPtr vHandle;
INTERNET_CACHE_ENTRY_INFOW vInternetCacheEntryInfo = new INTERNET_CACHE_ENTRY_INFOW();
uint vFirstCacheEntryInfoBufferSize = 0;
FindFirstUrlCacheEntryEx(null, 0, NORMAL_CACHE_ENTRY, 0, (IntPtr)null,
ref vFirstCacheEntryInfoBufferSize, null, null, null);
IntPtr vBuffer = Marshal.AllocHGlobal((int)vFirstCacheEntryInfoBufferSize);
vHandle = FindFirstUrlCacheEntryEx(null, 0, NORMAL_CACHE_ENTRY, 0,
vBuffer, ref vFirstCacheEntryInfoBufferSize,
null, null, null);
while (vHandle != null)
{
Marshal.PtrToStructure(vBuffer, vInternetCacheEntryInfo);
richTextBox1.AppendText(vInternetCacheEntryInfo.lpszSourceUrlName + "\r\n");
Marshal.FreeCoTaskMem(vBuffer);

FindNextUrlCacheEntryEx(vHandle, (IntPtr)null, ref vFirstCacheEntryInfoBufferSize,
null, null, null);
vBuffer = Marshal.AllocHGlobal((int)vFirstCacheEntryInfoBufferSize);
if (!FindNextUrlCacheEntryEx(vHandle, vBuffer,
ref vFirstCacheEntryInfoBufferSize, null, null, null)) break;
}
Marshal.FreeCoTaskMem(vBuffer);
}

//-------接口方式-------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace IEHistory
{
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}:{1}\r\n",
vSTATURL.pwcsTitle, vSTATURL.pwcsUrl));
}
//vUrlHistoryStg2.ClearHistory();//清除历史
}
}

struct STATURL
{
public static uint SIZEOF_STATURL =
(uint)Marshal.SizeOf(typeof(STATURL));

public uint cbSize;
[MarshalAs(UnmanagedType.LPWStr)]
public string pwcsUrl;
[MarshalAs(UnmanagedType.LPWStr)]
public string pwcsTitle;
public FILETIME ftLastVisited,
ftLastUpdated,
ftExpires;
public uint dwFlags;
}

[ComImport, Guid("3C374A42-BAE4-11CF-BF7D-00AA006946EE"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IEnumSTATURL
{
[PreserveSig]
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 methods
void 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();
#endregion

void 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] */ { }
}
fengxiao80444 2008-12-22
  • 打赏
  • 举报
回复
要取到标题
API里面能取到标题吗
cuike519 2008-12-22
  • 打赏
  • 举报
回复
通过下面的方式使用wininet.dll里面的API可以实现,下面是一个函数的声明。
[DllImport("wininet.dll", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool FindNextUrlCacheGroup(IntPtr hFind, ref long lpGroupId, IntPtr lpReserved);

wininet.dll的方法你可以参考MSDN里面:ms-help://MS.MSDNQTR.v90.en/wininet/wininet/wininet_functions.htm

或者在索引里面输入FindNextUrlCacheGroup找到这个函数然后关联过去即可。

别人已经实现的你也可以参考一下,有源代码的:http://www.freevbcode.com/ShowCode.asp?ID=6702

fengxiao80444 2008-12-22
  • 打赏
  • 举报
回复
上网的历史记录
jiang_jiajia10 2008-12-22
  • 打赏
  • 举报
回复
UP
david_anwei 2008-12-22
  • 打赏
  • 举报
回复
什么历史记录啊 !能说清楚点吗?
fengxiao80444 2008-12-22
  • 打赏
  • 举报
回复
清除也要

110,962

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧