十年

  :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

判断剪贴板文件格式

  在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;
posted on 2005-01-17 21:05  留不住的时光  阅读(1011)  评论(0)    收藏  举报