首页 > 代码库 > delphi备份恢复剪切板(使用了GlobalLock API函数和CopyMemory)
delphi备份恢复剪切板(使用了GlobalLock API函数和CopyMemory)
看了季世平老兄的C++代码后翻译过来的
[delphi] view plain copy
- 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)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。