钩子的问题!尊敬的朋友们,请看看我的程序到底那里错了,请帮忙指正!——分数立竿见影!

fellowcheung 2004-02-21 02:59:24
//CPP文件-----------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unt_HookProc.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
THookForm *HookForm;

EVENTMSG EventArr[1001];
int EventLog;
int PlayLog;
HHOOK hHook,hPlay;
int recOK;
int canPlay;
int Result;
bool bDelay;

//---------------------------------------------------------------------------
__fastcall THookForm::THookForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
LRESULT __stdcall PlayProc(int iCode, WPARAM wParam, LPARAM lParam)
{
canPlay = 1;
Result = 0;
if (iCode < 0)
Result = CallNextHookEx(hPlay, iCode, wParam, lParam);
else
if (iCode == HC_SYSMODALON)
canPlay = 0;
else
if (iCode == HC_SYSMODALOFF)
canPlay = 1;
else
if (canPlay == 1 && iCode == HC_GETNEXT)
{
if (bDelay)
{
bDelay = false;
Result = 50;
}
(EVENTMSG&)lParam = EventArr[PlayLog];
}
else
if (canPlay == 1 && iCode == HC_SKIP)
{
bDelay = true;
PlayLog ++;
}
if (PlayLog >= EventLog)
UnhookWindowsHookEx(hPlay);
return (LRESULT)Result;
}
//---------------------------------------------------------------------------
LRESULT __stdcall HookProc(int iCode, WPARAM wParam, LPARAM lParam)
{
recOK = 1;
Result = 0;
if (iCode < 0)
Result = CallNextHookEx(hHook, iCode, wParam, lParam);
else
if (iCode == HC_SYSMODALON)
recOK = 0;
else
if (iCode == HC_SYSMODALOFF)
recOK = 1;
else
if (recOK > 0 && iCode == HC_ACTION)
{
EventArr[EventLog] = (EVENTMSG&)lParam;
EventLog ++;
if (EventLog >= 1000)
UnhookWindowsHookEx(hHook);
}
return (LRESULT)Result;
}
//---------------------------------------------------------------------------
void __fastcall THookForm::FormShow(TObject *Sender)
{
Button1->Caption = "记录";
Button2->Caption = "停止";
Button3->Caption = "回放";
Button4->Caption = "范例";
Button2->Enabled = false;
Button4->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall THookForm::Button1Click(TObject *Sender)
{
EventLog = 0;
hHook = SetWindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, 0);
Button2->Enabled = true;
Button1->Enabled = !Button2->Enabled;
}
//---------------------------------------------------------------------------
void __fastcall THookForm::Button2Click(TObject *Sender)
{
UnhookWindowsHookEx(hHook);
hHook = 0;
Button1->Enabled = true;
Button2->Enabled = !Button1->Enabled;
Button3->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall THookForm::Button3Click(TObject *Sender)
{
PlayLog = 0;
hPlay = SetWindowsHookEx(WH_JOURNALPLAYBACK, PlayProc, HInstance, 0);
Button3->Enabled = false;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//H头文件-----------------------------------------------------------------

#ifndef Unt_HookProcH
#define Unt_HookProcH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Windows.hpp>
#include <Messages.hpp>
#include <SysUtils.hpp>
//---------------------------------------------------------------------------
class THookForm : public TForm
{
__published: // IDE-managed Components
TEdit *Edit1;
TButton *Button1;
TButton *Button2;
TButton *Button3;
TButton *Button4;
void __fastcall FormShow(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
void __fastcall Button3Click(TObject *Sender);
private: // User declarations

LRESULT __stdcall PlayProc(int iCode, WPARAM wParam, LPARAM lParam);
LRESULT __stdcall HookProc(int iCode, WPARAM wParam, LPARAM lParam);

public: // User declarations
__fastcall THookForm(TComponent* Owner);


};
//---------------------------------------------------------------------------
extern PACKAGE THookForm *HookForm;
//---------------------------------------------------------------------------
#endif
...全文
33 点赞 收藏 12
写回复
12 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复

还没有回复,快来抢沙发~

相关推荐
发帖
Windows SDK/API
创建于2007-08-02

1206

社区成员

C++ Builder Windows SDK/API
申请成为版主
帖子事件
创建了帖子
2004-02-21 02:59
社区公告
暂无公告