如何获取Windows复制、粘贴文件的 消息?(300分)

  • 主题发起人 主题发起人 zzutrain
  • 开始时间 开始时间
Z

zzutrain

Unregistered / Unconfirmed
GUEST, unregistred user!
如何获取Windows复制、粘贴文件的 消息?
 
delphi5开发人员指南中好象有介绍。<br>我自己的程序中写过一段剪贴板的,你参考看看,判断剪贴板的格式是否为文件应该就可以了,可是判断<br>剪贴板中的数据格式如果为e:/xxx.zip这样的行,就一行一行进行判断是否存在这个文件以进行确认<br>是否为copy文件的信息。。<br><br>&nbsp; //将WM_DRAWCLIPBOARD消息传递到下一个观察链中的窗口<br>&nbsp; SendMessage(NextClipHwnd,AMessage.Msg,AMessage.WParam,AMessage.LParam);<br>&nbsp; //查询剪贴板中特定格式的数据内容<br>&nbsp; if (Clipboard.HasFormat(CF_TEXT) or Clipboard.HasFormat(CF_OEMTEXT)) then<br>&nbsp; begin<br>&nbsp; &nbsp; //处理剪贴板中内容<br>&nbsp; &nbsp; tmpStr:=Clipboard.asText;<br>&nbsp; end;<br><br>&nbsp; if(NextClipHwnd&lt;&gt;0) then<br>&nbsp; begin<br>&nbsp; &nbsp; //从观察链中删除本观察窗口<br>&nbsp; &nbsp; ChangeClipboardChain(Handle,NextClipHwnd);<br>&nbsp; &nbsp; //将WM_DRAWCLIPBOARD消息传递到下一个观察链中的窗口<br>&nbsp; &nbsp; SendMessage(NextClipHwnd,WM_CHANGECBCHAIN,Handle,NextClipHwnd);<br>&nbsp; &nbsp; NextClipHwnd:=0;<br>&nbsp; end;<br><br>&nbsp; //获得观察链中下一个窗口句柄<br>&nbsp; if(NextClipHwnd=0) then<br>&nbsp; begin<br>&nbsp; &nbsp; NextClipHwnd:=SetClipBoardViewer(Handle);<br>&nbsp; end;<br><br>以上为我的理解,仅供参考。
 
WM_COPY &nbsp;<br>WM_CUT &nbsp;<br>WM_PASTE &nbsp;<br><br>可以这么做<br>procedure ClipCopy(var M:TMessage); Message WM_COPY;<br>//自己处理<br>begin<br>end;
 
再说明一下,当用户复制了一个文件,当他点击粘贴时,Windows不执行该复制文件的操作.<br>用自己的程序来实现Windows的操作.或者更确切的说,是拦截粘贴文件的消息
 
早说吗?害得楼上两位大哥都误解了!这个问题要根据不同的编辑框来定<br>也就是要取得编辑框的句柄后才可以操作,用sendmessage就可以直接屏蔽<br>windows的消息
 
DELPHI有一个剪贴板的类地<br>好像是叫<br>忘了,你查一下帮助<br><br>很简单地,我在书上看到过地
 
Delphi的例子:<br>X:/Program Files/Borland/Delphi6/Demos/ActiveX/ShellExt/copyhook.dpr
 
惭愧惭愧,一直用Delphi5开做开发,刚用Delphi6没有多久,连例子也没有来得及看,回去一定<br>好好看看,若可以实现,回头给分.
 
