深入解析钩子和动态链接库(下)

商河小虾米

商河小虾米

2016-02-19 12:56

只要你有一台电脑或者手机,都能关注图老师为大家精心推荐的深入解析钩子和动态链接库(下),手机电脑控们准备好了吗?一起看过来吧!

/*****************************************************************                             clearMyHook* Inputs:*       HWND hWnd: Window whose hook is to be cleared* Result: BOOL*       TRUE if the hook is properly unhooked*       FALSE if you gave the wrong parameter* Effect:*       Removes the hook that has been set.****************************************************************/__declspec(dllexport) BOOL clearMyHook(HWND hWnd)   {    if(hWnd != hWndServer)       return FALSE;    BOOL unhooked = UnhookWindowsHookEx(hook);    if(unhooked)       hWndServer = NULL;    return unhooked;   }/*****************************************************************                              msghook* Inputs:*       int nCode: Code value*       WPARAM wParam: parameter*       LPARAM lParam: parameter* Result: LRESULT** Effect:*       If the message is a mouse-move message, posts it back to*       the server window with the mouse coordinates* Notes:*       This must be a CALLBACK function or it will not work!****************************************************************/ static LRESULT CALLBACK msghook(int nCode, WPARAM wParam, LPARAM lParam)   {    // If the value of nCode is 0, just pass it on and return 0    // this is required by the specification of hook handlers    if(nCode 0)      { /* pass it on */       CallNextHookEx(hook, nCode,                   wParam, lParam);       return 0;      } /* pass it on */     // Read the documentation to discover what WPARAM and LPARAM    // mean. For a WH_MESSAGE hook, LPARAM is specified as being    // a pointer to a MSG structure, so the code below makes that    // structure available     LPMSG msg = (LPMSG)lParam;     // If it is a mouse-move message, either in the client area or    // the non-client area, we want to notify the parent that it has    // occurred. Note the use of PostMessage instead of SendMessage    if(msg-message == WM_MOUSEMOVE ||       msg-message == WM_NCMOUSEMOVE)      PostMessage(hWndServer,                  UWM_MOUSEMOVE,                     0, 0);      // Pass the message on to the next hook    return CallNextHookEx(hook, nCode,                        wParam, lParam);   } // msghookThe server application
在头文件中,将下面的增加到类的protected段:

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/)

afx_msg LRESULT OnMyMouseMove(WPARAM,LPARAM);在application 文件中, 增加以下代码到文件前部。

UINT UWM_MOUSEMOVE = ::RegisterWindowMessage(UWM_MOUSEMOVE_MSG);在 MESSAGE_MAP, 增加以下代码

 //{AFX_MSG comments:

ON_REGISTERED_MESSAGE(UWM_MOUSEMOVE, OnMyMouseMove)In your application file, add the following function:

LRESULT CMyClass::OnMyMouseMove(WPARAM, LPARAM)   {    // ...do stuff here    return 0;   }        上面是我写的一个小程序。既然我为了钩子花了n+1st 时间,我干脆给它一个好的用户界面。 猫在窗口之内盯着老鼠。小心! 当老鼠足够接近猫时并且它将捉住老鼠!

深入解析钩子和动态链接库(下)

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/)

你可以下载这个项目并建立它。 真正的关键是DLL 子工程项目; 其他的都不过是陪衬。有几个其它的技术被用在这个例子里,包括各种各样的图画技术, ClipCursor 和 SetCapture的用法,区域选择、屏幕更新等等。,因此除了展示钩子函数的使用以外,对初级程序员掌握窗口样式设计编程也有一些价值。

展开更多 50%)
分享

猜你喜欢

深入解析钩子和动态链接库(下)

编程语言 网络编程
深入解析钩子和动态链接库(下)

链接库动态链接库详细介绍

编程语言 网络编程
链接库动态链接库详细介绍

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

动态链接库编程(二)

Delphi
动态链接库编程(二)

Delphi 动态链接库编程

编程语言 网络编程
Delphi 动态链接库编程

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

动态链接库编程(一)

Delphi
动态链接库编程(一)

例程详析动态链接库

编程语言 网络编程
例程详析动态链接库

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

MapX之VC设置非地球坐标系

MapX之VC设置非地球坐标系

让插入到 innerHTML 中的 script 跑起来的实现代码

让插入到 innerHTML 中的 script 跑起来的实现代码
下拉加载更多内容 ↓