码迷,mamicode.com
首页 > Windows程序 > 详细

How to make TWebBrowser get focus in Delphi

时间:2014-10-14 19:04:09      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   io   os   ar   for   sp   div   

   
 

  Since TWebBrowser is inherited methods from TControl, you may think immediately to use the method ‘SetFocus‘ to make it get the focus. Unfortunately, it does not work. So we have to find out some way else to accomplish this task. I have found three ways to make it focused.

1. The first way need to write a function to get it.

  procedure TForm1.WebBrowserSetFocus;   begin    if WebBrowser1.Document nil then     with WebBrowser1.Application as IOleobject do      DoVerb(OLEIVERB_UIACTIVATE, nil, WebBrowser1, 0, Handle, GetClientRect);   end;

2. Another easy way to get it.

  if WebBrowser1.Document nil then    IHTMLWindow2(IHTMLDocument2(WebBrowser1.Document).ParentWindow).focus

3. The best way I found to get it.

  if WebBrowser1.Document nil then    IHTMLWindow4(WebBrowser1.Document).focus

Ok, when you need to determind if a webbrowser has the focus, use the following code:

  if IHTMLWindow4(WebBrowser1.Document).hasfocus then 

How to make TWebBrowser get focus in Delphi

标签:style   http   color   io   os   ar   for   sp   div   

原文地址:http://www.cnblogs.com/honeynm/p/4024678.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!