{$R 'res\resources.res'}

unit MainUnit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  OleCtrls, SHDocVw_TLB, BoxedAppSDK_Static, StdCtrls, Registry, ShellApi;

type
  TMainForm = class(TForm)
    WebBrowser1: TWebBrowser;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{$R *.DFM}

procedure TMainForm.FormCreate(Sender: TObject);
var
   v1, v2, v3, v4: OleVariant;
begin
   WebBrowser1.Navigate('file://C:\1.html', v1, v2, v3, v4);
end;

// It shows how to override some of Internet Explorer settings
function BoxedAppSDKHandler(Param: Pointer; RequestId: DWORD; pAdditionalInfo: Pointer): DWORD; stdcall;
var
   buf: Pointer;
begin
	if EnumBoxedAppSDK_RequestId__RegQueryValue = RequestId then
	begin
		if ((PBoxedAppSDK__RegQueryValue(pAdditionalInfo)^.m_Root = HKEY_CURRENT_USER) And 
		    (PBoxedAppSDK__RegQueryValue(pAdditionalInfo)^.m_szPath = 'Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders') And
		    (PBoxedAppSDK__RegQueryValue(pAdditionalInfo)^.m_szValue = 'Cookies'))
		Then
		begin
			buf := BoxedAppSDK_Alloc(256);

			lstrcpyW(PWideChar(buf), 'C:\!Cookies');

			PBoxedAppSDK__RegQueryValue(pAdditionalInfo)^.m_pData := buf;
			PBoxedAppSDK__RegQueryValue(pAdditionalInfo)^.m_dwSize := 256;
			PBoxedAppSDK__RegQueryValue(pAdditionalInfo)^.m_dwType := REG_SZ;

			PBoxedAppSDK__RegQueryValue(pAdditionalInfo)^.m_bHandled := 1;
		end;
	end;
end;

var
   Handle1, Handle2, Handle3: THandle;
   HandleStream: THandleStream;
   StringStream: TStringStream;
   ResourceStream: TResourceStream;
   ch: char;

initialization

   BoxedAppSDK_Init;

// It shows how to override some of Internet Explorer settings
// Uncomment the next line to see how it works
//   BoxedAppSDK_AddHandler(@BoxedAppSDKHandler, nil);

   Handle1 := BoxedAppSDK_CreateVirtualFile('c:\1.html', GENERIC_WRITE, FILE_SHARE_READ, nil, CREATE_NEW, 0, 0);
   HandleStream := THandleStream.Create(Handle1);
   StringStream := TStringStream.Create('');
   StringStream.WriteString('This page is loaded from a virtual file<br>This image is loaded from a virtual path too:<br><img src = "1.jpg" /><br>');
   StringStream.WriteString('<br>This flash movie is also loaded from a virtual file:<br><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"><param name = "src" value = "C:\1.swf"></object>');
   StringStream.WriteString('<br>Yes, both html file and picture are in the virtual file system created by <a href = "http://boxedapp.com/boxedappsdk/" target = "_blank">BoxedApp SDK</a> ');
   StringStream.WriteString('(<a href = "http://boxedapp.com/boxedappsdk/order.html" target = "_blank">Buy license</a>)<br>Here the Delphi code:<br>');
   StringStream.WriteString('<pre>');

   ResourceStream := TResourceStream.Create(0, 'HTML1', 'HTML');

   while ResourceStream.Read(ch, 1) > 0 do
   begin
        if ch = '<' then
        begin
             StringStream.WriteString('&lt;');
        end
        else if ch = '>' then
        begin
             StringStream.WriteString('&gt;');
        end
        else
                StringStream.Write(ch, 1);
   end;

   ResourceStream.Free;

   StringStream.WriteString('</pre>');

   StringStream.Position := 0;
   HandleStream.CopyFrom(StringStream, StringStream.Size);
   HandleStream.Free;
   StringStream.Free;
   CloseHandle(Handle1);

   Handle2 := BoxedAppSDK_CreateVirtualFile('c:\1.jpg', GENERIC_WRITE, FILE_SHARE_READ, nil, CREATE_NEW, 0, 0);
   HandleStream := THandleStream.Create(Handle2);
   ResourceStream := TResourceStream.Create(0, 'IMG1', 'IMG');
   HandleStream.CopyFrom(ResourceStream, ResourceStream.Size);
   HandleStream.Free;
   ResourceStream.Free;
   CloseHandle(Handle2);

   Handle3 := BoxedAppSDK_CreateVirtualFile('c:\1.swf', GENERIC_WRITE, FILE_SHARE_READ, nil, CREATE_NEW, 0, 0);
   HandleStream := THandleStream.Create(Handle3);
   ResourceStream := TResourceStream.Create(0, 'MOVIE1', 'MOVIE');
   HandleStream.CopyFrom(ResourceStream, ResourceStream.Size);
   HandleStream.Free;
   ResourceStream.Free;
   CloseHandle(Handle3);

finalization

   BoxedAppSDK_Exit;

end.
