Mousehook1.cpp
上传用户:qzzxgm
上传日期:2009-12-14
资源大小:1882k
文件大小:1k
- // Mousehook1.cpp: implementation of the CMousehook class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Mousehook1.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- #pragma data_seg("mydata")
- HWND glhPrevTarWnd=NULL;//上次鼠标所指的窗口句柄
- HWND glhDisplayWnd=NULL;//显示目标窗口标题编辑框的句柄
- HHOOK glhHook=NULL;//安装的鼠标勾子句柄
- HINSTANCE glhInstance=NULL;//DLL实例句柄
- #pragma data_seg()
- CMousehook::CMousehook()
- {
-
- }
- CMousehook::~CMousehook()
- {
- stophook();
- }
- BOOL CMousehook::starthook(HWND hWnd)
- {
- //安装钩子并设定接收显示窗口句柄
- BOOL bResult=FALSE;
- glhHook=SetWindowsHookEx(WH_MOUSE,MouseProc,glhInstance,0);
- if(glhHook!=NULL)
- bResult=TRUE;
- //设置显示目标窗口标题编辑框的句柄
- glhDisplayWnd=hWnd;
- return bResult;
- }
- BOOL CMousehook::stophook()
- {
- //卸载钩子
- BOOL bResult=FALSE;
- if(glhHook)
- bResult= UnhookWindowsHookEx(glhHook);
- if(bResult)
- {
- glhPrevTarWnd=NULL;
- glhDisplayWnd=NULL;//清变量
- glhHook=NULL;
- }
- return bResult;
- }