//--------------------------------------------------------------------------------
// HTMLView - This sample shows how to open HTM/HTML file with default browser.
// It uses ShellExecute Win32API function with 'open' parameter,which
// causes system to look through registry for a program, which is
// attached to HTM/HTML extension.
//-------------------------------------------------------------------------------
unit HTMLUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ShellAPI;
type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
Button1: TButton;
Button2: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1 : TForm1;
HTMLFile : Array[0..79] of Char;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
If OpenDialog1.Execute then
begin
// get name of selected file
StrPCopy(HTMLFile, OpenDialog1.FileName);
// allow user to open (i.e. view) it with browser
Button2.Enabled := True;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
// run ShellExecute function with 'open' paramemter
ShellExecute(Handle, 'open', HTMLFile, nil, nil, SW_SHOWNORMAL);
end;
end.
|