Board index » delphi » Any ways to monitor the clipboard?

Any ways to monitor the clipboard?

Hello,
Is there any ways to monitor the clipboard so that whenever there is
change in the clipboard, my program will be notified...

Anyone can tell me how to do so?
Pls provide sample codes.

Thanks in advance.
yeet...@iname.com

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

 

Re:Any ways to monitor the clipboard?


Hello,
   Check out the SetClipboardViewer Windows API function.  D1 did a better job
with examples, etc.
   --George

Re:Any ways to monitor the clipboard?


Quote
In article <7k7rhh$g4...@nnrp1.deja.com>, nyt <yeet...@iname.com> writes:
>Hello,
>Is there any ways to monitor the clipboard so that whenever there is
>change in the clipboard, my program will be notified...

>Anyone can tell me how to do so?
>Pls provide sample codes.

Hi the WM_DRAWCLIPBOARD is sent to all applications using set clipboard viewer
but you also have to process the WM_CHANGECBCHAIN message. I use something like
the following to update a clipboard list which could be visible for some time
and could change. There's a clipboard viewer in the Rxlibrary (
http://rx.demo.ru ). If you don't have it it's well worth the download. It's a
lot easier to find out how to do things like this than trying to glean it from
the Win32 help files. (freeware with some minor restrictions on use).

( the WM_DESTROYCLIPBOARD is also sent to the clipboard owner when someone
empties the clipboard)

private
fClipboardOwner: hwnd;

 public
    procedure WMDrawClipboard(var Message: TMessage); message WM_DRAWCLIPBOARD;
    procedure WMChangeCBChain(var Msg: TWMChangeCBChain); message
WM_CHANGECBCHAIN;
end;

var
YourDlg1: TYourDlg;
...
...

implementation

procedure TYourDlg.WMChangeCBChain(var Msg: TWMChangeCBChain);
begin
  if Msg.Remove = fClipboardOwner then fClipboardOwner := Msg.Next
  else SendMessage(fClipboardOwner, WM_CHANGECBCHAIN, Msg.Remove, Msg.Next);
  Msg.Result := 0;
inherited;
end;

procedure TYourDlg.WMDrawClipboard(var Message: TMessage);
begin
 // DoYour Stuff Here; like update a clipboard list
  inherited;
end;

procedure TYourDlg.FormCreate(Sender: TObject);
var
  count: integer;
begin
   SetClipBoardViewer(handle);
   fClipboardOwner:= handle;
end;

hth

Gordon

http://members.aol.com/mgcsoft/  (the function junction equation editor)
http://members.aol.com/delphistuf/delphstf.htm   (Delphi bits and bobs and a
few links)

MGCSoft

Other Threads