如何获取Windows当前剪切板内容的数据结构,以及如何向剪切板写数据。望解答! 如何获取Windows当前剪切板内容的数据及其结构,以及如何向剪切板写数据。问题解决马上给分。 谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 转贴:uses ShlObj, ClipBrd; procedure CopyFilesToClipboard(FileList: string); var DropFiles: PDropFiles; hGlobal: THandle; iLen: Integer; begin iLen := Length(FileList) + 2; FileList := FileList + #0#0; hGlobal := GlobalAlloc(GMEM_SHARE or GMEM_MOVEABLE or GMEM_ZEROINIT, SizeOf(TDropFiles) + iLen); if (hGlobal = 0) then raise Exception.Create('Could not allocate memory.'); begin DropFiles := GlobalLock(hGlobal); DropFiles^.pFiles := SizeOf(TDropFiles); Move(FileList[1], (PChar(DropFiles) + SizeOf(TDropFiles))^, iLen); GlobalUnlock(hGlobal); Clipboard.SetAsHandle(CF_HDROP, hGlobal); end; end; // Example: procedure TForm1.Button1Click(Sender: TObject); begin CopyFilesToClipboard('C:\Bootlog.Txt'#0'C:\AutoExec.Bat'); end; { Separate the files with a #0. } ********************************沈前卫的回答:unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,ShlObj;type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);const FileName:string='c:\netlog.txt';var DataHandle: THandle; DataPointer: PDROPFILES;begin DataHandle := GlobalAlloc(GMEM_DDESHARE or GMEM_MOVEABLE,SizeOf(DROPFILES)+2+Length(FileName)); DataPointer := PDROPFILES(GlobalLock(DataHandle)); FillChar(DataPointer^,SizeOf(DROPFILES)+2+Length(FileName),0); DataPointer.pFiles:=SizeOf(DROPFILES); DataPointer.pt:=Point(0,0); DataPointer.fNC:=False; DataPointer.fWide:=False; Move(FileName[1],Pointer(Integer(DataPointer)+SizeOf(DROPFILES))^,Length(FileName)); GlobalUnlock(DataHandle); OpenClipboard(Form1.Handle); EmptyClipboard; SetClipboardData(CF_HDROP, DataHandle); CloseClipboard;end;end.***************************在Windows的资源管理器中,选中一个或多个文件,在文件上单击鼠标右键,在弹出菜单中选复制。再切换到另外的目录,单击鼠标右键,点粘贴。就这样执行了一次文件的拷贝操作,那么Windows在拷贝过程中执行了什么操作,是否将整个文件拷贝到剪贴板上了呢?当然没有。实际上,Windows只是将一个文件结构拷贝到了剪贴版,这个结构如下: tDropFile+文件1文件名+vbNullChar+文件2文件名+vbNullChar……+文件N文件名+vbNullChar,其中tDropFile是一个DROPFILES结构,这个结构在Windows API中有定义。在粘贴文件时,利用API函数 DragQueryFile 就可以获得拷贝到剪贴板的文件全路径名,然后就可以根据获得的文件名执行文件拷贝函数,实现对文件的粘贴操作。那么如何从剪切板或取复制的文件内容呢?请参看下面的例子:/// Author:Peter Belowuses clipbrd, shellapi; {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var f: THandle; buffer: array [0..MAX_PATH] of Char; i, numFiles: Integer; begin if not Clipboard.HasFormat(CF_HDROP) then Exit; Clipboard.Open; try f := Clipboard.GetAsHandle(CF_HDROP); if f <> 0 then begin numFiles := DragQueryFile(f, $FFFFFFFF, nil, 0); memo1.Clear; for i := 0 to numfiles - 1 do begin buffer[0] := #0; DragQueryFile(f, i, buffer, SizeOf(buffer)); memo1.Lines.Add(buffer); end; end; finally Clipboard.Close; end; end; 希望对你有用 如何正确拼QUERY的SQL语句串,确保引号匹配正确 indy中的IdTcpServer控件如何绑定ip地址? 急问! 增加删除表的内容 关于数据库记录的问题!!! AnimateWindow问题 dbgrid 的問題還請解決 急 怎么对TBGrid中显示的数据库信息直接修改 是不是用ADO连接数据库,就不能显示货币符号了? 任意封闭图形填充的更好算法??? 我要去北京!!1—_! 怎么用ListView1控件时,显示大的图标? 如何做一个象FoxMail和Msn Message 中有新邮件的提示窗口
ShlObj, ClipBrd; procedure CopyFilesToClipboard(FileList: string);
var
DropFiles: PDropFiles;
hGlobal: THandle;
iLen: Integer;
begin
iLen := Length(FileList) + 2;
FileList := FileList + #0#0;
hGlobal := GlobalAlloc(GMEM_SHARE or GMEM_MOVEABLE or GMEM_ZEROINIT,
SizeOf(TDropFiles) + iLen);
if (hGlobal = 0) then raise Exception.Create('Could not allocate memory.');
begin
DropFiles := GlobalLock(hGlobal);
DropFiles^.pFiles := SizeOf(TDropFiles);
Move(FileList[1], (PChar(DropFiles) + SizeOf(TDropFiles))^, iLen);
GlobalUnlock(hGlobal);
Clipboard.SetAsHandle(CF_HDROP, hGlobal);
end;
end; // Example: procedure TForm1.Button1Click(Sender: TObject);
begin
CopyFilesToClipboard('C:\Bootlog.Txt'#0'C:\AutoExec.Bat');
end; {
Separate the files with a #0.
} ********************************
沈前卫的回答:unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,ShlObj;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
const FileName:string='c:\netlog.txt';
var
DataHandle: THandle;
DataPointer: PDROPFILES;
begin
DataHandle := GlobalAlloc(GMEM_DDESHARE or GMEM_MOVEABLE,SizeOf(DROPFILES)+2+Length(FileName));
DataPointer := PDROPFILES(GlobalLock(DataHandle));
FillChar(DataPointer^,SizeOf(DROPFILES)+2+Length(FileName),0); DataPointer.pFiles:=SizeOf(DROPFILES);
DataPointer.pt:=Point(0,0);
DataPointer.fNC:=False;
DataPointer.fWide:=False;
Move(FileName[1],Pointer(Integer(DataPointer)+SizeOf(DROPFILES))^,Length(FileName));
GlobalUnlock(DataHandle);
OpenClipboard(Form1.Handle);
EmptyClipboard;
SetClipboardData(CF_HDROP, DataHandle);
CloseClipboard;
end;end.
***************************
在Windows的资源管理器中,选中一个或多个文件,在文件上单击鼠标右键,在弹出菜单中选复制。再切换到另外的目录,单击鼠标右键,点粘贴。就这样执行了一次文件的拷贝操作,那么Windows在拷贝过程中执行了什么操作,是否将整个文件拷贝到剪贴板上了呢?当然没有。实际上,Windows只是将一个文件结构拷贝到了剪贴版,这个结构如下:
tDropFile+文件1文件名+vbNullChar+文件2文件名+vbNullChar……+文件N文件名+vbNullChar,其中tDropFile是一个DROPFILES结构,这个结构在Windows API中有定义。在粘贴文件时,利用API函数 DragQueryFile 就可以获得拷贝到剪贴板的文件全路径名,然后就可以根据获得的文件名执行文件拷贝函数,实现对文件的粘贴操作。那么如何从剪切板或取复制的文件内容呢?请参看下面的例子:
/// Author:Peter Below
uses
clipbrd, shellapi; {$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
f: THandle;
buffer: array [0..MAX_PATH] of Char;
i, numFiles: Integer;
begin
if not Clipboard.HasFormat(CF_HDROP) then Exit;
Clipboard.Open;
try
f := Clipboard.GetAsHandle(CF_HDROP);
if f <> 0 then
begin
numFiles := DragQueryFile(f, $FFFFFFFF, nil, 0);
memo1.Clear;
for i := 0 to numfiles - 1 do
begin
buffer[0] := #0;
DragQueryFile(f, i, buffer, SizeOf(buffer));
memo1.Lines.Add(buffer);
end;
end;
finally
Clipboard.Close;
end;
end;
希望对你有用