zoukankan      html  css  js  c++  java
  • How to make TWebBrowser get focus in Delphi

       
     

      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 

  • 相关阅读:
    函数参数
    字符编码
    本周内容
    int,float,str,list,dict,元组
    python 基础变量
    Python学习(小笔记一)
    🌐 网络管理
    📓 LVM相关
    📹 进程管理(二)
    🎬进程管理
  • 原文地址:https://www.cnblogs.com/honeynm/p/4024678.html
Copyright © 2011-2022 走看看