yingkit
asked on
Clipboard backup
Hi there,
How can I make a copy of the content of the clipboard in the memory? And how to restore the clipboard from the copy?
Thanks in advance.
PS. The content of the clipboard can be anything, not necessarily text
How can I make a copy of the content of the clipboard in the memory? And how to restore the clipboard from the copy?
Thanks in advance.
PS. The content of the clipboard can be anything, not necessarily text
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you all.
var
MyHandle: THandle;
TextPtr: PChar;
MyString: string;
begin
ClipBoard.Open;
try
MyHandle := Clipboard.GetAsHandle(CF_T
TextPtr := GlobalLock(MyHandle);
MyString := StrPas(TextPtr);
GlobalUnlock(MyHandle);
finally
Clipboard.Close;
end;
end;
procedure TForm1.Button1Click(Sender
var
MyFormat : Word;
Bitmap : TBitMap;
AData,APalette : THandle;
begin
Bitmap := TBitmap.Create;
try
Bitmap.LoadFromFile('c:\Pr
Bitmap.SaveToClipBoardForm
ClipBoard.SetAsHandle(MyFo
finally
Bitmap.Free;
end;
end;
If, OTOH, you've got this stuff down & just need to know when to get the data (as there are no events for TClipboard) you would then need to register a clipBoardViewer:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, clipbrd;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
nextViewer : HWND;
procedure doWMDRAWCLIPBOARD(var msg : TWMDRAWCLIPBOARD);message WM_DRAWCLIPBOARD;
procedure doWMCHANGECBCHAIN(var msg : TWMCHANGECBCHAIN);message WM_CHANGECBCHAIN;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
nextViewer := setClipBoardViewer(handle)
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
changeClipBoardChain(handl
end;
procedure TForm1.doWMCHANGECBCHAIN(v
begin
if msg.remove = nextViewer then
nextViewer := msg.Next
else
sendMessage(nextViewer,WM_
end;
procedure TForm1.doWMDRAWCLIPBOARD(v
begin
//this proc will get called anytime anything get's added
//to the clipboard. From here you can query the cb as to
//current formats & data & such, as seen above
end;
end.
GL
Mike