Delphi中用Webbrowser加载百度地图滚轮失效

在Delphi中使用


Webbrowser加载百度地图时,点击了其它界面,再回到百度地图中,即使点击了鼠标,再用滚轮也不能缩放地图,除非点地图里面的自带的控件,之后才能缩放,

原因是因为其它窗体控件获得焦点后没还回给Webbrowser.

目前的解决办法是在窗体上拖一个ApplicationEvents,在他的OnMessage事件中写入如下代码

if IsChild(WebBrowser1.Handle, Msg.Hwnd) then begin
    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;



猜你喜欢

转载自blog.csdn.net/fghydx/article/details/46122569