WINDOWS的“复制”消息如何拦截?(50分)

  • 主题发起人 主题发起人 supershan
  • 开始时间 开始时间
S

supershan

Unregistered / Unconfirmed
GUEST, unregistred user!
我想做一程序,监视着windows的复制,截获此消息后,<br>将所复制的目录或文件的路径得到。<br><br>我想应该是通过剪贴板去实现,现在问题:<br>1.如何时时截获复制消息?<br>2.截获后,如何得到文件或文件夹的绝对路径
 
?1、copyhook<br>2、search for "使用未公开的函数监视shell操作"<br><br>
 
我把问题再直接一点,在任何一个目录或文件上按‘Ctrl+C’或复制,则如何能用程序得到这个目录或文件的路径,<br>谢谢各位! <br><br>copyhook怎么用?我看了delphi的源程序
 
1,实现ICopyHook接口,但是只能截获,处理目录的增加,删除,修改.<br>2,使用FileNotifyAPI,可以截获文件打开关闭,读写等操作.
 
to jm:<br>FileNotifyAPI如何实现,有例子吗?<br>cyj_123456@163.net<br>
 
实现CopyHook接口<br><br>unit CopyMain;<br><br>interface<br><br>uses Windows, ComObj, ShlObj;<br><br>type<br>&nbsp; TCopyHook = class(TComObject, ICopyHook)<br>&nbsp; protected<br>&nbsp; &nbsp; function CopyCallback(Wnd: HWND; wFunc, wFlags: UINT; pszSrcFile: PAnsiChar;<br>&nbsp; &nbsp; &nbsp; dwSrcAttribs: DWORD; pszDestFile: PAnsiChar; dwDestAttribs: DWORD): UINT; stdcall;<br>&nbsp; end;<br><br>&nbsp; TCopyHookFactory = class(TComObjectFactory)<br>&nbsp; protected<br>&nbsp; &nbsp; function GetProgID: string; override;<br>&nbsp; &nbsp; procedure ApproveShellExtension(Register: Boolean; const ClsID: string);<br>&nbsp; &nbsp; &nbsp; virtual;<br>&nbsp; public<br>&nbsp; &nbsp; procedure UpdateRegistry(Register: Boolean); override;<br>&nbsp; end;<br><br>implementation<br><br>uses ComServ, SysUtils, Registry;<br><br>{ TCopyHook }<br><br>// This is the method which is called by the shell for folder operations<br>function TCopyHook.CopyCallback(Wnd: HWND; wFunc, wFlags: UINT;<br>&nbsp; pszSrcFile: PAnsiChar; dwSrcAttribs: DWORD; pszDestFile: PAnsiChar;<br>&nbsp; dwDestAttribs: DWORD): UINT;<br>const<br>&nbsp; MyMessage: string = 'Are you sure you want to mess with "%s"?';<br>begin<br>&nbsp; // confirm operation<br>&nbsp; Result := MessageBox(Wnd, &nbsp;PChar(Format(MyMessage, [pszSrcFile])),<br>&nbsp; &nbsp; 'D4DG Shell Extension', MB_YESNO);<br>end;<br><br>{ TCopyHookFactory }<br><br>function TCopyHookFactory.GetProgID: string;<br>begin<br>&nbsp; // ProgID not needed for shell extension<br>&nbsp; Result := '';<br>end;<br><br>procedure TCopyHookFactory.UpdateRegistry(Register: Boolean);<br>var<br>&nbsp; ClsID: string;<br>begin<br>&nbsp; ClsID := GUIDToString(ClassID);<br>&nbsp; inherited UpdateRegistry(Register);<br>&nbsp; ApproveShellExtension(Register, ClsID);<br>&nbsp; if Register then<br>&nbsp; &nbsp; // add shell extension clsid to CopyHookHandlers reg entry<br>&nbsp; &nbsp; CreateRegKey('directory/shellex/CopyHookHandlers/' + ClassName, '',<br>&nbsp; &nbsp; &nbsp; ClsID)<br>&nbsp; else<br>&nbsp; &nbsp; DeleteRegKey('directory/shellex/CopyHookHandlers/' + ClassName);<br>end;<br><br>procedure TCopyHookFactory.ApproveShellExtension(Register: Boolean;<br>&nbsp; const ClsID: string);<br>// This registry entry is required in order for the extension to<br>// operate correctly under Windows NT.<br>const<br>&nbsp; SApproveKey = 'SOFTWARE/Microsoft/Windows/CurrentVersion/Shell Extensions/Approved';<br>begin<br>&nbsp; with TRegistry.Create do<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; RootKey := HKEY_LOCAL_MACHINE;<br>&nbsp; &nbsp; &nbsp; if not OpenKey(SApproveKey, True) then Exit;<br>&nbsp; &nbsp; &nbsp; if Register then WriteString(ClsID, Description)<br>&nbsp; &nbsp; &nbsp; else DeleteValue(ClsID);<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; Free;<br>&nbsp; &nbsp; end;<br>end;<br><br>const<br>&nbsp; CLSID_CopyHook: TGUID = '{66CD5F60-A044-11D0-A9BF-00A024E3867F}';<br><br>initialization<br>&nbsp; TCopyHookFactory.Create(ComServer, TCopyHook, CLSID_CopyHook,<br>&nbsp; &nbsp; 'D4DG_CopyHook', 'D4DG Copy Hook Shell Extension Example',<br>&nbsp; &nbsp; ciMultiInstance, tmApartment);<br>end.<br>
 
这个问题应该监视剪切板!有一个反过来的问题的回答:ID=470181
 
用调试工具查看消息,然后拦截。
 
复制的内容都在剪贴板,所以问题转换为监视剪贴板即可!
 
类似于NORTON删除文件的拦截,应该是在SHELL里面实现,通过COPYHOOK之类<br>的回调函数,估计你要去查一下SHELL里面的函数操作了。
 
我也关注这个问题,想知道答案。<br>
 
后退
顶部