我已经做了一个简单的软件,代码很简单,只是用了一下注册热键而已。希望大家见谅。呵呵^_^
unit clipboard;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ComCtrls, IniFiles, ClipBrd;
const
TabNum = 9;
//数字键的最大数字
type
RcdHotKey = record //记录热键和对应的剪贴板内容
HotKeyId: Integer;
MemoText: String;
end;
TForm1 = class(TForm)
PCtrlMemo: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
TabSheet4: TTabSheet;
TabSheet5: TTabSheet;
Btn_Reset: TBitBtn;
Btn_Modify: TBitBtn;
TabSheet6: TTabSheet;
Memo1: TMemo;
Memo2: TMemo;
Memo3: TMemo;
Memo4: TMemo;
Memo5: TMemo;
Memo6: TMemo;
TabSheet7: TTabSheet;
TabSheet8: TTabSheet;
TabSheet9: TTabSheet;
Memo7: TMemo;
Memo8: TMemo;
Memo9: TMemo;
procedure FormCreate(Sender: TObject);
procedure Btn_ModifyClick(Sender: TObject);
procedure Btn_ResetClick(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
AryHotKey: array[1..TabNum] of RcdHotKey;
//记录各个热键和它对应的
//剪贴板内容
procedure ClipHotKeyHandle(var HotKeyMsg: TMessage);message WM_HOTKEY;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
FilePath, IniPath: String;
procedure TForm1.FormCreate(Sender: TObject);
var
ClipInit: TIniFile;
ClipFile: File;
//链接ClipIni
I, TagMemo: Integer;
//tagMemo 是Memo的Tag
TabSheet: TTabSheet;
//用于读取IniFile中的Memo值
begin
//根据ClipInit.ini初始化窗口;
FilePath:= ExtractFilePath(Application.ExeName);
IniPath:= FilePath + 'ClipInit.Ini';
AssignFile(ClipFile,IniPath);
if not FileExists(IniPath) then
begin
ReWrite(ClipFile);
CloseFile(ClipFile);
end;
//if
Try
ClipInit:= TIniFile.Create(IniPath);
if not ClipInit.SectionExists('Memo') then
begin
for I:= 0 to PCtrlMemo.ControlCount - 1 do
if (PCtrlMemo.Controls.ClassName = 'TTabSheet') then
begin
TabSheet:= PCtrlMemo.Controls as TTabSheet;
TagMemo:= (TabSheet.Controls[0] as TMemo).Tag;
(TabSheet.Controls[0] as TMemo).Clear;
AryHotKey[TagMemo].MemoText:= '';
end;
//if
end// if not
else
if ClipInit.SectionExists('Memo') then
begin
for I:= 0 to PCtrlMemo.ControlCount -1do
if (PCtrlMemo.Controls.ClassName = 'TTabSheet') then
begin
TabSheet:= PCtrlMemo.Controls as TTabSheet;
TagMemo:= (TabSheet.Controls[0] as TMemo).Tag;
(TabSheet.Controls[0] as TMemo).Text :=
ClipInit.ReadString('Memo',
'Memo' + IntToStr(TagMemo),'');
AryHotKey[TagMemo].MemoText:=
(TabSheet.Controls[0] as TMemo).Text;
end;
//if
end;
//else
if
finally
ClipInit.Free;
end;
//默认各个窗口不可用;
PCtrlMemo.Enabled:= False;
Btn_Reset.Enabled:= False;
end;
procedure TForm1.Btn_ModifyClick(Sender: TObject);
begin
PCtrlMemo.Enabled:= True;
Btn_Modify.Enabled:= True;
Btn_Reset.Enabled:= True;
end;
procedure TForm1.Btn_ResetClick(Sender: TObject);
var
ClipIni: TIniFile;
I, TagMemo: Integer;
TabSheet: TTabSheet;
begin
ClipIni:= TIniFile.Create(IniPath);
if ClipIni.SectionExists('Memo') then
ClipIni.EraseSection('Memo');
for I:= 0 to PCtrlMemo.ControlCount -1do
begin
if PCtrlMemo.Controls.ClassName = 'TTabSheet' then
begin
TabSheet:= PCtrlMemo.Controls as TTabSheet;
TagMemo:= (TabSheet.Controls[0] as TMemo).Tag;
ClipIni.WriteString('Memo',
'Memo'+ IntToStr(TagMemo),
(TabSheet.Controls[0] as TMemo).Text);
AryHotKey[TagMemo].MemoText:=
(TabSheet.Controls[0] as TMemo).Text;
end;
end;
//重置各个按钮的状态
PCtrlMemo.Enabled:= False;
Btn_ReSet.Enabled:= False;
Btn_Modify.Enabled:= True;
end;
procedure TForm1.FormResize(Sender: TObject);
var
I: Integer;
begin
for I:= 1 to TabNumdo
begin
AryHotKey.HotKeyId:=
GlobalAddAtom(Pchar('ClipBoardHotKey'+IntToStr(I)));
RegisterHotKey(Handle,AryHotKey.HotKeyId,MOD_CONTROL,48+I);//48是0
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
var
I: Integer;
begin
for I:= 1 to TabNumdo
begin
UnRegisterHotKey(Handle,AryHotKey.HotKeyId);
end;
//for
end;
procedure TForm1.ClipHotKeyHandle(var HotKeyMsg: TMessage);
var
MyClipBoard: TClipBoard;
KeyPress: Integer;
//用户按下的健
begin
Try
MyClipBoard:= TClipBoard.Create;
KeyPress:= HotKeyMsg.LParamHi - 48;
MyClipBoard.AsText:= AryHotKey[KeyPress].MemoText;
finally
MyClipBoard.Free;
end;
end;
end.