Getting notified of clipboard changes lazarus / 13-General ---------------------------------------------------------------------- Chewie · 2008-02-11 20:54 Hello evyeryone! I do have some experience in Delphi, but I'm completely new to Lazarus. My goal is to write a multi-platform clipboard-related program, so I am currently playing around with system clipboard access from Lazarus. For the start, I want to write a small program that is called when the contents of the clipboard changes, initially Windows-only. I have the following Delphi program which works just fine: Code: [Select] unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,   Dialogs, StdCtrls, Clipbrd; type   TForm1 = class(TForm)     Memo1: TMemo;     procedure FormCreate(Sender: TObject);     procedure FormDestroy(Sender: TObject);   private     { Private-Deklarationen }     FNextInChain: THandle;     procedure WMDrawClipboard(var Msg: TMessage); message WM_DRAWCLIPBOARD;     procedure WMChangeCBChain(var Msg: TMessage); message WM_CHANGECBCHAIN;   public     { Public-Deklarationen }   end; var   Form1: TForm1; implementation {$R *.dfm} procedure TForm1.WMDrawClipboard(var Msg: TMessage); begin   if Clipboard.HasFormat(CF_TEXT) then   begin     Memo1.Text := Clipboard.AsText;   end   else   begin     Memo1.Text := 'Wrong format';   end;   //pass the message on to the next window   if FNextInChain <> 0 then     SendMessage(FNextInChain, WM_DRAWCLIPBOARD, 0, 0); end; procedure TForm1.FormCreate(Sender: TObject); begin   FNextInChain := SetClipboardViewer(Self.Handle); end; procedure TForm1.FormDestroy ( Sender: TObject ) ; begin   ChangeClipboardChain(Self.Handle, Self.FNextInChain); end; procedure TForm1.WMChangeCBChain(var Msg: TMessage); var   Remove, Next: THandle; begin   Remove := Msg.WParam;   Next := Msg.LParam;   with Msg do     if FNextInChain = Remove then       FNextInChain := Next     else if FNextInChain <> 0 then       SendMessage(FNextInChain, WM_CHANGECBCHAIN, Remove, Next); end; end. The same (well, essentially the same- the used units and the resource inclusion is different of course) unfortunately does not work when compiled with Lazarus. The WMChangeCBChain and WMDrawClipboard methods are not called when they should be. At first, I thought there is a totally different approach to listening to system messages, but catching a basic message like e.g. WM_ACTIVATE works just fine. I'm pretty at a loss right now, I hope somebody can shed some light on this matter. Thanks in advance! For convenience, I'll post the Lazarus code. The form has just a single memo on it. Code: [Select] unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,   Clipbrd, Windows, Messages; type  { TForm1 }   TForm1 = class(TForm)     Memo1: TMemo;     procedure FormCreate(Sender: TObject);     procedure FormDestroy ( Sender: TObject ) ;   private     { private declarations }     FNextInChain: THandle;     procedure WMDrawClipboard(var Msg: TMessage); message WM_DRAWCLIPBOARD;     procedure WMChangeCBChain(var Msg: TMessage); message WM_CHANGECBCHAIN;   public     { public declarations }   end; var   Form1: TForm1; implementation { TForm1 } procedure TForm1.FormCreate(Sender: TObject); begin   FNextInChain := SetClipboardViewer(Self.Handle); end; procedure TForm1.FormDestroy ( Sender: TObject ) ; begin   ChangeClipboardChain(Self.Handle, Self.FNextInChain); end; procedure TForm1.WMDrawClipboard(var Msg: TMessage); begin   if Clipboard.HasFormat(CF_TEXT) then   begin     Memo1.Text := Clipboard.AsText;   end   else   begin     Memo1.Text := 'Falsches Format';   end;   //pass the message on to the next window   if FNextInChain <> 0 then     SendMessage(FNextInChain, WM_DRAWCLIPBOARD, 0, 0); end; procedure TForm1.WMChangeCBChain(var Msg: TMessage); var   Remove, Next: THandle; begin   Remove := Msg.WParam;   Next := Msg.LParam;   with Msg do     if FNextInChain = Remove then       FNextInChain := Next     else if FNextInChain <> 0 then       SendMessage(FNextInChain, WM_CHANGECBCHAIN, Remove, Next); end; initialization   {$I unit1.lrs} end. ---------------------------------------------------------------------- Leledumbo · 2008-02-12 05:52 You shouldn't use Windows and Messages, try LCLIntf, LCLType, and LMessages instead. All messages are prefixed with LM instead of WM. ---------------------------------------------------------------------- Chewie · 2008-02-12 10:37 Thanks, Leledumbo, but that does not help me much. I guess that LCL somehow translates messages from Windows, GTK or whatever UI interface is linked against to LCL-specific LM_xxx messages. Is this guess correct? If it is, I would need to find out if there is a translation for the two aforementioned Windows messages and if there is, how they are called. If there is no translation (yet),  can I at least catch Windows-specific messages (and lose platform independece of course) like I am trying right now? Have you or anyone else an answer for these questions or at least a clue in which source file(s) of LCL I can find the answers? ---------------------------------------------------------------------- AlistairG · 2011-03-08 23:32 Hi how did you get on with this as I want to get clipboard notification messages too from Linux/Win/Mac. Thanks, Alistair.