Executable
--------------------------
#include <windows.h>
#include <iostream>
extern "C" __declspec(dllimport) void InstallHook( );
extern "C" __declspec(dllimport) void UnInstallHook( );
extern "C" __declspec(dllimport) void GetX( int *px );
extern "C" __declspec(dllimport) void GetY( int *py );
int main()
{
int x, y;
InstallHook( );
do
{
GetX(&x);
GetY(&y);
std::cout << x << '\t' << y << std::endl;
// Nothing
}while( (x >= 5) && (y >= 5) );
UnInstallHook();
return 0;
}
--------------------------
DLL
--------------------------
#include <windows.h>
HHOOK hhk;
HINSTANCE dllInstance;
bool shown;
HWND shell;
HWND button;
RECT startRect;
int x = 10, y = 10;
LRESULT CALLBACK myMouseProc(int code, WPARAM wParam, LPARAM lParam);
extern "C"
{
__declspec(dllexport) void InstallHook( );
__declspec(dllexport) void UnInstallHook( );
__declspec(dllexport) void GetY( int *py );
__declspec(dllexport) void GetX( int *px );
}
BOOL WINAPI DllMain(HINSTANCE hInstance,DWORD fwdReason, LPVOID lpvReserved)
{
dllInstance = hInstance;
shown = true;
shell = FindWindow(L"Shell_TrayWnd", NULL);
button = FindWindowEx(shell, NULL, L"button", NULL);
GetWindowRect(button, &startRect); // Store the windows's rectangle in this rect.
return(TRUE);
}
extern "C" __declspec(dllexport) void InstallHook( )
{
hhk = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)&myMouseProc, dllInstance , NULL );
}
extern "C" __declspec(dllexport) void UnInstallHook( )
{
if( !UnhookWindowsHookEx( hhk ) )
MessageBox(NULL, L"NOT Uninstalled Bitch!", L"Yay!", MB_OK);
}
extern "C" __declspec(dllexport) void GetX( int *px )
{
*px = x;
}
extern "C" __declspec(dllexport) void GetY( int *py )
{
*py = y;
}
LRESULT CALLBACK myMouseProc(int code, WPARAM wParam, LPARAM lParam)
{
MOUSEHOOKSTRUCT * mouse_hook = (MOUSEHOOKSTRUCT *)(lParam);
if (code < 0) // do not process message
return CallNextHookEx(hhk, code, wParam, lParam);
x = (int)mouse_hook->pt.x;
y = (int)mouse_hook->pt.y;
if( (x > (startRect.left - 1 ) ) && (x < startRect.right) )
{
if ( (y > startRect.top) && (y < startRect.bottom) )
ShowWindow(button, 0);
}
else
ShowWindow(button, 1);
return(CallNextHookEx( hhk, code, wParam, lParam ) );
}