delphi备份恢复剪切板(使用了GlobalLock API函数和CopyMemory)
Posted 朝闻道
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了delphi备份恢复剪切板(使用了GlobalLock API函数和CopyMemory)相关的知识,希望对你有一定的参考价值。
看了季世平老兄的C++代码后翻译过来的
- unit clipbak;
- interface
- uses
- SysUtils, Classes, Clipbrd, Windows, Contnrs;
- type
- TClipData = class
- Format: WORD;
- Data: THANDLE;
- end;
- TClipBackuper = class
- private
- ClipList: TList;
- public
- constructor Create;
- destructor Destroy; override;
- procedure BackupClip();
- procedure RestoreClip();
- end;
- implementation
- constructor TClipBackuper.Create;
- begin
- Cliplist := TObjectList.Create;
- end;
- destructor TClipBackuper.Destroy;
- begin
- ClipList.Free;
- end;
- procedure TClipBackuper.BackupClip;
- var
- i: Integer;
- Data: THANDLE;
- pcd: TClipData;
- DataMem: Pointer;
- begin
- ClipList.Clear();
- Clipboard.Open();
- try
- for i := 0 to Clipboard().FormatCount - 1 do
- begin
- pcd := TClipData.Create;
- pcd.Format := Clipboard().Formats[i];
- Data := THANDLE(Clipboard().GetAsHandle( pcd.Format));
- if (Data = 0) then
- begin
- pcd.free;
- continue;
- end;
- pcd.Data := GlobalAlloc(GMEM_MOVEABLE or GMEM_DDESHARE, GlobalSize(Data));
- DataMem := GlobalLock(pcd.Data);
- if (DataMem <> nil) then
- begin
- CopyMemory(DataMem, GlobalLock(Data), GlobalSize(Data));
- GlobalUnlock(THANDLE(pcd.Data));
- GlobalUnlock(THANDLE(Data));
- end;
- ClipList.Add(pcd);
- end;
- finally
- Clipboard().Close();
- end;
- end;
- procedure TClipBackuper.RestoreClip;
- var
- pcd: TClipData;
- i: Integer;
- begin
- Clipboard.Open();
- try
- Clipboard.Clear();
- for i := 0 to ClipList.Count - 1 do
- begin
- pcd := TClipData(ClipList[i]);
- SetClipboardData(pcd.Format, pcd.Data);
- end;
- ClipList.Clear();
- finally
- Clipboard().Close();
- end;
- end;
- end.
http://blog.csdn.net/youthon/article/details/7327776
以上是关于delphi备份恢复剪切板(使用了GlobalLock API函数和CopyMemory)的主要内容,如果未能解决你的问题,请参考以下文章