简体   繁体   English

TWebbrowser / TEmbeddedWb:隐藏所有消息框

[英]TWebbrowser / TEmbeddedWb : hide all messageboxes

I have an application that uses TEmbeddedWb to automate data scrapping tasks.我有一个使用 TEmbeddedWb 来自动执行数据抓取任务的应用程序。

Some web-sites show messages / popup boxes when my app navigates to it, and these makes the process slower.当我的应用程序导航到某些网站时,某些网站会显示消息/弹出框,这会使过程变慢。

I want to block any messagebox that TWebbrowser could show.我想阻止 TWebbrowser 可以显示的任何消息框。

I'm already setting the 'silent' property to true, and also setting the onshowmessage method as follow, but still the messageboxes are show.我已经将“silent”属性设置为 true,并且还如下设置了 onshowmessage 方法,但消息框仍然显示。 Any hints?有什么提示吗?

 function TForm1.webShowMessage(Sender: TObject; HWND: Cardinal; lpstrText,
 lpstrCaption: PWideChar; dwType: Integer; lpstrHelpFile: PWideChar; dwHelpContext: Integer;
 var plResult: Integer): HRESULT;
 begin
 plresult := S_OK;
 end;

I could achieve these task by making some changes on TEmbeddedWb source, specifically on the functionbelow : 我可以通过对TEmbeddedWb源代码,特别是下面的函数进行一些更改来完成这些任务:

 procedure TEmbeddedWB.HandleDialogBoxes(var AMsg: Messages.TMessage);

Here is the change : 这是更改:

 DlgClss := GetWinClass(PopHandle);
 WinClss := GetWinClass(Windows.GetParent(PopHandle));
 DlgCaption := GetWinText(PopHandle);
 if (DlgClss = 'Internet Explorer_TridentDlgFrame') or ((DlgClss = '#32770'))
   // comment here to make all windows be evaluated
   {and (WinClss <> 'TApplication') and
   (FindControl(Windows.GetParent(PopHandle)) = nil))}
   then
 begin
   if (WinClss = 'TApplication') or (FindControl(Windows.GetParent(PopHandle)) <> nil) then
     begin
     if pos('web browser',lowercase(DlgCaption)) = 0 then
       exit;
     end;

I just add this code Result:= S_OK;我只是添加了这段代码Result:= S_OK; on ShowMessage Event and no more popup message:在 ShowMessage 事件上,不再有弹出消息:

function TForm1.webShowMessage(Sender: TObject; HWND: Cardinal; lpstrText,
 lpstrCaption: PWideChar; dwType: Integer; lpstrHelpFile: PWideChar; dwHelpContext: Integer;
 var plResult: Integer): HRESULT;
 begin
 Result := S_OK;
 end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM