How to create a HTML dialog using Delphi

'

ShowHTMLDialog function

The ShowHTMLDialog function creates a modal dialog box that displays HTML found at a specified URL.

Using a HTML dialog ovver a standard windows dialog gives you much more flexibility with what you can display, i.e. anything you find on a web page.

To use ShowHTMLDialog, which is implemented in Mshtml.dll, you need to dynamically load and call this function by using the LoadLibrary and GetProcAddress functions.

unit psvHTMLDialog;

interface

uses
  Windows, SysUtils, Classes, ActiveX, URLMon;

procedure DisplayHTMLDialog(AMessage : string;
              Resizable : boolean=false;
              AHeight : integer = 100;
              AWidth  : integer = 100);

implementation

type
  TShowHTMLDialog = function(const hwndParent : HWND; const pmk : IMoniker;
      const pvarArgIn : Variant; const pchOptions : POleStr;
      var pvarArgOut : Variant ):HResult; stdcall;

procedure DisplayHTMLDialog(AMessage : string;
              Resizable : boolean=false;
              AHeight : integer = 100;
              AWidth  : integer = 100);

var
 URLStr : POleStr;
 pmk : IMoniker;
 InParam  : Variant;
 OutParam : Variant;
 Features : PWideChar;
 LibHandle : THandle;
 ShowHTMLDialog:TShowHTMLDialog;
 AParams : Widestring;

begin
  LibHandle := LoadLibrary('MSHTML.DLL');

  if LibHandle = 0 then
    Exit;

  @ShowHTMLDialog:=GetProcAddress(LibHandle,'ShowHTMLDialog');

  if not Assigned(ShowHTMLDialog) then
   Exit;

  URLStr:=StringToOleStr(AMessage);
  CreateURLMoniker(nil, URLStr,pmk);
  SysFreeString(URLStr);

  TVarData(InParam).VType := varOleStr;
  TVarData(InParam).VOleStr:=StringToOleStr('');

  if Resizable then
   AParams := 'resizable:yes;'
    else
      AParams := '';

  AParams := AParams + Format('dialogHeight:%d pt;',[AHeight]);

  AParams := AParams + Format('dialogWidth:%d pt;',[AWidth]);

  Features := PWideChar(AParams);
  ShowHTMLDialog(0, pmk, InParam, Features, OutParam);
  FreeLibrary(LibHandle);
end;

end.

More information about ShowHTMLDialog function you can find here

This tutorial was kindly provided by serge perevoznyk


Google
Web www.Delphi-Central.com
Delphi Central - Delphi Programming Tutorials, Hints and Tips