记不大清楚了,用Api函数在剪贴板消息队列中注册。 
然后,剪贴板在接到数据后,就会发消息给你的程序了。 

解决方案 »

  1.   

    D5DG的例子,对你有帮助。
    {
    Copyright ?1999 by Delphi 5 Developer's Guide - Xavier Pacheco and Steve Teixeira
    }
    unit cbdata;
    interface
    uses
      SysUtils, Windows, clipbrd;const  DDGData = 'CF_DDG'; // constant for registering the clipboard format.
    type  // Record data to be stored to the clipboard  TDataRec = packed record
        LName: string[10];
        FName: string[10];
        MI: string[2];
        Age: Integer;
        BirthDate: TDateTime;
      end;  { Define an object around the TDataRec that contains the methods
        for copying and pasting the data to and from the clipboard }
      TData = class
      public
        Rec: TDataRec;
        procedure CopyToClipBoard;
        procedure GetFromClipBoard;
      end;var
      CF_DDGDATA: word; // Receives the return value of RegisterClipboardFormat().implementationprocedure TData.CopyToClipBoard;
    { This function copies the contents of the TDataRec field, Rec, to the
      clipboard as both binary data, as text. Both formats will be
      available from the clipboard }
    const
      CRLF = #13#10;
    var
      Data: THandle;
      DataPtr: Pointer;
      TempStr: String[50];
    begin
      // Allocate SizeOf(TDataRec) bytes from the heap
      Data := GlobalAlloc(GMEM_MOVEABLE, SizeOf(TDataRec));
      try
        // Obtain a pointer to the first byte of the allocated memory
        DataPtr := GlobalLock(Data);
        try
          // Move the data in Rec to the memory block
          Move(Rec, DataPtr^, SizeOf(TDataRec));
          { Clipboard.Open must be called if multiple clipboard formats are
            being copied to the clipboard at once. Otherwise, if only one
            format is being copied the call isn't necessary }
          ClipBoard.Open;
          try
            // First copy the data as its custom format
            ClipBoard.SetAsHandle(CF_DDGDATA, Data);
            // Now copy the data as text format
            with Rec do
              TempStr := FName+CRLF+LName+CRLF+MI+CRLF+IntToStr(Age)+CRLF+
                      DateTimeToStr(BirthDate);
            ClipBoard.AsText := TempStr;
            { If a call to Clipboard.Open is made you must match it
              with a call to Clipboard.Close }
          finally
            Clipboard.Close
          end;
        finally
          // Unlock the globally allocated memory
          GlobalUnlock(Data);
        end;
      except
        { A call to GlobalFree is required only if an exception occurs.
          Otherwise, the clipboard takes over managing any allocated
          memory to it.}
        GlobalFree(Data);
        raise; 
      end;
    end;procedure TData.GetFromClipBoard;
    { This method pastes memory saved in the clipboard if it is of the
      format CF_DDGDATA. This data is stored in the TDataRec field of
      this object. }
    var
      Data: THandle;
      DataPtr: Pointer;
      Size: Integer;
    begin
      // Obtain a handle to the clipboard
      Data := ClipBoard.GetAsHandle(CF_DDGDATA);
      if Data = 0 then Exit;
      // Obtain a pointer to the memory block referred to by Data
      DataPtr := GlobalLock(Data);
      try
        // Obtain the size of the data to retrieve
        if SizeOf(TDataRec) > GlobalSize(Data) then
          Size := GlobalSize(Data)
        else
          Size := SizeOf(TDataRec);
        // Copy the data to the TDataRec field
        Move(DataPtr^, Rec, Size)
      finally
        // Free the pointer to the memory block.  
        GlobalUnlock(Data);
      end;
    end;initialization
      // Register the custom clipboard format
      CF_DDGDATA := RegisterClipBoardFormat(DDGData);
    end.
      

  2.   

    代码:
    http://www.applevb.com/sourcecode/ClipV.zip
    delphi 4的
      

  3.   

    taxi:这个看完,绝对能解决你的问题,可惜我是看不下去,没耐性。
    Question: Explains how to hook into the clipboard change, and be notified when it changes. 
    Answer: IntroductionIn this article I intend explain how to enable your application to join the chain of clipboard viewers, thus receiving an appropiate messages whenever the contents of the clipboard change. There are several uses to this facility, the main two being: A clipboard monitor - This is an application that continually watches the clipboard, and stores any information passed to it 
    Enabling and Disabling of menu items - This is used in conjunction with the paste menu item (and toolbar buttons) to enable it whenever the clipboard contains a format that your application can paste. 
    I am sure that there are other uses for this facility but off hand I can not think of any. Steps InvolvedThere are four main steps involved in using the clipboard chain, these are: Joining the clipboard chain 
    Responding to and passing on messages when the clipboard contents change 
    Responding to messages when other members are added to or removed from the chain 
    Removing your application from the chain when it closes. 
    I will explain how to implement each of these stages in the following code section. Writing the CodeThe code can be crisply divided into the four steps previously mentioned, the extra declarations that needed are:     procedure WMDRAWCLIPBOARD(var Message: TMessage); message WM_DRAWCLIPBOARD;
        procedure WMCHANGECBCHAIN(var Message: TMessage); message WM_CHANGECBCHAIN;
    These are the messages that we will receive and respond too when the clipboard or clipboard chain is modified.
    We also need to store the handle of the next window in the chain (the reasons for this will be explained later): 
        NextHandle: THandle;
    We will now fill in the code to handle these messages, and also the code for joining and leaving the chain.
    Joining the Clipboard ChainThis is normally done in the onCreate procedure of the main form in the application. All we need to do here is add the following code:   NextHandle := SetClipboardViewer(handle);
    What we are doing here is adding our handle to the clipboard chain, the returned handle is the handle of the next viewer in the chain which we will need to use later.Responding when the Clipboards Contents ChangeWhenever the contents of the clipboard changes we now receive a WM_DRAWCLIPBOARD message. In the procedure which we previously declared we can now respond to clipboard changes. We also must pass on the message that we received to the next handle in the chain, as illustrated by the following code: procedure TForm1.WMDRAWCLIPBOARD(var Message: TMessage);
    begin
      { Add code here to respond to the change }
      sendmessage(NextHandle,WM_DRAWCLIPBOARD,0,0);
    end;
    Responding when the Chain ChangesWe also receive a message whenever a handle is removed from the chain. The message we receive provides us with the handle being removed and also with the handle that imediatly follows the one being removed. In response to this we must modify our next handle property (if its being removed) and pass the message along to the next handle in the chain. This is accomplished by the following code: 
    procedure TForm1.WMCHANGECBCHAIN(var Message: TMessage);
    begin
      if Message.WParam = NextHandle then
      begin
        NextHandle := Message.LParam;
      end
      else
      begin
        sendmessage(NextHandle,
                    WM_CHANGECBCHAIN,
                    Message.WParam,  // handle of window to remove  
                    Message.LParam); // handle of next window 
      end;
    end;
    Leaving the Clipboard ChainThis is normally done in the onDestroy procedure of the main form in the application. All we are doing here is removing the application from the chain. It is done by the following code: procedure TForm1.FormDestroy(Sender: TObject);
    begin
      ChangeClipboardChain(Handle,      // our handle to remove
                           NextHandle ); // handle of next window in the chain  
      

  4.   

    如何监视剪贴板我都知道,但我如果获取在资源管理器中复制或剪切的文件名的名称呢.
    procedure WMDrawClipboard(var msg:TMessage)
    begin
      //这里应该如何写呀,如果获取文件名呢.Clipboard.AsText不行呀
    end;