TWebbrowser / TEmbeddedWb : hide all messageboxes

513 views Asked by At

I have an application that uses TEmbeddedWb to automate data scrapping tasks.

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.

I'm already setting the 'silent' property to true, and also setting the onshowmessage method as follow, but still the messageboxes are show. 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;
2

There are 2 answers

0
delphirules On

I could achieve these task by making some changes on TEmbeddedWb source, specifically on the functionbelow :

 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;
0
Anthoner Monzon On

I just add this code Result := S_OK; on ShowMessage Event and no more popup message:

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;