三种自定义消息数值范围

在CSDN上看到一贴关于自定义消息的讨论:
  【http://topic.csdn.net/u/20080417/11/9e091cfe-3978-4b73-a1bd-ff5e7d508917.html】 

第一种楼主的方法是通过WM_USER自定义消息,这个方法,比较常用,也是容易知道的。楼主的5个步骤:
    1.#define wm_user_message wm_user+int (shift)语句后不能加";"号;
    2.上述shift 为1~1000以内的 整数值;
    3.该值的选择与系统消息,窗口消息,控件消息等无关;
    4.消息映射必须在BEGIN_MESSAGE_MAPS()和END_MESSAGE_MAPS()之内;
    5.消息处理的声明以及代码添加必须在指定的类中.
是正确的,不过这也说明楼主没有系统学过MFC,对MFC了解的不是很熟悉,如果在还没有熟悉MFC的情况下,就在MFC中定义自己的消息,不能称之为一个好办法。

第二种方法是WM_APP,这个消息我没有用过,查MSDN: 

WM_APP

The WM_APP constant is used by applications to help define private messages, usually of the form WM_APP+X, where X is an integer value.  (WM_APP常量在应用程序中帮助定义私有消息,常用WM_APP+X方式定义,其中X为整数值)
#define WM_APP       0x8000

在此文后面还有消息的范围,一并摘录,便于了解:
There are five ranges of message numbers: 五种消息范围数值

RangeMeaning
0 through WM_USER – 1Messages reserved for use by the system.系统保留消息
WM_USER through 0x7FFFInteger messages for use by private window classes.私有定义窗口类整数消息
WM_APP through 0xBFFFMessages available for use by applications.应用程序可获取消息
0xC000 through 0xFFFFString messages for use by applications.应用程序字符串消息
Greater than 0xFFFFReserved by the system for future use.保留消息

从这儿可以看到,楼主的整数说明不是很确切了,而WM_USER与WM_APP的使用范围也是有差别的,其应用范围也是不一样的。WM_USER用在窗口消息中,而WM_APP用在程序消息中,当然由于是自己定义的消息,自己爱怎么用就怎么用,不过,如果想管理好自己的代码,建议按MSDN推荐方式做。

第三种方法:RegisterWindowMessage
RegisterWindowMessage

The RegisterWindowMessage function defines a new window message that is guaranteed to be unique throughout the system. The returned message value can be used when calling the SendMessage or PostMessage function.  (RegisterWindowMessage函数定义了新的在系统内唯一的窗口消息,这个消息可以在SendMessage和PostMessage函数中使用)

UINT RegisterWindowMessage(
  LPCTSTR lpString   // address of message string
);
Parameters
lpString

Pointer to a null-terminated string that specifies the message to be registered. (指向NULL结尾的指定消息注册的字符串)
Return Values

If the message is successfully registered, the return value is a message identifier in the range 0xC000 through 0xFFFF.(如果消息成功注册,返回值将在0xC000和0xFFFF之间。
If the function fails, the return value is zero. To get extended error information, call GetLastError.
如果函数失败,返回值为0,获取下扩展消息信息,调用GetLastError,

在上面的消息数值范围表格中我们可以知道,这个消息是处于string消息范围之中的。

综上所述,这三个自定义消息都是可以使用的,而且是三个不同数值范围要求的三个消息。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值