截获鼠标被按下的消息
我想截获在任何情况下,鼠标被按下的消息,例如:鼠标在非当前活动窗体外按下时,也要截获鼠标消息,就.NET而言,好像无法解决此问题,只能求助于API,我把我的代码贴出来给大家看一看,我的代码现在就是截获不到鼠标消息,而类似的代码在VB6下是没有问题的,不知道为什么?
答对者,马上结帐.
以下代码是整个窗体的代码,按照我原先的设想,如果捕捉到鼠标消息,就会弹出对话框或输出当前鼠标位置.但就是调试不成功,
public partial class Form2 : Form
{
internal enum HookType //枚举,钩子的类型
{
MsgFilter = -1,
JournalRecord = 0,
JournalPlayback = 1,
Keyboard = 2,
GetMessage = 3,
CallWndProc = 4,
CBT = 5,
SysMsgFilter = 6,
Mouse = 7,
Hardware = 8,
Debug = 9,
Shell = 10,
ForegroundIdle = 11,
CallWndProcRet = 12,
KeyboardLL = 13,
MouseLL = 14,
};
const int WM_LBUTTONDOWN = 0x201;
const int HWND_TOPMOST = -1;
const int HWND_NOTOPMOST = -2;
const int SWP_NOSIZE = 0x1;
const int SWP_NOMOVE = 0x2;
const int SWP_NOACTIVATE = 0x10;
const int SWP_SHOWWINDOW = 0x40;
IntPtr _nextHookPtr; //记录Hook编号
[DllImport( &qu