Startseite ¦  was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews ¦  sonstiges
kylix ¦  tutorials ¦  online shop ¦  fotos ¦  Add&Win Gewinnspiel


Willkommen Gast. Bitte einloggen oder registrieren.
21.05.2012, 11:53:13
Übersicht Hilfe Suche Einloggen Registrieren

+  SwissDelphiCenter Forum
|-+  German Forums
| |-+  WinAPI Forum
| | |-+  Abfangen, ob etwas in den Zwischenspeicher kopiert wurde
« vorheriges nächstes »
Seiten: [1] Drucken
Autor Thema: Abfangen, ob etwas in den Zwischenspeicher kopiert wurde  (Gelesen 1669 mal)
BRAiNCrusher
Jr. Member
**
Offline Offline

Beiträge: 74



WWW
« am: 18.07.2002, 12:36:46 »

Gibt es einen Möglichkeit ein EVENT zu erstellen, das es mir ermöglicht, sobald (Systemweit) etwas in den Zwischenspeicher kopiert wurde darauf zu reagieren ?

thx im Vorraus
Gespeichert

wwerner
Gast
« Antworten #1 am: 18.07.2002, 12:57:35 »

[font  size=2 face="Courier New" color="#000000"]unit Unit1;
[font color="#000080"]{in dcld* gepostet von Gerd Kayser}

[/font]interface

uses
  
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs,
  StdCtrls, ExtCtrls, ComCtrls;

type
  
TForm1 = class(TForm)
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  private
    
[font color="#000080"]{ Private-Deklarationen }
  
[/font]public
    
[font color="#000080"]{ Public-Deklarationen }
    
[/font]procedure WMChangeCbChain(var Msg: TMessage); message wm_ChangeCbChain;
    procedure WMDrawClipboard(var Msg: TMessage); message wm_DrawClipboard;
  end;

var
  
Form1: TForm1;
  NextClipboardViewer: Integer;

implementation

[font color="#000080"]{$R *.DFM}

[/font]procedure TForm1.WMChangeCbChain(var Msg: TMessage);
begin
  if 
Msg.wParam = NextClipboardViewer then
    
NextClipboardViewer := Msg.lParam
  else
    
SendMessage(NextClipboardViewer, wm_ChangeCbChain, Msg.wParam, Msg.lParam);
end;

procedure TForm1.WMDrawClipboard(var Msg: TMessage);
begin
  
SendMessage(NextClipboardViewer, wm_DrawClipboard, Msg.wParam, Msg.lParam);
  Label1.Caption := 'Clipboard geändert um: ' + TimeToStr(Now);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  
NextClipboardViewer := SetClipboardViewer(Form1.Handle);
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  
ChangeClipboardChain(Form1.Handle, NextClipboardViewer);
end;

end.
[/font]
Gespeichert
Thomas Stutz
Global Moderator
Hero Member
*****
Offline Offline

Beiträge: 1784



WWW
« Antworten #2 am: 18.07.2002, 13:04:06 »

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:

Zitat

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.

Zitat
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:

Code:

procedure TForm1.FormCreate(Sender: TObject);

begin

  NextHandle := SetClipboardViewer(handle);

end;



Erklärung:

NextHandle ist das Handle zum nächsten ClipboardViewer.

Zitat
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:

Code:
private

  procedure WMDRAWCLIPBOARD(var Message: TMessage); message  WM_DRAWCLIPBOARD;


im Implementation Teil:

Code:
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:

Zitat
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:

Code:
private

  procedure WMCHANGECBCHAIN(var Message: TMessage); message WM_CHANGECBCHAIN;


im Implementation Teil:

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;



Bevor die App beendet wird, muss die App von der ClipBoardViewer Kette
entfernt werden. Dies kannst du z.B im OnDestroy machen.

Zitat


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:


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
Gespeichert

(¯`·._tom_.·´¯)

Tipp: Viele Antworten auf Fragen gibt's hier:
http://www.swissdelphicenter.ch/de/tipsuchen.php
BRAiNCrusher
Jr. Member
**
Offline Offline

Beiträge: 74



WWW
« Antworten #3 am: 18.07.2002, 17:09:22 »

Stimmt Zwischenablage meinte ich =)
big thx..genau das suchte ich...vielen lieben Dank
Gespeichert

Seiten: [1] Drucken 
« vorheriges nächstes »
Gehe zu:  


Einloggen mit Benutzername, Passwort und Sitzungslänge

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006, Simple Machines LLC Prüfe XHTML 1.0 Prüfe CSS