res协议可以使浏览器显示储存在资源中HTML
procedure TForm1.LoadHTMLResource;
var
Flags, TargetFrameName, PostData, Headers: OleVariant;
begin
WebBrowser1.Navigate('res://' + Application.ExeName + '/myhtml', Flags, TargetFrameName, PostData, Headers)
end;
资源文件
MYHTML 23 ".\html\myhtml.htm"
MOREHTML 23 ".\html\morehtml.htm"
用bcc32编译
{$R *.RES}
{$R HTML.RES}
---------------------------------------
如何用TWebBrowse控件或者IE打开网页文件?
参考:
Syntax:
res://sFile[/sType]/sID
Example:
res://mydll.dll/#2/#234
You can find it in Platform SDK documentation:
Web Development\Internet Development SDK\Pluggable Protocols\Predefined
Protocols\res
Web Site inside a Delphi EXE
---------------------------------------
http://delphi.about.com/library/weekly/aa061901a.htm
How to store Web-style content inside a Delphi application.
Many of you have asked how your application can be a container for any Web-style content, including HTML resources and pictures that are part of your project.
This articles will show you how HTML and associated files (pictures) can easily be included within a Delphi application. As a result, you simply have to distribute an EXE file that includes HTML pages, as it would do with icons and cursors.
Creating a HTML page
For the start we have to assemble a (simple) html page. Use your favorite HTML editor and create one page with one associated picture. I'll name mine aboutindex.htm.
Note that when you add a picture tag inside a htm page it looks something like:
<img src="/library/graphics/adp.gif" ...>
We have to alter the IMG tags so that the SRC attribute equals the name we are to give to a picture in a resource:
<img src="ABOUTDP" ...>
My HTML code looks like:
<HTML><HEAD><TITLE>HTML inside a Delphi exe</TITLE></HEAD><BODY>
This is a HTML Delphi resource test:<br>
<img src="/GIF/ABOUTDP" width=106 height=58 border=0 alt="">
</BODY></HTML>
Creating and compiling a resource file
Remember that to create a new resource script file, you have to:
1. Create a new text file in your projects directory.
2. Rename it to AHTMLDelphi.rc.
3. Write down the following two lines of text in the AHTMLDelphi.rc file.
DELPHIINDEX HTML "c:\Delphi\projects\aboutindex.htm"
ABOUTDP GIF "c:\library\graphics\adp.gif"
Note: the resource type "HTML" is RT_HTML, predefined as the resource type "23". This is the default resource type for the RES protocol.
In this way we have prepared one HTML page and one GIF picture to be included in the binary code of our EXE module.
The next step is to compile the .rc file. To compile the AHTMLDelphi.rc file to a .res file execute this command at the command prompt (in the projects directory):
BRCC32 AHTMLDelphi.RC
The final step is to add the following compiler directive to a unit in your project. RES file must be included in the program's build by adding a line like this:
{$R AHTMLDelphi.RES}
Displaying inside a Web browser
When you have the application's exe (let's call it: myhtmldelphi.exe) the HTML resource contained within can be accessed via the RES: protocol. Run Internet Explorer and, in the Address bar, type the following:
res://c:\myhtmldelphi.exe/RT_HTML/DELPHIINDEX
This should result in:
Put a TWebBrowser (in Delphi5, otherwise import the IE TWebBrowser ActiveX
control and use that) on your form. The code used to load the browser is:
procedure TForm1.Button1Click(Sender: TObject);
var
url: OleVariant;
begin
url := 'res://' + Application.ExeName + '/delphiindex';
WebBrowser1.Navigate2(url);
end;
You'll need OleCtrls, SHDocVw and MSHTML_TLB in your uses clause.
p.s.
"delphiindex" is the resource name from the article.
Hi,
I would just like to say that the delphi topic on about.com is extremely impressive!! Love the work :)
Anyway, what i found was if you followed the HTML resource tutorial you saved the resource file along the lines of "DELPHIINDEX HTML Drive:\Dir\Somefile.htm"
What i found was when i loaded the res file in Visual C++ is that the DELPHIINDEX alias is listed under the HTML "category"... so to load the file you would simply add /HTML/DELPHIINDEX to your resource request. The code i use is:
wbMain.Navigate('res://'+Application.EXEName+'/HTML/DELPHIINDEX');
res://C:\NewProg.exe/HTML/DELPHIINDEX
and it works like a charm.
---------------------------------------
Source:Brian Slack : Borland newsgroup
We use html extensively in our application "Agency Manager" you can see some
screen shots at http://www.agencymanager.co.uk/beta.asp
To get good quick code you will need
1. The rc.exe from a copy of Visual Studio, this allows you to build .rc
files with html files without naming (i.e. dot) problems which look like
this. If you cannot get rc.exe (not the Borland stuff) then you can find a
resource editor and add files as type 23 but this takes ages.
//////////////
am.css HTML "am.css"
agency-manager.gif HTML "agency-manager.gif"
logo.gif HTML "logo.gif"
about.html HTML "about.html"
backup.html HTML "backup.html"
backup-active.html HTML "backup-active.html"
backup-done.html HTML "backup-done.html"
activex.html HTML "activex.html"
////////////
2. We use the extended web browser from
http://www.euromind.com/iedelphi/index.html as it adds more functionality
that TWebBrowser although this isn't a requirement.
3. On the HTML page add
<input type="text" name="BackUpFile" size="72" value="c:\*.bak">
then read or write the value with
wbMain.OleObject.Document.All.Tags('Input').Item('BackUpFile').Value
and
<span id="TheTitle" name="TheTitle">Agency Manager Professional Login</span>
can be read or written with
wbMain.OleObject.Document.getElementById('TheTitle').innerHTML := 'Agency
Manager for rightmove';