首页  编辑  

WebBrowsekong控件的SetFocus

Tags: /超级猛料/OS.操作系统/IE.扩展/TWebBrowser/输入/   Date Created:

{

 Anyone that has worked with TWebBrowser knows that the

 TWebBrowser.SetFocus procedure doesn't set focus on the "web page",

 but rather on the control itself, which doesn't do us a whole lot of good.

 Here are two possibilities to set the focus on the "web page" (i.e., document):

}

{1}

uses

 ActiveX;

begin

 WebBrowser1.Navigate('irgendeinedatei.html');

 with WebBrowser1 do

 if Document <> nil then

   with Application as IOleobject do

     DoVerb(OLEIVERB_UIACTIVATE, nil, WebBrowser1, 0, Handle,

       GetClientRect);

end;

{2}

uses

 MSHTML;

begin

 WebBrowser1.Navigate('irgendeinedatei.html');

 repeat

   Application.ProcessMessages;

 until WebBrowser1.ReadyState >= READYSTATE_COMPLETE;

 if WebBrowser1.Document <> nil then

 (Webbrowser1.Document as IHTMLDocument2).ParentWindow.Focus;

end;