OnShowMessage

 

Part of IDocHostSHowUI. Called when the Window object needs to display a messagebox.

function TEmbeddedWB.ShowMessage(hwnd: THandle; lpstrText: POLESTR; lpstrCaption: POLESTR; dwType: longint; lpstrHelpFile: POLESTR;dwHelpContext: longint; var plResult: LRESULT):HRESULT;

 

Unfortunately this function is not called, when the webbrowser control is about to display one of Internet Explorers internal messageboxes. Neither is it called when a script-error message is displayed. It is only called when the window object is about to display a messagebox (alert or confirm).

hwnd
Handle to the owner window.
lpstrText
Text for the message box.
lpstrCaption
Caption for the message box.
dwType
Type flags (taken from the WINAPI Messagbox MB_xxxx constants).
lpstrHelpFile
Help file name.
dwHelpContext
Help context identifier.
plResult
Button clicked by user (taken from the WINAPI Messagebox IDxxx constants).
 
If Result:=S_OK all messages are disabled. Default is Result:=S_FALSE (show all messages).

In the following sample all messages are shown as normal, but the caption is changed from 'Microsoft Internet Explorer' to 'EmbeddedWB Messagebox':

 

function TForm1.EmbeddedWB1ShowMessage(hwnd: Cardinal; lpstrText, lpstrCaption: PWideChar; dwType: Integer; lpstrHelpFile: PWideChar; dwHelpContext: Integer; var plResult: Integer): HRESULT;
var
Text: string;
Caption: PChar;
begin
  Caption := 'EmbeddedWB Messagebox';
  text := lpstrText;
  plResult:=Windows.MessageBox(hWnd, Pchar(text), Caption,   dwType);
  Result := S_OK; 
end;

 

The next sample shows another useful way to use OnShowMessage:

Create a HTML-file:

<HTML><HEAD>
<TITLE>EmbeddedWB OnShowMessage Sample</TITLE>
<BODY>
Click the button to open Webbrowsers Pagesetup-dialog:
<P>
<FORM>
<INPUT type="Button" Value="PageSetup" OnClick="alert('EmbeddedWB:PageSetup')">
</FORM>
</BODY></HTML>

Add the following lines to OnShowMessage, and the pagesetup-dialog opens when you click the button.

function TForm1.EmbeddedWB1ShowMessage(hwnd: Cardinal; lpstrText, lpstrCaption: PWideChar; dwType: Integer; lpstrHelpFile: PWideChar; dwHelpContext: Integer; var plResult: Integer): HRESULT;
begin
 If lpstrText='EmbeddedWB:PageSetup'
     then begin
    
EmbeddedWb1.PageSetup; //Show Pagesetup-dialog
   
Result:=S_OK; //Don't show the messagebox
  
end
else
Result:=False; //Show all other messageboxes
end;