比如在一个窗体中有一个ListView,里面填充了硬盘中某个盘符下的文件和文件夹名。如果用户选中其中一项并按"Ctrl + C",然后在Windows其它地方按"Ctrl + V",那么这个程序就会把它复制过去。如果用户在Windows其它地方按"Ctrl + C"复制了一个文件,并在这个窗体上按了"Ctrl + V",那么程序就会在这个ListView中增加一项被复制的文件名。不知大家以前做过类似的工具没有,我想请问大家一下这个问题的实现思路,具体就是如何得知Windows复制过来的文件名?以及向Windows其它地方复制时,如何知道用户按"Ctrl + V"时所在的路径?谢谢!
解决方案 »
- 请各位大哥,给我调式这两个过程,马上揭贴,谢谢!
- 如何在delphi中设置Excel单元格顶对齐?
- 我想将数据库的连接做成动态连接库!
- 结算利润的问题,帮忙帮忙呀!sql语句如何写?
- 在d6中, toolbar 中toolbutton 的menuitem屬性與 mainmenu 連接過後, 為什麼mainmenu還會顯示在form上呀!
- 在过程或函数内部创建的对像,的生存期?
- 高手请进!
- 源码出售,VCL制作,内含Demo演示
- 各们,我在delphi6+ado+sqlserver2000开发了图书馆系统,但在客户端安装成功(mdac2.6及DCOM98),但不能连接数据库,望大家告诉小弟怎样写ado连接字符串才是最正确的。
- 如何把颜色转换成相对应的整数?比如把CLRED转换成一个整数。
- 内存泄露--------用checkmem.pas的单元生成了CheckMemory.Log后,怎么样查代码
- Fastreport 指定印表機
http://cache.baidu.com/c?word=delphi%2Cdragqueryfile&url=http%3A//www%2Eyesky%2Ecom/20000701/89833%2Eshtml&b=0&a=6&user=baidu 里面的例子.我现在觉得困难的是键盘或鼠标来实现复制粘帖,剪贴板可能不行,复制文本有用,复制文件还是个问题.
TCopyHook = class(TComObject, ICopyHook)
protected
function CopyCallback(Wnd: HWND; wFunc, wFlags: UINT; pszSrcFile: PAnsiChar;
dwSrcAttribs: DWORD; pszDestFile: PAnsiChar; dwDestAttribs: DWORD): UINT; stdcall;
end; TCopyHookFactory = class(TComObjectFactory)
protected
function GetProgID: string; override;
procedure ApproveShellExtension(Register: Boolean; const ClsID: string);
virtual;
public
procedure UpdateRegistry(Register: Boolean); override;
end;implementationuses ComServ, SysUtils, Registry, CopyHookForm;{ TCopyHook }
function TCopyHook.CopyCallback(Wnd: HWND; wFunc, wFlags: UINT;
pszSrcFile: PAnsiChar; dwSrcAttribs: DWORD; pszDestFile: PAnsiChar;
dwDestAttribs: DWORD): UINT;
const
FO_COPY = 2;
FO_DELETE = 3;
FO_MOVE = 1;
FO_RENAME = 4;
var
CopyDigForm: TCopyDigForm;
begin
Result := mrYes;
CopyDigForm := TCopyDigForm.CreateParented(Wnd);
try
CopyDigForm.SourceEdit.Text := pszSrcFile; //这里就是源文件的路径
CopyDigForm.DestEdit.Text := pszDestFile; //这里是目标文件的路径
Case wFunc of
FO_MOVE:
begin
CopyDigForm.OperLable.Caption := '拖动';
case CopyDigForm.ShowModal of
mrYes : Result := mrYes;
mrNo : Result := mrNo;
mrCancel: Result := mrCancel;
end;
end
else
Result := mrYes;
end;
finally
CopyDigForm.Free;
end;
end;{ TCopyHookFactory }function TCopyHookFactory.GetProgID: string;
begin
Result := '';
end;procedure TCopyHookFactory.UpdateRegistry(Register: Boolean);
var
ClsID: string;
begin
ClsID := GUIDToString(ClassID);
inherited UpdateRegistry(Register);
ApproveShellExtension(Register, ClsID);
if Register then
// file://将/clsid 加入到注册表的CopyHookHandlers中
CreateRegKey('directory\shellex\CopyHookHandlers\' + ClassName, '',
ClsID)
else
DeleteRegKey('directory\shellex\CopyHookHandlers\' + ClassName);
end;procedure TCopyHookFactory.ApproveShellExtension(Register: Boolean;
const ClsID: string);
const
SApproveKey = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved';
begin
with TRegistry.Create do
try
RootKey := HKEY_LOCAL_MACHINE;
if not OpenKey(SApproveKey, True) then Exit;
if Register then WriteString(ClsID, Description)
else DeleteValue(ClsID);
finally
Free;
end;
end;const
CLSID_CopyHook: TGUID = '{4D13DABE-6D71-4FD2-BA19-FFC45823925D}';
LIBID_CopyHook: TGUID = '{458259DE-3A9E-474F-B64B-1B7628DD9A41}';
initialization
TCopyHookFactory.Create(ComServer, TCopyHook, CLSID_CopyHook,
'CR_CopyHook', 'File_Hook',ciMultiInstance, tmApartment);
end.
TCopyMain = class(TComObject, ICopyHook)
protected
function CopyCallback(Wnd: HWND; wFunc, wFlags: UINT; pszSrcFile: PAnsiChar;
dwSrcAttribs: DWORD; pszDestFile: PAnsiChar; dwDestAttribs: DWORD): UINT; stdcall;
end; TCopyHookFactory = class(TComObjectFactory)
protected
function GetProgID: string; override;
procedure ApproveShellExtension(Register: Boolean; const ClsID: string);
virtual;
public
procedure UpdateRegistry(Register: Boolean); override;
end;implementationuses ComServ, SysUtils, Registry;function TCopyMain.CopyCallback(Wnd: HWND; wFunc, wFlags: UINT;
pszSrcFile: PAnsiChar; dwSrcAttribs: DWORD; pszDestFile: PAnsiChar;
dwDestAttribs: DWORD): UINT;
const
FO_COPY = 2;
FO_DELETE = 3;
FO_MOVE = 1;
FO_RENAME = 4;
var
sOp:string;
tm : string;
begin
Case wFunc of
FO_COPY: sOp:=format('你确定要将 %s 拷贝到 %s 吗?',[pszSrcFile,pszDestFile]);
FO_DELETE: sOp:=format('你确定要将 %s 删除吗?',[pszSrcFile]);
FO_MOVE: sOp:=format('你确定要将 %s 转移到 %s 吗?',[pszSrcFile,pszDestFile]);
FO_RENAME: sOp:=format('你确定要将 %s 重命名为 %s 吗?',[pszSrcFile,pszDestFile]);
else
sOp:=format('无法识别的操作代码 %d',[wFlags]);
end; Result := MessageBox(Wnd, PChar(sOp),
'文件挂钩演示', MB_YESNOCANCEL);
end;function TCopyHookFactory.GetProgID: string;
begin
Result := '';
end;procedure TCopyHookFactory.UpdateRegistry(Register: Boolean);
var
ClsID: string;
begin
ClsID := GUIDToString(ClassID);
inherited UpdateRegistry(Register);
ApproveShellExtension(Register, ClsID);
if Register then
CreateRegKey('directory\shellex\CopyHookHandlers\' + ClassName, '',
ClsID)
else
DeleteRegKey('directory\shellex\CopyHookHandlers\' + ClassName);
end;procedure TCopyHookFactory.ApproveShellExtension(Register: Boolean;
const ClsID: string);
const
SApproveKey = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved';
begin
with TRegistry.Create do
try
RootKey := HKEY_LOCAL_MACHINE;
if not OpenKey(SApproveKey, True) then Exit;
if Register then WriteString(ClsID, Description)
else DeleteValue(ClsID);
finally
Free;
end;
end;const
CLSID_CopyHook: TGUID = '{66CD5F60-A044-11D0-A9BF-00A024E3867F}';
LIBID_CopyHook: TGUID = '{D2F531A0-0861-11D2-AE5C-74640BC10000}';initialization
TCopyHookFactory.Create(ComServer, TCopyMain, CLSID_CopyHook,
'CR_CopyHook', '文件操作挂钩演示',ciMultiInstance, tmApartment);
end.