源程序:
[此贴子已经被作者于2007-4-20 21:26:43编辑过]
[此贴子已经被作者于2007-4-20 21:26:43编辑过]
我是钩子过程函数放在dll中了,可是还不行,还有个问题就是,记事本在前台激活状态为什么用快捷键不能启动钩子过程???必须要在有钩子的程序中才能启动钩子,有什么办法可以解决吗?
代码如下:
#include <windows.h>
#pragma data_seg("MySec")
HHOOK g_hMouse=NULL;
HWND g_wnd=NULL;
HHOOK g_hKeyboard=NULL;
HWND g_hWnd=NULL;
#pragma data_seg()
LRESULT CALLBACK MouseProc( int nCode , WPARAM wParam , LPARAM lParam )
{
LPMOUSEHOOKSTRUCT pm = ( MOUSEHOOKSTRUCT FAR*)lParam;
g_wnd = pm -> hwnd;
return CallNextHookEx( g_hKeyboard , nCode , wParam , lParam );;
}
VOID CALLBACK TimerProc ( HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime)
{
PostMessage ( g_wnd , WM_KEYDOWN , 0x31 , 0 );
}
LRESULT CALLBACK KeyboardProc( int nCode , WPARAM wParam , LPARAM lParam )
{
if(VK_F2==wParam && (1==(lParam>>29&1)))
{
SetTimer ( g_hWnd , 1 , 100 , TimerProc );
}
if(VK_F3==wParam && (1==(lParam>>29&1)))
{
KillTimer ( g_hWnd , 1 );
}
return CallNextHookEx( g_hMouse , nCode , wParam , lParam );
}