判断剪贴板文件格式
在Delphi中,TMemo与写字板、Word等通过剪切板复制/粘贴后,往往会产生乱码,这是因为TMemo把文本都当作CF_TEXT格式处理的缘故。事实上,剪贴板中文字的格式有以下几种:CF_TEXT,CF_OEMTEXT,CF_UNICODETEXT等。
那么,要怎样才能判断剪贴板中内容的具体格式呢?答案就是使用GetPriorityClipboardFormat这个API函数。使用范例如下:
var
anFormats:array of Cardinal;
Format:Cardinal;
iCount:Integer;
I:Integer;
begin
Clipboard.Open;
iCount:=Clipboard.FormatCount;
SetLength(anFormats,iCount);
for I:=0 to iCount-1 do anFormats[I]:=Formats[I];
Format:=GetPriorityClipboardFormat(anFormats[0],iCount);
if Format=49161 then Format:=CF_UNICODETEXT;
CASE Format of
CF_TEXT: //对ansi格式文本处理
CF_OEMTEXT: //对ansi格式文本处理
CF_UNICODETEXT: // 对unicode格式文本处理
end;
end;
那么,要怎样才能判断剪贴板中内容的具体格式呢?答案就是使用GetPriorityClipboardFormat这个API函数。使用范例如下:
var
anFormats:array of Cardinal;
Format:Cardinal;
iCount:Integer;
I:Integer;
begin
Clipboard.Open;
iCount:=Clipboard.FormatCount;
SetLength(anFormats,iCount);
for I:=0 to iCount-1 do anFormats[I]:=Formats[I];
Format:=GetPriorityClipboardFormat(anFormats[0],iCount);
if Format=49161 then Format:=CF_UNICODETEXT;
CASE Format of
CF_TEXT: //对ansi格式文本处理
CF_OEMTEXT: //对ansi格式文本处理
CF_UNICODETEXT: // 对unicode格式文本处理
end;
end;

浙公网安备 33010602011771号