就是如同在操作系统中点中文件后右键弹出菜单,可以“复制”、“剪切”文件到剪贴板?
网上看到的都是直接把一个文件复制到另一个目录下,我只想实现让用户“复制”、“剪切”,至于他最后到操作系统下是不是“粘贴”,不在程序里实现的那种效果?
网上看到的都是直接把一个文件复制到另一个目录下,我只想实现让用户“复制”、“剪切”,至于他最后到操作系统下是不是“粘贴”,不在程序里实现的那种效果?
解决方案 »
- *****脱掉裤衩使劲放*****
- [Error] File not found: 'dxBarStrs.res'
- 一个极奇怪的问题,恳请各位高手援手!百分,不够再给!
- 请教一个问题,运行后如何监视win2000中的程序运行?
- 手机同步软件pclink中那个从一张图中截取其中一部分的矩形框是如何做出来的
- 关于工具栏的问题?
- 如何对写字板操作,如对写字板中符合要求的某一行进行筛选等
- Delphi高手看过来。
- ---------->>>>>>>>>>>21世纪之惊人大发现:Delphi/BCB编译器之缺陷???
- 在ontimer事件里,能否结束timer本身?
- Delphi如何实现将“非常多的字符”写入注册表reg_binary类型的数据中?
- 关于VMT地址
参考
LPCTSTR lpNewFileName, // pointer to filename to copy to
BOOL bFailIfExists // flag for operation if file exists
);
HANDLE CreateFile( LPCTSTR lpFileName, // pointer to name of the file
DWORD dwDesiredAccess, // access (read-write) mode
DWORD dwShareMode, // share mode
LPSECURITY_ATTRIBUTES lpSecurityAttributes, // pointer to security attributes
DWORD dwCreationDistribution, // how to create
DWORD dwFlagsAndAttributes, // file attributes
HANDLE hTemplateFile // handle to file with attributes to copy
);
begin
SendMessage (ActiveControl.Handle, WM_Cut, 0, 0);
end;
procedure TForm1.Copy1Click(Sender: TObject);
begin
SendMessage (ActiveControl.Handle, WM_Copy, 0, 0);
end;procedure TForm1.Paste1Click(Sender: TObject);
begin
SendMessage (ActiveControl.Handle, WM_Paste, 0, 0);
end;如果你开发一个MDI应用程序,你需要保证信息发送到活动子窗口,使用: ActiveMDIChild.ActiveControl.Handle
UINT format, // clipboard format to retrieve
LPTSTR lpszFormatName, // address of buffer for name
int cchMaxCount // length of name string in characters
);
如果format=CF_HDROP就是文件了HANDLE SetClipboardData(
UINT uFormat, // clipboard format
HANDLE hMem // data handle
);Delphi定义了两个格式:CF_PICTURE和CF_COMPONENT.
用户可以定义自己的格式.不过因为Formats是WORD格式,所以系统中只能有
16种格式.打开ClipBrd单元,可以查到.
CF_PICTURE := RegisterClipboardFormat('Delphi Picture');
CF_COMPONENT := RegisterClipboardFormat('Delphi Component');
你添加:
CF_MYFILE := RegisterClipboardFormat(' My File Format');剪贴板操作:
打开;
清空;
SetFormatData(CF_TEXT) --->文件名;
SetFormatData(CF_MYFILE) --->文件内容
关闭;如果你只对文件名感兴趣,那只是一个文本格式.取出内容,用FileExists查询
是否存在即可.
registerClipboardFormat函数登记新的剪贴板格式
格式的值在OXC000和0XFFF范围
IsClipboardFormatAvailable函数判断剪贴板是否包含指定格式数据
格式可用返回非零值
windows是有定义:
可以用cf_Hdrop;uses shlobj,activex,clipbrd;procedure TForm1.Button1Click(Sender: TObject);
var
FE:TFormatEtc;
Medium: TStgMedium;
FileName:String;
dropfiles:PDropFiles;
pFile:PChar;
begin
FileName:='c:\1.bmp';
FE.cfFormat := CF_HDROP;
FE.dwAspect := DVASPECT_CONTENT;
FE.tymed := TYMED_HGLOBAL;
Medium.hGlobal := GlobalAlloc(GMEM_SHARE or GMEM_ZEROINIT, SizeOf(TDropFiles)+length(FileName)+1);
if Medium.hGlobal<>0 then begin
Medium.tymed := TYMED_HGLOBAL;
dropfiles := GlobalLock(Medium.hGlobal);
try
dropfiles^.pfiles := SizeOf(TDropFiles);
dropfiles^.fwide := False;
longint(pFile) := longint(dropfiles)+SizeOf(TDropFiles);
StrPCopy(pFile,FileName);
Inc(pFile, Length(FileName)+1);
pFile^ := #0;
finally
GlobalUnlock(Medium.hGlobal);
end;
Clipboard.SetAsHandle(CF_HDROP,Medium.hGlobal);
end;
end;
上面这个例子把filename这个文件放在了clipboard上