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