1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| // MouseHook.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#define _COMPILING_44E531B1_14D3_11d5_A025_006067718D04
#include "MouseHook.h"
#pragma data_seg(".JOE")
HWND hWndServer = NULL;
//POINT position = {0,0};
#pragma data_seg()
#pragma comment(linker, "/section:.JOE,rws")
HINSTANCE hInst;
UINT UWM_MOUSEMOVE;
HHOOK hook;
static LRESULT CALLBACK msghook(UINT nCode, WPARAM wParam, LPARAM lParam);
BOOL APIENTRY DllMain( HINSTANCE hInstance,
DWORD Reason,
LPVOID Reserved
)
{
switch(Reason)
{ /* reason */
case DLL_PROCESS_ATTACH:
hInst = hInstance;
UWM_MOUSEMOVE = RegisterWindowMessage(UWM_MOUSEMOVE_MSG);
return TRUE;
case DLL_PROCESS_DETACH:
if(hWndServer != NULL)
clearMyHook(hWndServer);
return TRUE;
} /* reason */
return TRUE;
}
/****************************************************************************
* setMyHook
* Inputs:
* HWND hWnd: Window to notify
* Result: BOOL
* TRUE if successful
* FALSE if error
* Effect:
* Sets the hook
****************************************************************************/
__declspec(dllexport) BOOL setMyHook(HWND hWnd)
{
if(hWndServer != NULL)
return FALSE; // already hooked!
hook = SetWindowsHookEx(WH_GETMESSAGE,
(HOOKPROC)msghook,
hInst,
0);
if(hook != NULL)
{ /* success */
hWndServer = hWnd;
return TRUE;
} /* success */
return FALSE; // failed to set hook
} // setMyHook
/****************************************************************************
* clearMyHook
* Inputs:
* HWND hWnd: Window hook
* Result: BOOL
* TRUE if successful
* FALSE if error
* Effect:
* Removes the hook that has been set
****************************************************************************/
__declspec(dllexport) BOOL clearMyHook(HWND hWnd)
{
if(hWnd != hWndServer || hWnd == NULL)
return FALSE;
BOOL unhooked = UnhookWindowsHookEx(hook);
if(unhooked)
hWndServer = NULL;
return unhooked;
} // clearMyHook
/****************************************************************************
* msghook
* Inputs:
* int nCode: Code value
* WPARAM wParam:
* LPARAM lParam:
* Result: LRESULT
* Either 0 or the result of CallNextHookEx
* Effect:
* Hook processing function. If the message is a mouse-move message,
* posts the coordinates to the parent window
****************************************************************************/
static LRESULT CALLBACK msghook(UINT nCode, WPARAM wParam, LPARAM lParam)
{
if(nCode < 0)
{ /* pass it on */
CallNextHookEx(hook, nCode, wParam, lParam);
return 0;
} /* pass it on */
POINT pos;
LPMSG msg = (LPMSG)lParam;
if(msg->message == WM_LBUTTONDOWN)
{
GetCursorPos(&pos);
if (pos.x<500)
{
PostMessage(hWndServer, UWM_MOUSEMOVE, 0, 0);
return 1;
}
}
return CallNextHookEx(hook, nCode, wParam, lParam);
} // msghook |
Partager