谁能解释一下这两段Dephi代码(作用:打开IE添加收藏和管理收藏夹对话框)的原理,并将其翻译为C++ Builder语言,多谢了!!!(100分)

  • 主题发起人 主题发起人 prog1
  • 开始时间 开始时间
P

prog1

Unregistered / Unconfirmed
GUEST, unregistred user!
谁能解释一下这两段Dephi代码(作用:打开IE添加收藏和管理收藏夹对话框)的
原理,并将其翻译为C++ Builder语言,多谢了!!!
const
 CLSID_ShellUIHelper: TGUID = '{64AB4BB7-111E-11D1-8F79-00C04FC2FBE1}';

procedure TForm1.OrganizeFavorites1Click(Sender: TObject);
var
 H: HWnd;
 p: procedure(Handle: THandle;
Path: PChar);
stdcall;
begin

    H := LoadLibrary(PChar('shdocvw.dll'));
    if H <> 0 then

     begin

      p := GetProcAddress(H, PChar('DoOrganizeFavDlg'));
      if Assigned(p) then
p(Application.Handle, PChar(Favorites1.Hint));
     end;

    FreeLibrary(h);
end;


procedure TForm1.AddtoFavorites1Click(Sender: TObject);
var
 ShellUIHelper: ISHellUIHelper;
 url, title: Olevariant;
begin

    Title := EmbeddedWB1.LocationName;
    Url := EmbeddedWB1.LocationUrl;
    if Url <> '' then

     begin

      ShellUIHelper := CreateComObject(CLSID_SHELLUIHELPER) as IShellUIHelper;
      ShellUIHelper.AddFavorite(url, title);
     end;

end;

 
加上
unit x...xx;
interface
uses ........;
type
TForm1 =
...
end;
const
...
implementation
procedure TForm1.OrganizeFavorites1Click
.....
end;

end.

保存为 x...xx.pas (同第一句)
加入工程,OK,要什么翻译。

 
第一段已经有人回答过了
对于第二段
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "SHDocVw_Tlb.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
IShellUIHelper *p;
if(SUCCEEDED(CoInitialize(NULL)))
{
if(SUCCEEDED(CoCreateInstanceCLSID_CppShellUIHelper,NULL,
CLSCTX_INPROC_SERVER,
IID_IShellUIHelper,(void **)&amp;p)))
{
WideString str = "http://www.delphibbs.com";
OleVariant title = AnsiString("大富翁网站");
p->AddFavorite(str.c_bstr(),title);
p->Release();
}
CoUninitialize();
}
}
 
http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=261173
 
多人接受答案了。
 
后退
顶部