//命令句柄ID,是來自Shell DocObject VIEw這個類
const ID_IE_FILE_PAGESETUP = 259;
const ID_IE_FILE_PRINT = 260;
const ID_IE_FILE_NEWWINDOW = 275;
const ID_IE_FILE_PRINTPREVIEW = 277;
const ID_IE_FILE_NEWMAIL = 279;
const ID_IE_FILE_SENDPAGE = 282;
const ID_IE_FILE_SENDLINK = 283;
const ID_IE_FILE_SENDDESKTOPSHORTCUT = 284;
const ID_IE_HELP_VERSIONINFO = 336;
const ID_IE_HELP_HELPINDEX = 337;
const ID_IE_HELP_WEBTUTORIAL = 338;
const ID_IE_HELP_FREESTUFF = 341;
const ID_IE_HELP_PRODUCTUPDATE = 342;
const ID_IE_HELP_FAQ = 343;
const ID_IE_HELP_ONLINESUPPORT = 344;
const ID_IE_HELP_FEEDBACK = 345;
const ID_IE_HELP_BESTPAGE = 346;
const ID_IE_HELP_SEARCHWEB = 347;
const ID_IE_HELP_MSHOME = 348;
const ID_IE_HELP_VISITINTERNET = 349;
const ID_IE_HELP_STARTPAGE = 350;
const ID_IE_HELP_NETSCAPEUSER = 351;
const ID_IE_FILE_IMPORTEXPORT = 374;
const ID_IE_HELP_ENHANCEDSECURITY = 375;
const ID_IE_FILE_ADDTRUST = 376;
const ID_IE_FILE_ADDLOCAL = 377;
const ID_IE_FILE_NEWPUBLISHINFO = 387;
const ID_IE_FILE_NEWPEOPLE = 390;
const ID_IE_FILE_NEWCALL =395; //命令句柄ID,是來自 'Internet Explorer_Server'
const ID_IE_CONTEXTMENU_NEWWINDOW = 2137;
const ID_IE_CONTEXTMENU_ADDFAV = 2261;
const ID_IE_CONTEXTMENU_REFRESH = 6042; //下面是獲取IE
句柄:
function GetIEHandle(WebBrowser: TWebbrowser; ClassName: string): HWND;
var
hwndChild, hwndTmp: HWND;
oleCtrl: TOleControl;
szClass: array [0..255] of char;
begin
oleCtrl :=WebBrowser;
hwndTmp := oleCtrl.Handle;
while (true) do
begin
hwndChild := GetWindow(hwndTmp, GW_CHILD);
GetClassName(hwndChild, szClass, SizeOf(szClass));
if (string(szClass)=ClassName) then
begin
Result :=hwndChild;
Exit;
end;
hwndTmp := hwndChild;
end;
Result := 0;
end; //先是試試調用‘添加到收藏夾’
procedure TForm1.ToolButton2Click(Sender: TObject);
begin
SendMessage(GetIEHandle(web, 'Internet Explorer_Server'), WM_COMMAND, ID_IE_CONTEXTMENU_ADDFAV, 0);
end; //再試試'導入和導出'
procedure TForm1.ToolButton3Click(Sender: TObject);
begin
SendMessage(GetIEHandle(web, 'Shell DocObject View'), WM_COMMAND, ID_IE_FILE_IMPORTEXPORT, 0);
end; //初始化
procedure TForm1.FormCreate(Sender: TObject);
begin
web.Go(http://blog.csdn.Net/laoli/');
end; //ok //