The WebBrowser
control itself does not provide the possibility to block these dialogs, so Silent
does not help. I cannot provide a reference right now, but I'm sure I have read it from MSDN somewhere.
Fortunately, you can observe Windows messages and block these dialogs as you want. Here is a famous component TEmbeddedWB
that implements all you need as a VCL. If you think it is too huge, you can extract related code into your project.
procedure TEmbeddedWB.FormWndProc(var AMsg: Messages.TMessage);
begin
if AMsg.Msg = WM_ACTIVATE then
begin
HandleDialogBoxes(AMsg);
end;
FOldWindowProc(AMsg);
end;
procedure TEmbeddedWB.HandleDialogBoxes(var AMsg: Messages.TMessage);
var
PopHandle: Integer;
DlgCaption, DlgClss: string;
Msg: TWMActivate;
WI: TWindowInfo;
begin
Msg := TWMActivate(AMsg);
if Msg.Active = 0 then
begin
PopHandle := Msg.ActiveWindow;
FillChar(WI, SizeOf(WI), 0);
if PopHandle <> 0 then
begin
WI.dwStyle := Abs(GetWindowLong(PopHandle, GWL_STYLE));
WI.dwExStyle := Abs(GetWindowLong(PopHandle, GWL_EXSTYLE));
end;
DlgClss := GetWinClass(PopHandle);
if (DlgClss = 'Internet Explorer_TridentDlgFrame') or ((DlgClss = '#32770') and
((GetWinClass(Windows.GetParent(PopHandle)) <> 'TApplication') and
(FindControl(Windows.GetParent(PopHandle)) = nil))) then
begin
DlgCaption := GetWinText(PopHandle);
if (PopHandle <> 0) and Assigned(FOnShowDialog) then
FOnShowDialog(Self, PopHandle, WI.dwExStyle, DlgCaption, FDialogBoxes.FNewCaption, FDialogBoxes.FDisableAll);
if FDialogBoxes.FDisableAll then
SendMessage(PopHandle, WM_CLOSE, 0, 0);
if FDialogBoxes.FReplaceIcon then
SendMessage(PopHandle, WM_SETICON, ICON_SMALL, Forms.Application.Icon.Handle);
if FDialogBoxes.FReplaceCaption then
begin
DlgCaption := StringReplace(DlgCaption, 'Microsoft ', '', []);
DlgCaption := StringReplace(DlgCaption, 'Internet Explorer', FDialogBoxes.FNewCaption, []);
SetWindowText(PopHandle, PChar(DlgCaption));
end;
if FDisableErrors.FScriptErrorsSuppressed then
begin
if (AnsiPos('SCRIPT', AnsiUpperCase(DlgCaption)) <> 0) then
begin
PostMessage(PopHandle, WM_LBUTTONDOWN, 0, 0);
PostMessage(PopHandle, WM_LBUTTONUP, 0, 0);
SendMessage(PopHandle, WM_CLOSE, 0, 0);
Forms.Application.ProcessMessages;
Exit;
end;
if (AnsiPos('ERROR', AnsiUpperCase(DlgCaption)) <> 0) or (WI.dwExStyle = 4260097) then
begin
DestroyWindow(PopHandle);
Exit;
end;
end;
if FPrintOptions.FEnabled then
begin
bPrintOptionsEnable := True;
if bInvokingPageSetup then
begin
bInvokingPageSetup := False;
if PrintingWithOptions then
begin
SetWindowPos(0, 0, -4400, 0, 0, 0, 0); //SetWindowPos(Wnd, 0, -600, 0, 0, 0, 0);
PrintingWithOptions := False;
end;
if FPrintOptions.FOrientation = poPortrait then
SendDlgItemMessage(PopHandle, $0420, BM_CLICK, 0, 0)
else
SendDlgItemMessage(PopHandle, $0421, BM_CLICK, 0, 0);
SetDlgItemText(PopHandle, $1FD3, PChar(FPrintOptions.FHeader));
SetDlgItemText(PopHandle, $1FD5, PChar(FPrintOptions.FFooter));
SetDlgItemText(PopHandle, $0483, PChar(PrintMarginStr(FPrintOptions.FMargins.FLeft)));
SetDlgItemText(PopHandle, $0484, PChar(PrintMarginStr(FPrintOptions.FMargins.FTop)));
SetDlgItemText(PopHandle, $0485, PChar(PrintMarginStr(FPrintOptions.FMargins.FRight)));
SetDlgItemText(PopHandle, $0486, PChar(PrintMarginStr(FPrintOptions.FMargins.FBottom)));
if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion > 4) then
PostMessage(FindWindowEx(PopHandle, 0, 'Button', nil), BM_CLICK, 0, 0) //Win2000
else
SendDlgItemMessage(PopHandle, 1, BM_CLICK, 0, 0);
end;
end;
end;
end;
end;