深入解析钩子和动态链接库(下)
来源:互联网 发布:iphone7实用软件 编辑:程序博客网 时间:2024/06/05 18:29
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
/****************************************************************
* 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);
} // msghook
The server application
在头文件中,将下面的增加到类的protected段:
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;
}
你可以下载这个项目并建立它。 真正的关键是DLL 子工程项目; 其他的都不过是陪衬。有几个其它的技术被用在这个例子里,包括各种各样的图画技术, ClipCursor 和 SetCapture的用法,区域选择、屏幕更新等等。,因此除了展示钩子函数的使用以外,对初级程序员掌握窗口样式设计编程也有一些价值。
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 深入解析钩子和动态链接库(下)
- 深入解析钩子和动态链接库(下)
- 深入解析钩子和动态链接库
- 深入解析钩子和动态链接库
- 深入解析钩子和动态链接库
- 深入解析钩子和动态链接库
- 深入解析钩子和动态链接库(上)
- 深入解析钩子和动态链接库(中)
- 深入解析钩子和动态链接库(上)
- 深入解析钩子和动态链接库(中)
- 深入解析钩子和动态链接库(上)
- 深入解析钩子和动态链接库(中)
- 动态链接库和钩子
- 动态链接库 全局钩子
- 《Windows核心编程》---动态链接库和钩子基础
- 钩子函数与动态链接库
- 钩子函数与动态链接库
- 深入理解静态链接库和动态链接库
- Using Extra Libraries
- 警惕二十九岁现象
- 综合布线工程实战经验九则
- 深入解析钩子和动态链接库(中)
- 动态数据窗创建原理及实现
- 深入解析钩子和动态链接库(下)
- 「小知识」关于补丁使得IIS启动不了
- 局域网维护和优化技巧
- 孙振耀撰文谈退休并畅谈人生
- TreeView控件与数据窗结合控件原理
- 使用SkinMagic Toolkit美化界面
- 开始
- 白话范式
- 了解Cookie与浏览器的关系