Mega Code Archive

 
Categories / Delphi / Examples
 

Clipboard gösterici

unit Clipvuu; interface uses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) Memo1: TMemo; ScrollBox1: TScrollBox; Image1: TImage; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } PrevHwnd : Hwnd; procedure WMChangeCBChain(VAR Msg: TWMChangeCBChain); message WM_CHANGECBCHAIN; procedure WMDrawClipboard(VAR Msg: TWMDrawClipboard); message WM_DRAWCLIPBOARD; public { Public declarations } end; var Form1: TForm1; implementation uses ClipBrd; {$R *.DFM} procedure TForm1.FormCreate(Sender: TObject); begin PrevHwnd := SetClipboardViewer(Handle); end; procedure TForm1.FormDestroy(Sender: TObject); begin ChangeClipboardChain(Handle, PrevHwnd); end; procedure TForm1.WMChangeCBChain(VAR Msg: TWMChangeCBChain); begin {If previous viewer is being removed, "patch" around it} IF PrevHWnd = Msg.Remove THEN PrevHWnd := Msg.Next; {If not SELF being removed, pass along the message} IF Msg.Remove <> Handle THEN SendMessage(PrevHWnd, WM_CHANGECBCHAIN, Msg.Remove, Msg.Next); end; procedure TForm1.WMDrawClipboard(VAR Msg: TWMDrawClipboard); VAR H : THandle; begin {pass along the message} WITH TMessage(Msg) DO SendMessage(PrevHWnd, WM_DRAWCLIPBOARD, wParam, lParam); IF Clipboard.HasFormat(CF_PICTURE) THEN BEGIN ScrollBox1.BringToFront; Image1.Picture.Assign(Clipboard); END ELSE IF Clipboard.HasFormat(CF_TEXT) THEN BEGIN Memo1.BringToFront; Memo1.Font.Color := clWindowText; {$IFDEF Win32} Memo1.Text := Clipboard.AsText; {$ELSE} H := Clipboard.GetAsHandle(CF_TEXT); Memo1.SetTextBuf(GlobalLock(H)); GlobalUnlock(H); {$ENDIF} END ELSE BEGIN Memo1.BringToFront; Memo1.Font.Color := clGrayText; Memo1.Lines.Insert(0,'(no text or bitmap in clipboard)'); END; Msg.Result := 0; end; end.