将WM消息拦截到C ++类中 [英] Intercept a WM message into a C++ class

查看:94
本文介绍了将WM消息拦截到C ++类中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何将WM_特定消息截取到C ++类中,我需要使用RegisterDeviceNotification函数注册特定的WM_消息(我需要在这里显示一个窗口吗?)然后截取它并调用适当的函数

C ++类应包含在任何项目中,从控制台到Win32再到mfc.我的想法是创建Win32窗口的框架,然后对该窗口使用WndProc,这很愚蠢吗?

有(肯定)更好的解决方案吗? /div>

您肯定需要有一个Windows Proc来接收您的消息,因为该消息专门与已注册的Windows类相关联. MSDN上的文档应该向您展示如何.请参见: Windows过程概述 [ http://msdn.microsoft.com/en-us/library/ms632599 (VS.85).aspx#message_ [ 解决方案

You definitely need to have a Window Proc to recieve your message, because it is associated specifically with a registered Windows class. The documentation over at MSDN should show you how. See this: Windows Procedures Overview[^]
You can also define your own custom Windows messages using a define, and by selecting a value above WM_USER.


Well, you will need a message pump. As long as you can get a message pump running in your console app, then yeah, your solution sounds great. Can be tricky, because usually console apps aren''t event driven. If concurrency is an issue for you, you might have to create a worker thread in which you house both the message pump and window. If concurrency isn''t an issue, all you have to do is start a while(GetMessage(...) { DispatchMessage(...) }-loop, while you wait for the message.

You might also be interested in using message-only windows for your code. http://msdn.microsoft.com/en-us/library/ms632599(VS.85).aspx#message_[^]


这篇关于将WM消息拦截到C ++类中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