“确定”,同时在DoAddToFavDlg的第二个参数中返回用户希望放置Internet快捷方式的路径,建立.Url文件的工作由应用
程序自己来完成。
procedure TForm1.AddFavorite(IE: TEmbeddedWB);
procedure CreateUrl(AUrlPath, AUrl: PChar);
var
URLfile: TIniFile;
begin
URLfile := TIniFile.Create(String(AUrlPath));
RLfile.WriteString(''InternetShortcut'', ''URL'',
String(AUrl));
RLfile.Free;
end;
var
AddFav: function(Handle: THandle;
UrlPath: PChar; UrlPathSize: Cardinal;
Title: PChar; TitleSize: Cardinal;
FavIDLIST: pItemIDList): Bool; stdcall;
FDoc: IHTMLDocument2;
UrlPath, url, title: array[0..MAX_PATH] of char;
H: HWnd;
pidl: pItemIDList;
FRetOK: Bool;
begin
FDoc := IHTMLDocument2(IE.Document);
if FDoc = nil then exit;
StrPCopy(Title, FDoc.Get_title);
StrPCopy(url, FDoc.Get_url);
if Url <> '''' then
begin
H := LoadLibrary(PChar(''shdocvw.dll''));
if H <> 0 then
begin
SHGetSpecialFolderLocation(0, CSIDL_FAVORITES, pidl);
AddFav := GetProcAddress(H, PChar(''DoAddToFavDlg''));
if Assigned(AddFav) then
FRetOK :=AddFav(Handle, UrlPath, Sizeof(UrlPath),
Title, Sizeof(Title), pidl)
end;
FreeLibrary(h);
if FRetOK then
CreateUrl(UrlPath, Url);
end
end;
-----------------------------------------------------------------------------------
6、使WebBrowser获得焦点
TWebBrowser非常特殊,它从TWinControl继承来的SetFocus方法并不能使得它所包含的文档获得焦点,从而不能立即使用Internet
Explorer本身具有得快捷键,解决方法如下:<
procedure TForm1.SetFocusToDoc;
begin
if WebBrowser1.Document <> nil then
with WebBrowser1.Application as IOleobject do
DoVerb(OLEIVERB_UIACTIVATE, nil, WebBrowser1, 0, Handle,
GetClientRect);
end;
除此之外,我还找到一种更简单的方法,这里一并列出:
if WebBrowser1.Document <> nil then
IHTMLWindow2(IHTMLDocument2(WebBrowser1.Document).ParentWindow).focus
刚找到了更简单的方法,也许是最简单的:
if WebBrowser1.Document <> nil then
IHTMLWindow4(WebBrowser1.Document).focus
还有,需要判断文档是否获得焦点这样来做:
if IHTMLWindow4(WebBrowser1.Document).hasfocus then
-----------------------------------------------------------------------------------
7、点击“提交”按钮
如同
程序里每个窗体上有一个“缺省”按钮一样,Web页面上的每个Form也有一个“缺省”按钮——即属性为