http://blog.csdn.net/youthon/article/details/7327776
delphi备份恢复剪切板
看了季世平老兄的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.
delphi lazarus opengl
网页操作自动化, 图像分析破解,游戏开发