|
|
http://blog.sina.com.cn/u/4c38d61001000908
翻译的不好,大家多包含!
怎样使用HtmlLite
Introduction
简介
There is an undocumented DLL component used in the Installer of VS.NET that allows you to render HTML for your application, and all from a simple window class.
在VS.NET的安装包里有一个没有文档说明的DLL组件。它可以让你在自己的应用程序中渲染HTML,而且所有的一切只需要一个简单的WINDOW类。
The control would allow you to render, say, a richly formatted report in your application and display it to the user.
这个控件可以使你在应用程序中给你的用户渲染或者展示一个丰富格式的报告。
The library is located at \Program Files\Microsoft Visual Studio .NET 2003\Setup\Visual Studio .NET Enterprise Architect 2003 - English with the filename: htmllite.dll (136 Kb).
这个库的在你的安装目录下,名字叫做HTMLLITE.DLL(136KB)
You must copy the DLL from here and place it with the other source and executable files extracted from the ZIP archive. The DLL has not been included in the ZIP for redistribution reasons.
你必须把这个DLL文件从这个目录中拷贝到ZIP包解压缩的的目录下。因为一些再发布的原因,这个DLL并没有包含再ZIP中。
How to use HTMLLITE
怎样使用
The library is very simple to use. You need to first call a sub aliased:
这个库使用起来很简单。你首先需要调用这个函数
RegisterHtmlLiteClass
... and this will make ready the window class for use in your application (similar to calling InitCommonControls).
然后就可以再你的应用程序中使用这个WINDOW类了(有点类似调用InitCommonControls)
The control can then be created with CreateWindowEx like any other window:
这个控件可以像其他窗口一样用CreateWindowEx创建
CreateWindowEx(WS_EX_CONTROLPARENT, "HTMLLITE",
"TODO: HTML goes here...", WS_CHILD | WS_VISIBLE,
10, 10, 500, 500, hWnd, 0, 0, 0);
The control is then ready and visible on your parent window.
这时空间就就绪了并在你的父窗口中显示了。
Under the hood
进一步了解
A few weeks ago when I first started tinkering with HTMLLITE, I spent a few hours on that ancient utility called Spy++ to see what messages HTMLLITE was using...
几周前当我开始补充HTMLLITE的时候,我花了几个小时用一种古老的叫SPY++的工具来观察HTMLLITE使用了什么消息。
I found that HTMLLITE works very similar to the standard Windows Common Controls, such as ListViews. It makes use of WM_NOTIFY, to send notifications to your application about mouse clicks, moves, and others.
我发现HTML的工作原理和WINDOWS标准控件非常类似,比如LISTVIEWS。它利用WM_NOTIFY来通知你的程序鼠标点击、移动或其他的一些东西。
The lParam of the WM_NOTIFY contains a pointer to a NMHDR structure, and like any other control, the members are no different... hwndFrom, idFrom and code.
WM_NOTIFY中的LPARM包含着一个NMHDR结构的指针,而且像其他控件一样,成员变量没什么不同,像HWNDFROM,IDFROM和CODE。
'Code' was the important one, so I set about learning what each code meant and came up with the following:
“CODE”是非常重要的一个,所以我开始着手了解下面每个CODE的意义和来源。
//HTMLLITE Notify Codes
//A link has been clicked either via
//... the Mouse or Spacebar key
//一个连接通过鼠标或空白键被点击
#define HTMLLITE_CODE_LEFTCLICK 1000
//A link has received focus due to
//... the Tab Cycle, or Keyboard Arrow Keys
//一个连接通过TAB循环或键盘方向键得到焦点
#define HTMLLITE_CODE_TABCYCLE 1001
//A link has been right-clicked, and already had focus
//一个连接被右击,而且已经得到焦点
#define HTMLLITE_CODE_RIGHTCLICK 1003
//Mouse is over a link
//鼠标在连接上
#define HTMLLITE_CODE_MOUSEOVER 1004
//Mouse is hovering a link (~1 second = hover)
//鼠标覆盖了一个连接(1秒=覆盖)
#define HTMLLITE_CODE_MOUSEHOVER 1005
//Mouse has left a link's rectangle
//鼠标离开连接的矩形区
#define HTMLLITE_CODE_MOUSEEXIT 1006
Simple.
实例
The control also uses its window text/caption as the source for the HTML. So if you want to change the HTML content after it has been created, simply send a WM_SETTEXT message containing the new HTML.
这个控件也使用窗口的TEXT或CAPTION作为HTML来源。所以如果你想创建后更新HTML内容,简单的发送一个包含新的HTML内容的WM_SETTEXT消息就可以了。
Next step was to find a way to determine which hyperlink had been clicked in any given HTMLLITE control instance. As pot luck had it, a couple of days ago I stumbled upon the MSDN pages about the SYSLINK control (new with Common Controls v6). The SYSLINK control is similar to HTMLLITE except it can only render simple <a href> style markup. I tried out the notification structure of the SYSLINK control to see if HTMLLITE used anything similar.. and.. hut-damn, it did:
下一步是要找到一个方法来判断在HTML控件实例中哪个超连接被点击了。很幸运,几天前我正在钻研MSDN中有关一个叫SYSLINK控件(Common Controls v6中新添加的)。这个SYSLINK控件除了仅能渲染<a href>符号,它非常像HTMLLITE。我尝试了SYSLINK控件的通知结构,看它和HTMLLITE中所使用的有什么相似的地方,天啊(自己编的词,原文是在不知道是什么)就是这种结构。
typedef struct tagNMLINK { //nm structure for SYSLINK
NMHDR hdr;
LITEM item;
} NMLINK, *PNMLINK;
After about half an hour I had reversed the entire HTMLLITE NM structure...
大于过了半个小时,我修正了全部的HTMLLITE NM结构……
The most important member is linkid. This member contains the value of the parameter linkid used in a <a href="..."> style markup. So if you have more than one link in a HTMLLITE control, simply add linkid parameters to your <a>'s and they will be filled into the following structure's similarly named member.
最重要的成员变量是LINKID,这个成员包含了在<a href="...">符号中LINKID的参数值。所以,如果你有多个HTMLLITE控件,简单的在你<a>中添加LINKID参数,那么他们就会出现在LINKID变量中。
Collapse
综合
typedef struct NMHTMLLITE {
//The Window Handle (hWnd) of the HTMLLITE control
//... sending you this message
//HTMLLITE控件的窗口句柄.
DWORD hwndFrom;
//If your HTMLLITE control is on a dialog, this member
//... contains its Dialog ID.
//如果你的HTMLLITE控件在一个对话框中,这个变量包含了它的对话框ID
DWORD idFrom;
//As defined below. As an example, this member will
//... equal HTMLLITE_CODE_LEFTCLICK when a Link has
//... been Left-clicked.
//上面定义了,例如如果这个参数等于HTMLLITE_CODE_LEFTCLICK,那么就是一个连接//被点击了
DWORD code;
//When you create a Link with <a href="..." linkid=xxx>
//... the linkid parameter is filled in this member.
//.. allowing you to know which link has been clicked
//... in your HTMLLITE control and then perform a specific action.
//当你用LINKID创建了一个连接时如:<a href="..." linkid=xxx>,那么连接参数就会填充到//这个变量中,这个润许你了解哪个连接被点击了。这时你就可以执行一些特殊的动作了
DWORD linkid;
//This is a RECT structure which contains the coord's and
//... dimensions of the Link concerned.
//这是一个RECT结构,包含着所关注的LINK的坐标。
RECT linkrc;
} NMHTMLLITE, *LPNMHTMLLITE;
Easy peasy.
简单,相当简单
Extent of HTML implementation?
HTML的扩展引入了吗?
Well to be honest, I am unsure. I know it seems to use CSS-alike HTML, but it is not really W3C quality 
说实话,我也不确定。我只知道它好像时使用了CSS似的HTML,但并不是真正的W3C标准
Here are a few pieces of markup that MS .NET apps use, so you'll know how much I know:
这里有一些在MS.NET应用程序中使用的代码片段,所以你就知道了我知道多少了。
<p highlight=#003399 padding-left=20 padding-top=14 padding-bottom=14>
<font face="arial" size=12pt color="white"><b>Microsoft</b></font>
<br><font face="arial" size=22pt color="white">Visual Studio .NET Setup
</font></p>
<p align="right"><a color=#3F4F7F HOVER-COLOR=#C3120C linkid=211>
<b>Text goes here</b></a></p>
Earlier today I checked if Tables would work - they didn't.
今天的早些时候我检查了下表格很能用-他们不能用!
全文完
原文:http://www.codeproject.com/miscctrl/htmllite.asp
PS:最近微软不知道发什么神经,好像是要搞LITE包似的,刚发布了一个XMLLITE,这又有一个HTMLLITE等着发布,唉……
|
|