GetClipCursor(&m_Rc);
m_Rc.left=0;
m_Rc.top=0;
m_Rc.right=0;
m_Rc.bottom=0;
if(!ClipCursor(&m_Rc))
{
.........
}
各位哥哥姐姐,小弟那里出错了?(运行于win2000adserver)
m_Rc.left=0;
m_Rc.top=0;
m_Rc.right=0;
m_Rc.bottom=0;
if(!ClipCursor(&m_Rc))
{
.........
}
各位哥哥姐姐,小弟那里出错了?(运行于win2000adserver)
win2000 5.00.2195
锁定键盘和鼠标的钩子
DLL端
// HOOK.cpp : Defines the entry point for the DLL application.
//#include "stdafx.h"
#include "HOOK.h"
#include "mmsystem.h"
#define _WIN32_WINNT 0x0500 #include <windows.h>
#include <winuser.h>
HINSTANCE hInstance;
HHOOK hhkKeyboard;
HHOOK hhMouseHook;BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
hInstance=(HINSTANCE)hModule;
return TRUE;
}
// This is an example of an exported variable
HOOK_API int nHOOK=0;// This is an example of an exported function.
HOOK_API int fnHOOK(void)
{
return 42;
}// This is the constructor of a class that has been exported.
// see HOOK.h for the class definition
CHOOK::CHOOK()
{
return;
}LRESULT LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
//可以加入一些释放键盘的代码return 1
}LRESULT LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
//可以加入一些释放鼠标的代码
return 1
}HOOK_API BOOL EnableKeyboardCapture()//设定钩子用来锁定键盘鼠标
{
if (!(hhkKeyboard=SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)LowLevelKeyboardProc, hInstance, 0)))
return FALSE;
if (!(hhMouseHook=SetWindowsHookEx(WH_MOUSE_LL, (HOOKPROC)LowLevelMouseProc, hInstance, 0)))
return FALSE;;
return TRUE;
}HOOK_API BOOL DisableKeyboardCapture()//释放键盘和鼠标
{
UnhookWindowsHookEx(hhMouseHook);
return UnhookWindowsHookEx(hhkKeyboard);
}-------------------------------------------------
DLL端编译器(VC6)C/C++属性页加入环境变量HOOK_EXPORTS
//头文件定义
HOOK.h
------------------------------------------------------------
#ifdef HOOK_EXPORTS
#define HOOK_API __declspec(dllexport)
#else
#define HOOK_API __declspec(dllimport)
#endif HOOK_API BOOL EnableKeyboardCapture();
HOOK_API BOOL DisableKeyboardCapture();
// This class is exported from the HOOK.dll
class HOOK_API CHOOK {
public:
CHOOK(void);
// TODO: add your methods here.
};extern HOOK_API int nHOOK;HOOK_API int fnHOOK(void);应用程序端只要加入HOOK.H和HOOK.lib就行了,然后按自己要求调用 EnableKeyboardCapture();
DisableKeyboardCapture();最后提醒一句,在没有加入释放键盘鼠标的代码前,不要编译运行,否则后果自负
m_Rc.left=0;
m_Rc.top=0;
m_Rc.right=0;
m_Rc.bottom=0;
if(!ClipCursor(&m_Rc))
{
.........
}
全是0就是不锁定,稍微有个范围才行。如果rect是整个桌面,和rect都是0一样,总之,msdn上有。
另外,我并不是完全要锁定键盘,我的意图是只能让键盘资源和鼠标资源只能为我的程序服务,
不能服务到其他程序上去,甚至是系统级的程序,我使用ClipCursor后,确实可以锁定到一个范围,
但是当我拖动一个窗口后,发现鼠标就可以乱晃了,这是怎么回事情?