home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 13
/
mediashare_13.zip
/
mediashare_13
/
ZIPPED
/
PROGRAM
/
WTJ9403.ZIP
/
WILDASS
/
SOURCE
/
HOOKSDLL.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-14
|
6KB
|
172 lines
// mshoook.cpp
//
// (de)install the mouse hook fxn
//
// update: 1.00 08-Aug-93 tw
// 1.01 14-Aug-93 tw removed bug in MouseHookProc
#include <windows.h>
#include "hooksdll.h"
// dll fxns
int __export CALLBACK LibMain( HANDLE hModule, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine);
// int __export CALLBACK _WEP( int bSystemExit);
// WEP is optional in win 3.1
void __export CALLBACK MouseHookFunc( int nCode, WORD wParam, DWORD lParam);
// global vars for inside mosue hook dll
HANDLE msHookDLL_hInstance; // Global instance handle for DLL
HHOOK msHookDLL_hhookHooks; // last mouse hook
HWND msHookDLL_wndDektop; // Handle of DesktopWindow
HWND msHookDLL_wndApplication;// Handle of Application Window
BOOL msHookDLL_fComeUpAllways = FALSE; // default: only come up when dsktop is clicked
#ifdef _DEBUG
BOOL msHookDLL_fInitCalled = FALSE; // in debug version, make sure init was called
#endif
// dll do-nothint stuff
int __export CALLBACK
LibMain( HANDLE hModule, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine)
{
msHookDLL_hInstance = hModule; // store instance handle
return 1;
}
// WEP is optional in win 3.1
// as we don`t need no cleanup,.... skip it
//int __export
//CALLBACK _WEP (int bSystemExit)
//{
// return 1;
//}
void __export CALLBACK
MsHookDLL_InitDLL( HWND wndApplication )
{
// make sure debugging version doesnt assert
#ifdef _DEBUG
msHookDLL_fInitCalled = TRUE;
#endif
// store handle to Desktop window
msHookDLL_wndDektop = GetDesktopWindow();
// store handle to application window
msHookDLL_wndApplication = wndApplication;
}
// InstallFilter()
//
// (de)install the mouse message filter.
// store the previous mouse hook fxn
//
// in the debugging version, make sure InitMsHook() has been called
//
void __export CALLBACK
MsHookDLL_InstallFilter( BOOL fCode )
{
// make sure init was called before
#ifdef _DEBUG
if( ! msHookDLL_fInitCalled )
OutputDebugString("MsHookDLL_SetComUpParam: InitDLL not called prior to usage\n");
#endif
if ( fCode ) // install the filter
{
msHookDLL_hhookHooks = SetWindowsHookEx( WH_MOUSE, (FARPROC) MouseHookFunc, msHookDLL_hInstance, NULL );
}
else // remove the filter
{
UnhookWindowsHookEx( msHookDLL_hhookHooks );
}
}
// set the behaviour: should we come up on every right
// mouse click or only when clicked upon the desktop...
void __export CALLBACK
MsHookDLL_SetComeUpAllways( BOOL fCode )
{
// make sure init was called before
#ifdef _DEBUG
if( ! msHookDLL_fInitCalled )
OutputDebugString("MsHookDLL_SetComUpParam: InitDLL not called prior to usage\n");
#endif
// set the behaviour
msHookDLL_fComeUpAllways = fCode;
}
// MouseHookFunc
//
// Handle mouse messages
//
// update 1.01 - removed bug that caused the windowpos to be calculated
// relativ to the window beeing clicked upon; not relativ
// to the desktop window
void __export CALLBACK
MouseHookFunc( int nCode, WORD wParam, DWORD lParam )
{
if ( nCode >= 0 )
{
if ( wParam == WM_RBUTTONDOWN )
{
LPMOUSEHOOKSTRUCT pMSH = (LPMOUSEHOOKSTRUCT)lParam;
// if this is the desktop beeing clicked, come up ...
// that is, come up always when the behaviour is set this way ...
if ( ( msHookDLL_fComeUpAllways ) ||
( ! msHookDLL_fComeUpAllways && (pMSH->hwnd == msHookDLL_wndDektop) ) )
{
// get our size
RECT rectWindow;
GetWindowRect( msHookDLL_wndApplication, &rectWindow );
// take care all of us is _visible_, not parts
// outside the desktop ...
// the point clicked can`t possibly be out of of
// view, so check if the right and lower edges are within
// the desktop window ranges. if not, move the window so
// it is completelyy visible
RECT rectDesktop;
GetWindowRect( msHookDLL_wndDektop, &rectDesktop );
int cxWindow = rectWindow.right - rectWindow.left;
int cyWindow = rectWindow.bottom - rectWindow.top;
int x = pMSH->pt.x;
int y = pMSH->pt.y;
int dx = rectDesktop.right - (x+cxWindow);
dx = dx < 0 ? dx : 0;
int dy = rectDesktop.bottom - (y+cyWindow);
dy = dy < 0 ? dy : 0;
// move the window to some appropriate place
MoveWindow( msHookDLL_wndApplication, x+dx, y+dy,
cxWindow, cyWindow, TRUE );
// if we are already visible, no need to call ShowWindow ...
if ( ! IsWindowVisible( msHookDLL_wndApplication ) )
ShowWindow( msHookDLL_wndApplication, SW_SHOWNORMAL );
// make sure we have focus
SetFocus( msHookDLL_wndApplication );
// throw away the message ....
// this will make sure noone else is coming up
// because of this message
return;
}
}
}
// make sure other hooks are called for
// the other messages ...
CallNextHookEx( msHookDLL_hhookHooks, nCode, wParam, lParam);
}