#define _WIN32_WINNT 0x500
#include <windows.h>
static LRESULT CALLBACK hookproc(UINT nCode,WPARAM wParam,LPARAM lParam);
BOOL _stdcall InstallMyHook(HWND hWnd);
BOOL _stdcall UninstallMyHook(HWND hWnd);
HHOOK hook;
HWND hWndMain;
HINSTANCE hInst=GetModuleHandle("MouseDll.dll");
BOOL _stdcall InstallMyHook(HWND hWnd){
hook=SetWindowsHookEx(WH_MOUSE_LL,(HOOKPROC)hookproc,hInst,0);
//SetWindowsHookEx()
if(!hook)
{
DWORD reason=GetLastError();
LPCSTR tt=(LPCSTR)&reason;
//CString str;
// str.Format("%c",reason);
MessageBox(hWnd,tt,"HHOOK",MB_OK);
// OutputDebugString(reason);
return FALSE;
}
hWndMain=hWnd;
return TRUE;
} // HOOK安装
BOOL _stdcall UninstallMyHook(HWND hWnd)
{
if(hWnd != hWndMain || hWnd==NULL)
return FALSE;
BOOL unhooked=UnhookWindowsHookEx(hook);
if(unhooked)
hWndMain=NULL;
return unhooked;
}
static LRESULT CALLBACK hookproc(UINT nCode,WPARAM wParam,LPARAM lParam)
{
if(wParam == WM_MOUSEMOVE)
{
MOUSEHOOKSTRUCT *mhookstruct;
mhookstruct=(MOUSEHOOKSTRUCT*)lParam;
POINT pt=mhookstruct->pt;
PostMessage(hWndMain,WM_MOUSEMOVE,MK_CONTROL,MAKELPARAM(pt.x,pt.y));
}
return CallNextHookEx(hook,nCode,wParam,lParam);
}
#include <windows.h>
static LRESULT CALLBACK hookproc(UINT nCode,WPARAM wParam,LPARAM lParam);
BOOL _stdcall InstallMyHook(HWND hWnd);
BOOL _stdcall UninstallMyHook(HWND hWnd);
HHOOK hook;
HWND hWndMain;
HINSTANCE hInst=GetModuleHandle("MouseDll.dll");
BOOL _stdcall InstallMyHook(HWND hWnd){
hook=SetWindowsHookEx(WH_MOUSE_LL,(HOOKPROC)hookproc,hInst,0);
//SetWindowsHookEx()
if(!hook)
{
DWORD reason=GetLastError();
LPCSTR tt=(LPCSTR)&reason;
//CString str;
// str.Format("%c",reason);
MessageBox(hWnd,tt,"HHOOK",MB_OK);
// OutputDebugString(reason);
return FALSE;
}
hWndMain=hWnd;
return TRUE;
} // HOOK安装
BOOL _stdcall UninstallMyHook(HWND hWnd)
{
if(hWnd != hWndMain || hWnd==NULL)
return FALSE;
BOOL unhooked=UnhookWindowsHookEx(hook);
if(unhooked)
hWndMain=NULL;
return unhooked;
}
static LRESULT CALLBACK hookproc(UINT nCode,WPARAM wParam,LPARAM lParam)
{
if(wParam == WM_MOUSEMOVE)
{
MOUSEHOOKSTRUCT *mhookstruct;
mhookstruct=(MOUSEHOOKSTRUCT*)lParam;
POINT pt=mhookstruct->pt;
PostMessage(hWndMain,WM_MOUSEMOVE,MK_CONTROL,MAKELPARAM(pt.x,pt.y));
}
return CallNextHookEx(hook,nCode,wParam,lParam);
}