delphi 读取剪粘板内的html格式数据
根据剪贴板的原理,在获取剪贴板内容之前,必须指定要获取内容的格式。由于剪贴板中的数据可能存在多种格式,所以有必要对剪贴板的格式类型先做一些了解。W写下了以下的测试代码:
procedure TForm1.Button3Click(Sender: TObject);
var
i: integer;
Buffer: PChar;
s: string;
begin
Memo1.Lines.Clear; //增加了一个Memo控件来跟踪数据
with TClipboard.Create do //利用TClipboard追踪剪贴板
begin
GetMem(Buffer, 20);
for i:=0 to FormatCount - 1 do
begin
GetClipboardFormatName(Formats[i], Buffer, 20);
s := StrPas(Buffer);
Memo1.Lines.Add(Format('%s:%d', [s, Formats[i]]));
end;
FreeMem(Buffer);
Free;
end;
end;
点击Button3,在Memo1文本框中显示出以下的内容:
DataObject:49161
Object Descriptor:49166
Rich Text Format:49312
HTML Format:49394
HTML Format:14
HTML Format:3
PNG:49672
GIF:49536
JFIF:49538
……
很明显,第4行的“HTML Format:49394”应该就是HTML编辑器真正需要的格式。由于“HTML Format”并不是剪贴板默认支持的格式,所以W需要使用API函数RegisterClipboardFormat先进行注册。
procedure TForm1.Button4Click(Sender: TObject);
var
s: string;
hMem: DWORD;
CF_HTML: DWORD; // 声明一个CF_HTML剪贴板格式
txtPtr: PChar;
begin
CF_HTML := RegisterClipboardFormat('HTML Format'); //注册HTML Format格式
with TClipboard.Create do
begin
hMem := GetAsHandle(CF_HTML);
txtPtr := GlobalLock(hMem);
s := StrPas(txtPtr);
GlobalUnlock(hMem);
Memo1.Lines.Add(UF8Decode(s));
Free;
end;
end;
单击Button4就可以在memo1中看到真定html格式文本。
相关文档:
\webapps\test 路径下ThreeParams.html:
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>TreeParams</title>
</head>
<body>
<form method="get" onsubmit="return true" name="form1" action="/test/tp">
<tabl ......
匹配中文字符的正则表达式: [u4e00-u9fa5]
评注:匹配中文还真是个头疼的事,有了这个表达式就好办了
匹配双字节字符(包括汉字在内):[^x00-xff]
评注:可以用来计算字符串的长度(一个双字节字符长度计2,ASCII字符计1)
匹配空白行的正则表达式:ns* ......
aspx 生成HTML 静态页 :http://www.cnblogs.com/ejiyuan/archive/2007/11/09/954325.html
cs 页:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
u ......
1、先用Const 定义一个常量,例如 const WM_MyMessage=WM_USER+$200;
2、在要实现的unit中定义一个私有方法
procedure doMyMessage(var msg:TMessage);message WM_MyMessage;
3、实现这个私有方法
procedure TForm1.doMyMessage(var msg:TMessage);
begin
//
if msg. ......