HOOK获取鼠标信息 谢谢大家200分 ( 积分: 100 )

  • 主题发起人 主题发起人 lxxiaoxiao
  • 开始时间 开始时间
L

lxxiaoxiao

Unregistered / Unconfirmed
GUEST, unregistred user!
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <stdio.h>
#include <tlhelp32.h>
#include &quot;Unit1.h&quot;
#include <winuser.h>
#include <windows.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm1 *Form1;
long sbx,sby;
HOOKPROC JournalLogProc(int iCode,WPARAM wParam,LPARAM lParam);
//钩子变量
HHOOK g_hLogHook=NULL;
//记录上一次得到焦点的窗口句柄
HWND g_hLastFocus=NULL;
//键盘掩码变量
const int KeyPressMask=0x80000000;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
HOOKPROC JournalLogProc(int iCode,WPARAM wParam,LPARAM lParam)
{
if(iCode<0)
{
return (HOOKPROC)CallNextHookEx(g_hLogHook,iCode,wParam,lParam);
}
PMOUSEHOOKSTRUCT mouse = (PMOUSEHOOKSTRUCT)lParam;
POINT p = mouse->pt;
sbx = p.x;
sby = p.y;
return (HOOKPROC)CallNextHookEx(g_hLogHook,iCode,wParam,lParam);
}
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Edit1->Text = AnsiString(sbx)+&quot;,&quot;+AnsiString(sby);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
if(g_hLogHook==NULL)//安装日志钩子
{
g_hLogHook=SetWindowsHookEx(WH_JOURNALRECORD,(HOOKPROC)JournalLogProc,HInstance,0);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &amp;Action)
{
if(g_hLogHook!=NULL)
{
UnhookWindowsHookEx(g_hLogHook);
g_hLogHook=NULL;
}
}
//---------------------------------------------------------------------------
 
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <stdio.h>
#include <tlhelp32.h>
#include &quot;Unit1.h&quot;
#include <winuser.h>
#include <windows.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm1 *Form1;
long sbx,sby;
HOOKPROC JournalLogProc(int iCode,WPARAM wParam,LPARAM lParam);
//钩子变量
HHOOK g_hLogHook=NULL;
//记录上一次得到焦点的窗口句柄
HWND g_hLastFocus=NULL;
//键盘掩码变量
const int KeyPressMask=0x80000000;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
HOOKPROC JournalLogProc(int iCode,WPARAM wParam,LPARAM lParam)
{
if(iCode<0)
{
return (HOOKPROC)CallNextHookEx(g_hLogHook,iCode,wParam,lParam);
}
PMOUSEHOOKSTRUCT mouse = (PMOUSEHOOKSTRUCT)lParam;
POINT p = mouse->pt;
sbx = p.x;
sby = p.y;
return (HOOKPROC)CallNextHookEx(g_hLogHook,iCode,wParam,lParam);
}
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Edit1->Text = AnsiString(sbx)+&quot;,&quot;+AnsiString(sby);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
if(g_hLogHook==NULL)//安装日志钩子
{
g_hLogHook=SetWindowsHookEx(WH_JOURNALRECORD,(HOOKPROC)JournalLogProc,HInstance,0);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &amp;Action)
{
if(g_hLogHook!=NULL)
{
UnhookWindowsHookEx(g_hLogHook);
g_hLogHook=NULL;
}
}
//---------------------------------------------------------------------------
 
现在上面的代码 只能记录Y的坐标 没有X的坐标
 
g_hLogHook=SetWindowsHookEx(WH_MOUSE,(HOOKPROC)JournalLogProc,HInstance,0);
 
我写成迷糊所给的答案了 但是 现在Y的坐标也没了
 
后退
顶部