Hi,
Meinst du mit Zwischenspeicher die Zwischenablage?
Wenn immer der Inhalt der Zwischenablage ändert, versendet Windows
eine WM_DRAWCLIPBOARD Nachricht an all diejenigen Fenster,
welche sich als ClipboardViewer registriert haben.
Folgende 4 Schritte müssen ausgeführt werden, um einen ClipboardViewer zu registrieren:
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.
The SetClipboardViewer function adds the specified window to the chain of clipboard viewers. Clipboard viewer windows receive a WM_DRAWCLIPBOARD message whenever the content of the clipboard changes.
Beispiel:Den ClipBoardViewer im OnCreate installieren:
procedure TForm1.FormCreate(Sender: TObject);
begin
NextHandle := SetClipboardViewer(handle);
end;
Erklärung:NextHandle ist das Handle zum nächsten ClipboardViewer.
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.
So musst du dann einen Handler deklarieren, um die
WM_DRAWCLIPBOARD abzufangen:
private
procedure WMDRAWCLIPBOARD(var Message: TMessage); message WM_DRAWCLIPBOARD;
im Implementation Teil:
procedure TForm1.WMDRAWCLIPBOARD(var Message: TMessage);
begin
ShowMessage('Inhalt der Zwischenablage wurde geöndert');
{ Add code here to respond to the change }
sendmessage(NextHandle,WM_DRAWCLIPBOARD,0,0);
end
Wenn ein anderer ClipBoardViewer sich von der Kette entfernt, wird
eine WM_CHANGECBCHAIN versandt.
Dann muss das NextHandle modifiziert werden:
We 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:
So musst du dann einen Handler deklarieren, um die
WM_CHANGECBCHAIN abzufangen:
private
procedure WMCHANGECBCHAIN(var Message: TMessage); message WM_CHANGECBCHAIN;
im Implementation Teil:
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;
Bevor die App beendet wird, muss die App von der ClipBoardViewer Kette
entfernt werden. Dies kannst du z.B im OnDestroy machen.
The ChangeClipboardChain function removes a specified window from the chain of clipboard viewers.
This 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
end;
Die Unit sieht dann etwa so aus:
[font size=2 face="Courier New"][font color="#000000"]
type
TForm1 =
class(TForm)
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
[font color="#000080"]
{ Private declarations }
[/font]NextHandle: THandle;
procedure WMDRAWCLIPBOARD(
var Message: TMessage);
message WM_DRAWCLIPBOARD;
procedure WMCHANGECBCHAIN(
var Message: TMessage);
message WM_CHANGECBCHAIN;
public
[font color="#000080"]
{ Public declarations }
[/font]
end;
var
Form1: TForm1;
implementation
[font color="#000080"]
{$R *.dfm}
[/font]
procedure TForm1.WMDRAWCLIPBOARD(
var Message: TMessage);
begin
ShowMessage('Inhalt der Zwischenablage wurde geöndert');
[font color="#000080"]
{ Add code here to respond to the change }
[/font]SendMessage(NextHandle, WM_DRAWCLIPBOARD, 0, 0);
end;
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, [font color="#000080"]
// handle of window to remove
[/font]
Message.lParam); [font color="#000080"]
// handle of next window
[/font]
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
ChangeClipboardChain(Handle, [font color="#000080"]
// our handle to remove
[/font]NextHandle); [font color="#000080"]
// handle of next window in the chain
[/font]
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
NextHandle := SetClipboardViewer(Handle);
end;
[/font][/font]
tom