首页  编辑  

ie 里收藏夹成为popmenu

Tags: /超级猛料/OS.操作系统/IE.扩展/历史记录、Cache、收藏夹、Cookie/   Date Created:

]、。·ˉˇ¨〃々—~‖…’”〕〉》」』〗】∶!"'),.:;?]` //创建菜单

procedure Tfrm_MainForm.FindWebFavorites;

var

 WindowDirChar:Array[0..MAX_PATH] of Char;

 WindowDir :String;

Begin

 GetWindowsDirectory(WindowDirChar,MAX_PATH);  //我这里取的系统目录,准确的应在注册表中取得

 WindowDir :=StrPas(WindowDirChar);

 if WindowDir[Length(WindowDir)]<>'\' then WindowDir :=WindowDir +'\';

 WindowDir :=WindowDir +'Favorites';

 FavoritesMenuItem.Clear;  //菜单

 CreateFavoritesMenu(WindowDir,FavoritesMenuItem);

End;

//读取URL文件内容

function Tfrm_MainForm.GetUrlFileURL(FilePath,FileName:String):String;

Var

 IniFile:TIniFile;

Begin

 IniFile:=TIniFile.Create(FilePath+'\'+FileName);

 Result :=IniFile.ReadString('InternetShortcut','URL','about:blank');

 IniFile.Free;

End;

//以下是递归取得收藏的所有目录和URL

procedure Tfrm_MainForm.CreateFavoritesMenu(Const WorkDir:String;Var MenuItem:TMenuItem);

Var

 SearchRec:TSearchRec;

 FWorkDir:String;

 SubMenuItem:TMenuItem;

begin

 FWorkDir :=WorkDir;

 if (FindFirst(FWorkDir +'\*.*', faDirectory,SearchRec)=0) then

 begin

   repeat

     if (SearchRec.Attr and faDirectory = faDirectory) then

     Begin

       if (SearchRec.Name <>'.')and (SearchRec.Name <>'..') then

       begin

         SubMenuItem:=TMenuItem.Create(Self);

         SubMenuItem.Caption :=SearchRec.Name;

         MenuItem.Add(SubMenuItem);  //子目录

         CreateFavoritesMenu(FWorkDir+'\'+SearchRec.Name,SubMenuItem);

       end;

     end;

   until FindNext(SearchRec) <> 0;

 End;

 FindClose(SearchRec);

 if (FindFirst(FWorkDir +'\*.*', faDirectory,SearchRec)=0) then

 begin

   repeat

     if (SearchRec.Attr and faDirectory <> faDirectory) then

     Begin

       SubMenuItem:=TMenuItem.Create(MenuItem);

       SubMenuItem.Caption :=Copy(SearchRec.Name,1,Length(SearchRec.Name)-4);

       if Length(SubMenuItem.Caption) >25 then

         SubMenuItem.Caption :=Copy(SubMenuItem.Caption,1,25)+'...';

       SubMenuItem.Hint :=GetUrlFileURL(FWorkDir,SearchRec.Name);

       SubMenuItem.OnClick :=MenuItem_FaClick;

       MenuItem.Add(SubMenuItem);

     end;

   until FindNext(SearchRec) <> 0;

 End;

 FindClose(SearchRec);

End;

//菜单单击事件处理

procedure Tfrm_MainForm.MenuItem_FaClick(Sender: TObject);

begin

//  if ActiveMDIChild = nil then

//    Action_NewExecute(nil);

//  Tfrm_Explorer(WindowList.Items[GetChildFormListNumber(ActiveMDIChild.Tag)]).

 WebBrowser.Navigate((Sender As TMenuItem).Hint);

end;