<br>{*******************************************************}<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{ &nbsp; &nbsp; &nbsp; Borland Delphi Visual Component Library &nbsp; &nbsp; &nbsp; &nbsp; }<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{ &nbsp;Copyright (c) 1995-2001 Borland Software Corporation }<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{*******************************************************}<br><br>unit Clipbrd;<br><br>{$R-,T-,H+,X+}<br><br>interface<br><br>uses Windows, Messages, Classes, Graphics;<br><br>var<br>&nbsp; CF_PICTURE: Word;<br>&nbsp; CF_COMPONENT: Word;<br><br>{ TClipboard }<br><br>{ The clipboard object encapsulates the Windows clipboard.<br><br>&nbsp; Assign - Assigns the given object to the clipboard. &nbsp;If the object is<br>&nbsp; &nbsp; a TPicture or TGraphic desendent it will be placed on the clipboard<br>&nbsp; &nbsp; in the corresponding format (e.g. TBitmap will be placed on the<br>&nbsp; &nbsp; clipboard as a CF_BITMAP). Picture.Assign(Clipboard) and<br>&nbsp; &nbsp; Bitmap.Assign(Clipboard) are also supported to retrieve the contents<br>&nbsp; &nbsp; of the clipboard.<br>&nbsp; Clear - Clears the contents of the clipboard. &nbsp;This is done automatically<br>&nbsp; &nbsp; when the clipboard object adds data to the clipboard.<br>&nbsp; Close - Closes the clipboard if it is open. &nbsp;Open and close maintain a<br>&nbsp; &nbsp; count of the number of times the clipboard has been opened. &nbsp;It will<br>&nbsp; &nbsp; not actually close the clipboard until it has been closed the same<br>&nbsp; &nbsp; number of times it has been opened.<br>&nbsp; Open - Open the clipboard and prevents all other applications from changeing<br>&nbsp; &nbsp; the clipboard. &nbsp;This is call is not necessary if you are adding just one<br>&nbsp; &nbsp; item to the clipboard. &nbsp;If you need to add more than one format to<br>&nbsp; &nbsp; the clipboard, call Open. &nbsp;After all the formats have been added. Call<br>&nbsp; &nbsp; close.<br>&nbsp; HasFormat - Returns true if the given format is available on the clipboard.<br>&nbsp; GetAsHandle - Returns the data from the clipboard in a raw Windows handled<br>&nbsp; &nbsp; for the specified format. &nbsp;The handle is not owned by the application and<br>&nbsp; &nbsp; the data should be copied.<br>&nbsp; SetAsHandle - Places the handle on the clipboard in the given format. &nbsp;Once<br>&nbsp; &nbsp; a handle has been given to the clipboard it should *not* be deleted. &nbsp;It<br>&nbsp; &nbsp; will be deleted by the clipboard.<br>&nbsp; GetTextBuf - Retrieves<br>&nbsp; AsText - Allows placing and retrieving text from the clipboard. &nbsp;This property<br>&nbsp; &nbsp; is valid to retrieve if the CF_TEXT format is available.<br>&nbsp; FormatCount - The number of formats in the Formats array.<br>&nbsp; Formats - A list of all the formats available on the clipboard. }<br><br>type<br>&nbsp; TClipboard = class(TPersistent)<br>&nbsp; private<br>&nbsp; &nbsp; FOpenRefCount: Integer;<br>&nbsp; &nbsp; FClipboardWindow: HWND;<br>&nbsp; &nbsp; FAllocated: Boolean;<br>&nbsp; &nbsp; FEmptied: Boolean;<br>&nbsp; &nbsp; procedure Adding;<br>&nbsp; &nbsp; procedure AssignGraphic(Source: TGraphic);<br>&nbsp; &nbsp; procedure AssignPicture(Source: TPicture);<br>&nbsp; &nbsp; procedure AssignToBitmap(Dest: TBitmap);<br>&nbsp; &nbsp; procedure AssignToMetafile(Dest: TMetafile);<br>&nbsp; &nbsp; procedure AssignToPicture(Dest: TPicture);<br>&nbsp; &nbsp; function GetAsText: string;<br>&nbsp; &nbsp; function GetClipboardWindow: HWND;<br>&nbsp; &nbsp; function GetFormatCount: Integer;<br>&nbsp; &nbsp; function GetFormats(Index: Integer): Word;<br>&nbsp; &nbsp; procedure SetAsText(const Value: string);<br>&nbsp; protected<br>&nbsp; &nbsp; procedure AssignTo(Dest: TPersistent); override;<br>&nbsp; &nbsp; procedure SetBuffer(Format: Word; var Buffer; Size: Integer);<br>&nbsp; &nbsp; procedure WndProc(var Message: TMessage); virtual;<br>&nbsp; &nbsp; procedure MainWndProc(var Message: TMessage);<br>&nbsp; &nbsp; property Handle: HWND read GetClipboardWindow;<br>&nbsp; &nbsp; property OpenRefCount: Integer read FOpenRefCount;<br>&nbsp; public<br>&nbsp; &nbsp; procedure Assign(Source: TPersistent); override;<br>&nbsp; &nbsp; procedure Clear; virtual;<br>&nbsp; &nbsp; procedure Close; virtual;<br>&nbsp; &nbsp; function GetComponent(Owner, Parent: TComponent): TComponent;<br>&nbsp; &nbsp; function GetAsHandle(Format: Word): THandle;<br>&nbsp; &nbsp; function GetTextBuf(Buffer: PChar; BufSize: Integer): Integer;<br>&nbsp; &nbsp; function HasFormat(Format: Word): Boolean;<br>&nbsp; &nbsp; procedure Open; virtual;<br>&nbsp; &nbsp; procedure SetComponent(Component: TComponent);<br>&nbsp; &nbsp; procedure SetAsHandle(Format: Word; Value: THandle);<br>&nbsp; &nbsp; procedure SetTextBuf(Buffer: PChar);<br>&nbsp; &nbsp; property AsText: string read GetAsText write SetAsText;<br>&nbsp; &nbsp; property FormatCount: Integer read GetFormatCount;<br>&nbsp; &nbsp; property Formats[Index: Integer]: Word read GetFormats;<br>&nbsp; end;<br><br>function Clipboard: TClipboard;<br>function SetClipboard(NewClipboard: TClipboard): TClipboard;<br><br>implementation<br><br>uses SysUtils, Forms, Consts;<br><br>procedure TClipboard.Clear;<br>begin<br>&nbsp; Open;<br>&nbsp; try<br>&nbsp; &nbsp; EmptyClipboard;<br>&nbsp; finally<br>&nbsp; &nbsp; Close;<br>&nbsp; end;<br>end;<br><br>procedure TClipboard.Adding;<br>begin<br>&nbsp; if (FOpenRefCount &lt;&gt; 0) and not FEmptied then<br>&nbsp; begin<br>&nbsp; &nbsp; Clear;<br>&nbsp; &nbsp; FEmptied := True;<br>&nbsp; end;<br>end;<br><br>procedure TClipboard.Close;<br>begin<br>&nbsp; if FOpenRefCount = 0 then Exit;<br>&nbsp; Dec(FOpenRefCount);<br>&nbsp; if FOpenRefCount = 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; CloseClipboard;<br>&nbsp; &nbsp; if FAllocated then<br>&nbsp; &nbsp; &nbsp; Classes.DeallocateHWnd(FClipboardWindow);<br>&nbsp; &nbsp; FClipboardWindow := 0;<br>&nbsp; end;<br>end;<br><br>procedure TClipboard.Open;<br>begin<br>&nbsp; if FOpenRefCount = 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; FClipboardWindow := Application.Handle;<br>&nbsp; &nbsp; if FClipboardWindow = 0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; FClipboardWindow := Classes.AllocateHWnd(MainWndProc);<br>&nbsp; &nbsp; &nbsp; FAllocated := True;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; if not OpenClipboard(FClipboardWindow) then<br>&nbsp; &nbsp; &nbsp; raise Exception.CreateRes(@SCannotOpenClipboard);<br>&nbsp; &nbsp; FEmptied := False;<br>&nbsp; end;<br>&nbsp; Inc(FOpenRefCount);<br>end;<br><br>procedure TClipboard.WndProc(var Message: TMessage);<br>begin<br>&nbsp; with Message do<br>&nbsp; &nbsp; Result := DefWindowProc(FClipboardWindow, Msg, wParam, lParam);<br>end;<br><br>function TClipboard.GetComponent(Owner, Parent: TComponent): TComponent;<br>var<br>&nbsp; Data: THandle;<br>&nbsp; DataPtr: Pointer;<br>&nbsp; MemStream: TMemoryStream;<br>&nbsp; Reader: TReader;<br>begin<br>&nbsp; Result := nil;<br>&nbsp; Open;<br>&nbsp; try<br>&nbsp; &nbsp; Data := GetClipboardData(CF_COMPONENT);<br>&nbsp; &nbsp; if Data = 0 then Exit;<br>&nbsp; &nbsp; DataPtr := GlobalLock(Data);<br>&nbsp; &nbsp; if DataPtr = nil then Exit;<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; MemStream := TMemoryStream.Create;<br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; MemStream.WriteBuffer(DataPtr^, GlobalSize(Data));<br>&nbsp; &nbsp; &nbsp; &nbsp; MemStream.Position := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; Reader := TReader.Create(MemStream, 256);<br>&nbsp; &nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Reader.Parent := Parent;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := Reader.ReadRootComponent(nil);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if Owner &lt;&gt; nil then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Owner.InsertComponent(Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; except<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result.Free;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raise;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Reader.Free;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; &nbsp; MemStream.Free;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; GlobalUnlock(Data);<br>&nbsp; &nbsp; end;<br>&nbsp; finally<br>&nbsp; &nbsp; Close;<br>&nbsp; end;<br>end;<br><br>procedure TClipboard.SetBuffer(Format: Word; var Buffer; Size: Integer);<br>var<br>&nbsp; Data: THandle;<br>&nbsp; DataPtr: Pointer;<br>begin<br>&nbsp; Open;<br>&nbsp; try<br>&nbsp; &nbsp; Data := GlobalAlloc(GMEM_MOVEABLE+GMEM_DDESHARE, Size);<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; DataPtr := GlobalLock(Data);<br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; Move(Buffer, DataPtr^, Size);<br>&nbsp; &nbsp; &nbsp; &nbsp; Adding;<br>&nbsp; &nbsp; &nbsp; &nbsp; SetClipboardData(Format, Data);<br>&nbsp; &nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; &nbsp; GlobalUnlock(Data);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; except<br>&nbsp; &nbsp; &nbsp; GlobalFree(Data);<br>&nbsp; &nbsp; &nbsp; raise;<br>&nbsp; &nbsp; end;<br>&nbsp; finally<br>&nbsp; &nbsp; Close;<br>&nbsp; end;<br>end;<br><br>procedure TClipboard.SetComponent(Component: TComponent);<br>var<br>&nbsp; MemStream: TMemoryStream;<br>begin<br>&nbsp; MemStream := TMemoryStream.Create;<br>&nbsp; try<br>&nbsp; &nbsp; MemStream.WriteComponent(Component);<br>&nbsp; &nbsp; SetBuffer(CF_COMPONENT, MemStream.Memory^, MemStream.Size);<br>&nbsp; finally<br>&nbsp; &nbsp; MemStream.Free;<br>&nbsp; end;<br>end;<br><br>function TClipboard.GetTextBuf(Buffer: PChar; BufSize: Integer): Integer;<br>var<br>&nbsp; Data: THandle;<br>begin<br>&nbsp; Open;<br>&nbsp; Data := GetClipboardData(CF_TEXT);<br>&nbsp; if Data = 0 then Result := 0 else<br>&nbsp; begin<br>&nbsp; &nbsp; Result := StrLen(StrLCopy(Buffer, GlobalLock(Data), BufSize - 1));<br>&nbsp; &nbsp; GlobalUnlock(Data);<br>&nbsp; end;<br>&nbsp; Close;<br>end;<br><br>procedure TClipboard.SetTextBuf(Buffer: PChar);<br>begin<br>&nbsp; SetBuffer(CF_TEXT, Buffer^, StrLen(Buffer) + 1);<br>end;<br><br>function TClipboard.GetAsText: string;<br>var<br>&nbsp; Data: THandle;<br>begin<br>&nbsp; Open;<br>&nbsp; Data := GetClipboardData(CF_TEXT);<br>&nbsp; try<br>&nbsp; &nbsp; if Data &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; Result := PChar(GlobalLock(Data))<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; Result := '';<br>&nbsp; finally<br>&nbsp; &nbsp; if Data &lt;&gt; 0 then GlobalUnlock(Data);<br>&nbsp; &nbsp; Close;<br>&nbsp; end;<br>end;<br><br>function TClipboard.GetClipboardWindow: HWND;<br>begin<br>&nbsp; if FClipboardWindow = 0 then<br>&nbsp; &nbsp; Open;<br>&nbsp; Result := FClipboardWindow;<br>end;<br><br>procedure TClipboard.SetAsText(const Value: string);<br>begin<br>&nbsp; SetBuffer(CF_TEXT, PChar(Value)^, Length(Value) + 1);<br>end;<br><br>procedure TClipboard.AssignToPicture(Dest: TPicture);<br>var<br>&nbsp; Data: THandle;<br>&nbsp; Format: Word;<br>&nbsp; Palette: HPALETTE;<br>begin<br>&nbsp; Open;<br>&nbsp; try<br>&nbsp; &nbsp; Format := EnumClipboardFormats(0);<br>&nbsp; &nbsp; while Format &lt;&gt; 0 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if TPicture.SupportsClipboardFormat(Format) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Data := GetClipboardData(Format);<br>&nbsp; &nbsp; &nbsp; &nbsp; Palette := GetClipboardData(CF_PALETTE);<br>&nbsp; &nbsp; &nbsp; &nbsp; Dest.LoadFromClipboardFormat(Format, Data, Palette);<br>&nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; Format := EnumClipboardFormats(Format);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; raise Exception.CreateRes(@SInvalidClipFmt);<br>&nbsp; finally<br>&nbsp; &nbsp; Close;<br>&nbsp; end;<br>end;<br><br>procedure TClipboard.AssignToBitmap(Dest: TBitmap);<br>var<br>&nbsp; Data: THandle;<br>&nbsp; Palette: HPALETTE;<br>begin<br>&nbsp; Open;<br>&nbsp; try<br>&nbsp; &nbsp; Data := GetClipboardData(CF_BITMAP);<br>&nbsp; &nbsp; Palette := GetClipboardData(CF_PALETTE);<br>&nbsp; &nbsp; Dest.LoadFromClipboardFormat(CF_BITMAP, Data, Palette);<br>&nbsp; finally<br>&nbsp; &nbsp; Close;<br>&nbsp; end;<br>end;<br><br>procedure TClipboard.AssignToMetafile(Dest: TMetafile);<br>var<br>&nbsp; Data: THandle;<br>&nbsp; Palette: HPALETTE;<br>begin<br>&nbsp; Open;<br>&nbsp; try<br>&nbsp; &nbsp; Data := GetClipboardData(CF_METAFILEPICT);<br>&nbsp; &nbsp; Palette := GetClipboardData(CF_PALETTE);<br>&nbsp; &nbsp; Dest.LoadFromClipboardFormat(CF_METAFILEPICT, Data, Palette);<br>&nbsp; finally<br>&nbsp; &nbsp; Close;<br>&nbsp; end;<br>end;<br><br>procedure TClipboard.AssignTo(Dest: TPersistent);<br>begin<br>&nbsp; if Dest is TPicture then<br>&nbsp; &nbsp; AssignToPicture(TPicture(Dest))<br>&nbsp; else if Dest is TBitmap then<br>&nbsp; &nbsp; AssignToBitmap(TBitmap(Dest))<br>&nbsp; else if Dest is TMetafile then<br>&nbsp; &nbsp; AssignToMetafile(TMetafile(Dest))<br>&nbsp; else inherited AssignTo(Dest);<br>end;<br><br>procedure TClipboard.AssignPicture(Source: TPicture);<br>var<br>&nbsp; Data: THandle;<br>&nbsp; Format: Word;<br>&nbsp; Palette: HPALETTE;<br>begin<br>&nbsp; Open;<br>&nbsp; try<br>&nbsp; &nbsp; Adding;<br>&nbsp; &nbsp; Palette := 0;<br>&nbsp; &nbsp; Source.SaveToClipboardFormat(Format, Data, Palette);<br>&nbsp; &nbsp; SetClipboardData(Format, Data);<br>&nbsp; &nbsp; if Palette &lt;&gt; 0 then SetClipboardData(CF_PALETTE, Palette);<br>&nbsp; finally<br>&nbsp; &nbsp; Close;<br>&nbsp; end;<br>end;<br><br>procedure TClipboard.AssignGraphic(Source: TGraphic);<br>var<br>&nbsp; Data: THandle;<br>&nbsp; Format: Word;<br>&nbsp; Palette: HPALETTE;<br>begin<br>&nbsp; Open;<br>&nbsp; try<br>&nbsp; &nbsp; Adding;<br>&nbsp; &nbsp; Palette := 0;<br>&nbsp; &nbsp; Source.SaveToClipboardFormat(Format, Data, Palette);<br>&nbsp; &nbsp; SetClipboardData(Format, Data);<br>&nbsp; &nbsp; if Palette &lt;&gt; 0 then SetClipboardData(CF_PALETTE, Palette);<br>&nbsp; finally<br>&nbsp; &nbsp; Close;<br>&nbsp; end;<br>end;<br><br>procedure TClipboard.Assign(Source: TPersistent);<br>begin<br>&nbsp; if Source is TPicture then<br>&nbsp; &nbsp; AssignPicture(TPicture(Source))<br>&nbsp; else if Source is TGraphic then<br>&nbsp; &nbsp; AssignGraphic(TGraphic(Source))<br>&nbsp; else inherited Assign(Source);<br>end;<br><br>function TClipboard.GetAsHandle(Format: Word): THandle;<br>begin<br>&nbsp; Open;<br>&nbsp; try<br>&nbsp; &nbsp; Result := GetClipboardData(Format);<br>&nbsp; finally<br>&nbsp; &nbsp; Close;<br>&nbsp; end;<br>end;<br><br>procedure TClipboard.SetAsHandle(Format: Word; Value: THandle);<br>begin<br>&nbsp; Open;<br>&nbsp; try<br>&nbsp; &nbsp; Adding;<br>&nbsp; &nbsp; SetClipboardData(Format, Value);<br>&nbsp; finally<br>&nbsp; &nbsp; Close;<br>&nbsp; end;<br>end;<br><br>function TClipboard.GetFormatCount: Integer;<br>begin<br>&nbsp; Result := CountClipboardFormats;<br>end;<br><br>function TClipboard.GetFormats(Index: Integer): Word;<br>begin<br>&nbsp; Open;<br>&nbsp; try<br>&nbsp; &nbsp; Result := EnumClipboardFormats(0);<br>&nbsp; &nbsp; while Index &gt; 0 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Dec(Index);<br>&nbsp; &nbsp; &nbsp; Result := EnumClipboardFormats(Result);<br>&nbsp; &nbsp; end;<br>&nbsp; finally<br>&nbsp; &nbsp; Close;<br>&nbsp; end;<br>end;<br><br>function TClipboard.HasFormat(Format: Word): Boolean;<br><br>&nbsp; function HasAPicture: Boolean;<br>&nbsp; var<br>&nbsp; &nbsp; Format: Word;<br>&nbsp; begin<br>&nbsp; &nbsp; Open;<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; Result := False;<br>&nbsp; &nbsp; &nbsp; Format := EnumClipboardFormats(0);<br>&nbsp; &nbsp; &nbsp; while Format &lt;&gt; 0 do<br>&nbsp; &nbsp; &nbsp; &nbsp; if TPicture.SupportsClipboardFormat(Format) then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := True;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Break;<br>&nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; &nbsp; else Format := EnumClipboardFormats(Format);<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; Close;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br><br>begin<br>&nbsp; Result := IsClipboardFormatAvailable(Format) or ((Format = CF_PICTURE) and<br>&nbsp; &nbsp; HasAPicture);<br>end;<br><br><br>var<br>&nbsp; FClipboard: TClipboard;<br><br>function Clipboard: TClipboard;<br>begin<br>&nbsp; if FClipboard = nil then<br>&nbsp; &nbsp; FClipboard := TClipboard.Create;<br>&nbsp; Result := FClipboard;<br>end;<br><br>function SetClipboard(NewClipboard: TClipboard): TClipboard;<br>begin<br>&nbsp; Result := FClipboard;<br>&nbsp; FClipboard := NewClipboard;<br>end;<br><br>procedure TClipboard.MainWndProc(var Message: TMessage);<br>begin<br>&nbsp; try<br>&nbsp; &nbsp; WndProc(Message);<br>&nbsp; except<br>&nbsp; &nbsp; if Assigned(ApplicationHandleException) then<br>&nbsp; &nbsp; &nbsp; ApplicationHandleException(Self)<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; raise;<br>&nbsp; end;<br>end;<br><br>initialization<br>&nbsp; { The following strings should not be localized }<br>&nbsp; CF_PICTURE := RegisterClipboardFormat('Delphi Picture');<br>&nbsp; CF_COMPONENT := RegisterClipboardFormat('Delphi Component');<br>&nbsp; FClipboard := nil;<br>finalization<br>&nbsp; FClipboard.Free;<br>end.<br><br>
 
to zzutrain:<br>//惭愧惭愧,一直用Delphi5开做开发,刚用Delphi6没有多久,连例子也没有来得及看,回去一定<br>//好好看看,若可以实现,回头给分.<br>对不起,可我想告诉你,这个例子Delphi5里面就有了,和Delphi6里面的一模一样
 
楼上的大哥好象搞错了.我要的文件操作,不是文件夹的,而且更重要是拦截创建文件的<br>消息.copyhook是对文件夹操作的。真不好意思,但是还是要谢谢你。
 
没有人可以告诉我么?
 
没有人可以帮我解决这个问题么?
 
//楼上的大哥好象搞错了.我要的文件操作,不是文件夹的,而且更重要是拦截创建文件的<br>//消息.copyhook是对文件夹操作的。<br>对不起,我说的例子是搞错了[8D]<br>刚才倒发现一个可以监视文件及文件夹操作的程序,不过不能拦截<br>http://210.78.159.116:8080/dispbbspro.php?id=2<br>或许还有未公开的函数可以做到<br>
 
先谢谢楼上的兄弟!我看看去
 
我看过了,上边的内容我已用来监视硬件的热插拔了。不过还是很谢谢您。
 
SendMessage(h,WM_Cut, 0, 0 ) ;<br>SendMessage(h,WM_Copy, 0, 0 ) ;<br>SendMessage(h,WM_Paste, 0, 0 ) ;<br>
 
问题未解决,拖太久了,散分。
 
后退
顶部