zoukankan      html  css  js  c++  java
  • Delphi中用Webbrowser加载百度地图滚轮失效(ApplicationEvents里使用IsChild提前判断是哪个控件的消息)

    在Delphi中使用Webbrowser加载百度地图时,点击了其它界面,再回到百度地图中,即使点击了鼠标,再用滚轮也不能缩
    放地图,除非点地图里面的自带的控件,之后才能缩放,原因是因为其它窗体控件获得焦点后没还回给Webbrowser.
    目前的解决办法是在窗体上拖一个ApplicationEvents,在他的OnMessage事件中写入如下代码:

    if IsChild(WebBrowser1.Handle, Msg.Hwnd) then begin // 使用API进行判断,第一个参数是父窗口,第二个参数是测试窗口
        if ((Msg.Message = WM_LBUTTONDOWN) or (Msg.Message = WM_LBUTTONUP))  then
        begin
          Webbrowser1.SetFocus;
         end;
    end;
    
    procedure SetFocusToDoc(Webbrowser:TWebBrowser);
    begin
      if Webbrowser.Document <> nil then
      begin
        if IHTMLDocument2(WebBrowser1.Document).activeElement<>IHTMLDocument2(WebBrowser1.Document).body 
    
    then
        begin
          with Webbrowser.Application as IOleobject do
          DoVerb(OLEIVERB_UIACTIVATE, nil, Webbrowser, 0, Handle, GetClientRect);
        end;
      end;
    
    //  if Webbrowser.Document <> nil then
    //  begin
    //    with Webbrowser.Application as IOleobject do         //引用ActivitX
    //      DoVerb(OLEIVERB_UIACTIVATE, nil, Webbrowser, 0, Handle, GetClientRect);
    //  end;
    
    //  if WebBrowser1.Document <> nil then
    //  begin
    //    if not IHTMLDocument4(WebBrowser1.Document).hasFocus then   //引用MSHTML单元
    //      IHTMLWindow2(IHTMLDocument2(WebBrowser1.Document).ParentWindow).focus;
    //  end;
    //  if WebBrowser1.Document <> nil then
    //  begin
    //    if not IHTMLDocument4(WebBrowser1.Document).hasFocus then
    //      IHTMLDocument4(WebBrowser1.Document).focus;
    //  end;
    end;

    参考:http://m.blog.csdn.net/blog/fghydx/46122569

  • 相关阅读:
    HDU 5313 bitset优化背包
    bzoj 2595 斯坦纳树
    COJ 1287 求匹配串在模式串中出现的次数
    HDU 5381 The sum of gcd
    POJ 1739
    HDU 3377 插头dp
    HDU 1693 二进制表示的简单插头dp
    HDU 5353
    URAL 1519 基础插头DP
    UVA 10294 等价类计数
  • 原文地址:https://www.cnblogs.com/findumars/p/4739779.html
Copyright © 2011-2022 走看看