关于Hitsory的问题(二)

解决方案二:

使用IE自己的history对象. 封装其实现, 暴露给用户Add, Query, Delete等方法.

 

使用次方法的重点是windows的com的调用.关于hisroty的主要接口:

IEnumSTATURL ---- 用于遍历当前history中所有的历史纪录. 在windows api中, 每一个历史记录都是STATURL对象.在后面会介绍该对象. 既然该接口是用于遍历, 很容易想到一下方法:

 

//Returns the next \"celt\" URLS from the cache
void Next(int celt, ref STATURL rgelt, out int pceltFetched);

 

//Skips the next \"celt\" URLS from the cache. doed not work.
void Skip(int celt);

 

//Resets the enumeration
void Reset();

 

//Clones this object
void Clone(out IEnumSTATURL ppenum);

 

//Sets the enumeration filter
void SetFilter([MarshalAs(UnmanagedType.LPWStr)] string poszFilter, STATURL_FLAGS dwFlags); 

 

 

IUrlHistoryStg ---- 此接口代表着history对象.可以对其进去添加, 删除, 查询等操作.

//Adds a new history entry
void AddUrl(string url, string title, ADDURL_FLAG dwFlags);
       
//Deletes an entry by its URL. does not work!
void DeleteUrl(string url, int dwFlags);
       
//Returns a STATURL for a given URL
 void QueryUrl([MarshalAs(UnmanagedType.LPWStr)] string url, STATURL_QUERYFLAGS dwFlags, ref STATURL lpSTATURL);
       
//Binds to an object. does not work!
 void BindToObject([In] string url, [In] UUID riid, IntPtr ppvOut);
        
//Returns an enumerator for URLs
object EnumUrls { [return: MarshalAs(UnmanagedType.IUnknown)] get; }

 

 

 IUrlHistoryStg2 ---- 加强版本的IUrlHistoryStg.在其基础上, 添加了新的方法. 实际应用中主要使用的接口.

 

Code

 

 

1. STATURL对象

 

该对象是存储在hisroty对应于一个url的对象.

 

2.  STATURL对象操作时用到的enum

 

public enum STATURL_QUERYFLAGS : uint
    {
        /// <summary>
        /// The specified URL is in the content cache.
        /// </summary>
        STATURL_QUERYFLAG_ISCACHED = 0x00010000,
        /// <summary>
        /// Space for the URL is not allocated when querying for STATURL.
        /// </summary>
        STATURL_QUERYFLAG_NOURL = 0x00020000,
        /// <summary>
        /// Space for the Web page's title is not allocated when querying for STATURL.
        /// </summary>
        STATURL_QUERYFLAG_NOTITLE = 0x00040000,
        /// <summary>
        /// //The item is a top-level item.
        /// </summary>
        STATURL_QUERYFLAG_TOPLEVEL = 0x00080000,

    }

 

public enum STATURL_FLAGS : uint
    {
        /// <summary>
        /// Flag on the dwFlags parameter of the STATURL structure
        /// indicating that the item is in the cache.
        /// </summary>
        STATURL_FLAG_ISCACHED = 0x00000001,
        /// <summary>
        /// Flag on the dwFlags parameter of the STATURL structure
        /// indicating that the item is a top-level item.
        /// </summary>
        STATURL_FLAG_ISTOPLEVEL = 0x00000002,
    }

 

public enum ADDURL_FLAG : uint
    {
        /// <summary>
        /// Write to both the visited links and the dated containers.
        /// </summary>
        ADDURL_ADDTOHISTORYANDCACHE = 0,
        /// <summary>
        /// Write to only the visited links container.
        /// </summary>
        ADDURL_ADDTOCACHE = 1
    }

 

3. 对hisroty的包装.

 

3.1   在cache history中的遍历类.

 

Code

 

 

3.2   使用该遍历的包装类

 

 

Code

posted on 2008-07-31 14:20  Joe.W.Chen  阅读(710)  评论(0编辑  收藏  举报

导航