类型:转载 责任编辑:asp 日期:2007/03/01
如何编程实现ie工具栏internet选项里清除历史记录,这样在ie地址栏里输入地址时
相关的网址不会出现
推荐阅读
给你个思路!找到internet的历史记录所在的目录,然后,删除所有文件!就ok!
c:\documents and settings\bing\local settings\history
如果是win2k系统,位置在这!
win98你自己找找!
呵呵,说清楚了。
清除internet explorer临时文件 在tfrmmain你必须引用wininet单元 uses wininet; 然后放上一个tbutton按钮命名为btnemptycache,加入以下代码:
procedure tfrmmain.btnemptycacheclick( sender : tobject );
var
lpentryinfo : pinternetcacheentryinfo;
hcachedir : longword;
dwentrysize : longword;
dwlasterror : longword;
begin
dwentrysize := 0;
findfirsturlcacheentry(nil,tinternetcacheentryinfonil^ ),dwentrysize );
getmem( lpentryinfo, dwentrysize );
hcachedir := findfirsturlcacheentry( nil, lpentryinfo^,
dwentrysize );
if ( hcachedir <> 0 ) then
deleteurlcacheentry( lpentryinfo^.lpszsourceurlname );
freemem( lpentryinfo );
repeat
dwentrysize := 0;
findnexturlcacheentry( hcachedir, tinternetcacheentryinfo(
nil^ ), dwentrysize );
dwlasterror := getlasterror();
if ( getlasterror = error_insufficient_buffer ) then begin
getmem( lpentryinfo, dwentrysize );
if ( findnexturlcacheentry( hcachedir, lpentryinfo^,
dwentrysize ) ) then
deleteurlcacheentry( lpentryinfo^.lpszsourceurlname );
freemem(lpentryinfo);
end;
until ( dwlasterror = error_no_more_items );
end;
*********************
type
tstaturl = record
cbsize: dword;
pwcsurl: dword;
pwcstitle: dword;
ftlastvisited: filetime;
ftlastupdated: filetime;
ftexpires: filetime;
dwflags: dword;
end;
type
ienumstaturl = interface(iunknown)
[{3c374a42-bae4-11cf-bf7d-00aa006946ee}]
function next(celt: integer; out elt; pceltfetched: plongint): hresult; stdcall;
function skip(celt: longint): hresult; stdcall;
function reset: hresult; stdcall;
function clone(out ppenum: ienumstaturl): hresult; stdcall;
function setfilter(poszfilter: pwidechar; dwflags: dword): hresult; stdcall;
end;
type
iurlhistorystg = interface(iunknown)
[{3c374a41-bae4-11cf-bf7d-00aa006946ee}]
function addurl(pocsurl: pwidechar; pocstitle: pwidechar; dwflags: integer): hresult; stdcall;
function deleteurl(pocsurl: pwidechar; dwflags: integer): hresult; stdcall;
function queryurl(pocsurl: pwidechar; dwflags: integer; var lpstaturl: tstaturl): hresult; stdcall;
function bindtoobject(pocsurl: pwidechar; var riid: tguid; out ppvout: pointer): hresult; stdcall;
function enumurls(out ppenum: ienumstaturl): hresult; stdcall;
end;
type
iurlhistorystg2 = interface(iurlhistorystg)
[{afa0dc11-c313-11d0-831a-00c04fd5ae38}]
function addurlandnotify(pocsurl: pwidechar; pocstitle: pwidechar; dwflags: integer;
fwritehistory: integer; var poctnotify: pointer;
const punkisfolder: iunknown): hresult; stdcall;
function clearhistory: hresult; stdcall;
end;
function cleariehistory:integer;
const
clsid_curlhistory: tguid = {3c374a40-bae4-11cf-bf7d-00aa006946ee};
var
iehistory:iurlhistorystg2;
begin
iehistory:=createcomobject(clsid_curlhistory) as iurlhistorystg2;
iehistory.clearhistory;
end;
procedure tform1.button1click(sender: tobject);
begin
cleariehistory;
end;
**********************
uses wininet;
procedure tform1.button1click(sender: tobject);
var
cache_info:pinternetcacheentryinfo;
cbsizeof_cache_info:dword;
hw:hwnd;
buf:tstrings;
begin
// buf:=tstringlist.create;
new(cache_info);
hw:=findfirsturlcacheentryex(nil,0,normal_cache_entry or urlhistory_cache_entry,0,cache_info,@cbsizeof_cache_info,nil,nil,nil);
if hw<>0 then
begin
deleteurlcacheentry(cache_info.lpszsourceurlname);
// buf.add(cache_info.lpszsourceurlname);
while findnexturlcacheentryex(hw,cache_info,@cbsizeof_cache_info,nil,nil,nil) do
// buf.add(cache_info.lpszsourceurlname);
deleteurlcacheentry(cache_info.lpszsourceurlname);
end;
findcloseurlcache(hw);
dispose(cache_info);
// showmessage(buf.text);
// buf.free;
end;
给你一个完成代码,很有效:
unit unit;
interface
uses
windows, messages, sysutils, classes, graphics, controls, forms, dialogs,
activex, comobj, stdctrls, comctrls, grids;
const
staturl_queryflag_iscached = $00010000;
staturl_queryflag_nourl = $00020000;
staturl_queryflag_notitle = $00040000;
staturl_queryflag_toplevel = $00080000;
staturlflag_iscached = $00000001;
staturlflag_istoplevel = $00000002;
iid_ienumstaturl: tguid = (d1: $3c374a42; d2: $bae4; d3: $11cf; d4: ($bf, $7d, $00, $aa, $00, $69, $46, $ee));
iid_iurlhistorystg: tguid = (d1: $3c374a41; d2: $bae4; d3: $11cf; d4: ($bf, $7d, $00, $aa, $00, $69, $46, $ee));
iid_iurlhistorystg2: tguid = (d1: $afa0dc11; d2: $c313; d3: $831a; d4: ($83, $1a, $00, $c0, $4f, $d5, $ae, $38));
iid_iurlhistorynotify: tguid = (d1: $bc40bec1; d2: $c493; d3: $11d0; d4: ($83, $1b, $00, $c0, $4f, $d5, $ae, $38));
sid_ienumstaturl = {3c374a42-bae4-11cf-bf7d-00aa006946ee};
sid_iurlhistorystg = {3c374a41-bae4-11cf-bf7d-00aa006946ee};
sid_iurlhistorystg2 = {afa0dc11-c313-11d0-831a-00c04fd5ae38};
sid_iurlhistorynotify = {bc40bec1-c493-11d0-831b-00c04fd5ae38};
clsid_curlhistory: tguid = {3c374a40-bae4-11cf-bf7d-00aa006946ee};
type
staturl = record
cbsize: dword;
pwcsurl: dword;
pwcstitle: dword;
ftlastvisited: filetime;
ftlastupdated: filetime;
ftexpires: filetime;
dwflags: dword;
end;
ienumstaturl = interface(iunknown)
[{3c374a42-bae4-11cf-bf7d-00aa006946ee}]
function next(celt: integer; out elt; pceltfetched: plongint): hresult; stdcall;
function skip(celt: longint): hresult; stdcall;
function reset: hresult; stdcall;
function clone(out ppenum: ienumstaturl): hresult; stdcall;
function setfilter(poszfilter: pwidechar; dwflags: dword): hresult; stdcall;
end;
iurlhistorystg = interface(iunknown)
[{3c374a41-bae4-11cf-bf7d-00aa006946ee}]
function addurl(pocsurl: pwidechar; pocstitle: pwidechar; dwflags: integer): hresult; stdcall;
function deleteurl(pocsurl: pwidechar; dwflags: integer): hresult; stdcall;
function queryurl(pocsurl: pwidechar; dwflags: integer; var lpstaturl: staturl): hresult; stdcall;
function bindtoobject(pocsurl: pwidechar; var riid: tiid; out ppvout: pointer): hresult; stdcall;
function enumurls(out ppenum: ienumstaturl): hresult; stdcall;
end;
iurlhistorystg2 = interface(iurlhistorystg)
[{afa0dc11-c313-11d0-831a-00c04fd5ae38}]
function addurlandnotify(pocsurl: pwidechar; pocstitle: pwidechar; dwflags: integer;
fwritehistory: integer; var poctnotify: pointer;
const punkisfolder: iunknown): hresult; stdcall;
function clearhistory: hresult; stdcall;
end;
iurlhistorynotify = interface(iolecommandtarget)
[{bc40bec1-c493-11d0-831b-00c04fd5ae38}]
end;
tform1 = class(tform)
stringgrid1: tstringgrid;
retrievebtn: tbutton;
clearbtn: tbutton;
procedure retrievebtnclick(sender: tobject);
procedure clearbtnclick(sender: tobject);
private
{ private declarations }
public
{ public declarations }
end;
var
form1: tform1;
i: iurlhistorystg2;
implementation
{$r *.dfm}
function filetimetodt(ft: tfiletime): tdatetime;
var
l: integer;
lft: tfiletime;
begin
filetimetolocalfiletime(ft, lft);
if filetimetodosdatetime(lft, longrec(l).hi, longrec(l).lo) then
result := filedatetodatetime(l) else
result := 0;
end;
//显示历史记录
procedure tform1.retrievebtnclick(sender: tobject);
var
r: staturl;
enum: ienumstaturl;
x: integer;
row: integer;
begin
stringgrid1.cells[0, 0] := last visited;
stringgrid1.cells[1, 0] := title;
stringgrid1.cells[2, 0] := url;
stringgrid1.cells[3, 0] := last updated;
stringgrid1.cells[4, 0] := expires;
row := 0;
i := createcomobject(clsid_curlhistory) as iurlhistorystg2;
i.enumurls(enum);
enum.setfilter(http://, 0);
while enum.next(1, r, @x) = s_ok do begin
inc(row);
stringgrid1.rowcount := row + 1;
stringgrid1.cells[0, row] := datetimetostr(filetimetodt(r.ftlastvisited));
stringgrid1.cells[1, row] := pwidechar(pointer(r.pwcstitle));
stringgrid1.cells[2, row] := pwidechar(pointer(r.pwcsurl));
stringgrid1.cells[3, row] := datetimetostr(filetimetodt(r.ftlastupdated));
stringgrid1.cells[4, row] := datetimetostr(filetimetodt(r.ftexpires));
end;
end;
//清除历史记录
procedure tform1.clearbtnclick(sender: tobject);
begin
i.clearhistory;
end;
end.