获取Windows消息名称 [英] getting a windows message name

查看:226
本文介绍了获取Windows消息名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows程序,我用DLL扩展。我包括通过调试流对象的调试代码通过OutputDebugString打印,我可以查看与DebugView。接口的一部分是消息处理函数。

I have a windows program that I'm extending with a DLL. I include debug code through a debug stream objects that print through OutputDebugString and I can view with DebugView. Part of the interface is a message processing function.

__declspec(dllexport) LRESULT messageProc(UINT Message, WPARAM wParam, LPARAM lParam) {
  dbg << "Message received " << Message  << endl;
  return TRUE; 

我的问题是如果有一个函数从代码中检索消息的名称。例如代替输出message received 534我想看到message received WM_MOVING以更适当地区分和过滤调试输出。

My question is if there is a function to retrieve the name of an message from the code. For example instead of the output "message received 534" I would like to see "message received WM_MOVING" to more appropriately distinguish and filter the debug output.

推荐答案

据我所知,没有函数,但你可以相对容易地做一个。你需要从Windows.h复制所有的消息定义,并把它们放在一个C ++文件像这样:

There is no function as far as I know, but you can make one relatively easily. You need to copy all the message definitions from Windows.h and put them in a C++ file like this:

#define X(x) { x, #x },
struct WindowsMessage
{
    int msgid;
    char* pname;
} WindowsMessages[] =
{
    X( WM_PAINT )
    X( WM_NCPAINT )
    ...
};
#undef X

然后你写一个函数,这个表并返回相应的文本。在宏中的是C的着名的stringize运算符,它将以下标识符转换为字符串文字。多么方便!

Then you write a function which, given a message id, searches through this table and returns the corresponding text. # in the macro is the famous "stringize" operator of C, which converts the following identifier into a string literal. How convenient!

这篇关于获取Windows消息名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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