Windows 消息综述/WM_USER/WM_APP

130 篇文章 1 订阅
windows message :
Range Description 
From 0 through WM_USER –1 Messages reserved for use by the system. 
From WM_USER through 0x7FFF Integer messages for use by private window classes. 
WM_APP through 0xBFFF Messages available for use by applications. 
0xC000 through 0xFFFF String messages for use by applications. 
Greater than 0xFFFF Reserved by the system for future use. 
Message numbers in the first range (from 0 through WM_USER –1) are system-defined. Values not explicitly defined in this range are reserved for use by the system. 
Message numbers in the second range (WM_USER through 0x7FFF) can be defined and used by an application to send messages within a private window class. These values cannot be used to define messages that are meaningful throughout an application, because some predefined window classes already define values in this range. For example, predefined control classes such as BUTTON, EDIT, and LISTBOX may use these values. Messages in this range should not be sent to other applications unless the applications have been designed to exchange messages and to attach the same meaning to the message numbers. 
Message numbers in the third range (from 0x8000 through 0xBFFF) are available for application to use as private messages. Message in this range do not conflict with system messages. 
Message numbers in the fourth range (from 0xC000 through 0xFFFF) are defined at run time when an application calls the RegisterWindowMessage function to retrieve a message number for a string. All applications that register the same string can use the associated message number for exchanging messages. The actual message number, however, is not a constant and cannot be assumed to be the same between different sessions. 
Message numbers in the fifth range (greater than 0xFFFF) are reserved for use by the system. 
Windows 消息:
范围描述:
从 0 到 WM_USER –1 消息 是系统预留消息;
从 WM_USER 到 0x7FFF 消息 用于用户私有窗口消息;
 也就是说用户可以自定义消息,但是自定义消息只能在窗口内部使用,不能跨窗口或者跨进程使用,
因为这个范围的的消息值对于程序是有意义的,预定义的系统控件已经使用了这个范围的消息值,
例如:BUTTON、EDIT、LISTBOX可能就使用了这些值。
从 WM_APP 到 0xBFFF 消息 用于程序间的消息传递,并保证不会和系统消息冲突;
从 0xC000 到 0xFFFF 消息 使用用户通过调用RegisterWindowMessage注册的字符串消息;
 注意:两个进程调用RegisterWindowMessage,即使使用相同的字符串参数,也有可能返回不同的消息值,但是他们是同一个消息,可以用来交换数据。
 
大于 0xFFFF 消息 是系统未来预留消息。
 
Windows分为标准Windows消息、控件通知消息和命令消息三大类:

1. 标准Windows消息

标准Windows消息,除WM_COMMAND消息外,所有以WM为前缀的消息都是标准Windows消息,标准Windows消息主要分为三类

2. 控件消息(WM_COMMAND)

控件消息是从控件传送给父窗口的消息,HIWORD(wParam)=控件消息类型 LOWORD(wParam)=控件ID lParam=控件窗口句柄

3.命令消息

命令消息是菜单项、工具栏按钮、加速键等用户界面对象发送的WM_COMMAND消息,HIWORD(wParam)==0=菜单消息 HIWORD(wParam)==1=加速键

菜单:LOWORD(wParam)=菜单命令ID lParam=0

加速键:LOWORD(wParam)=加速键命令ID lParam=0

对于Windows的命令,如:最大化最小化等命令,会自动转换成WM_SYSCOMMAND命令。

 

WM_NOTIFY:

This message informs the parent window of a control that an event has occurred in the control or that the control requires some kind of information.

WM_NOTIFY消息 是控件向父窗口请求信息的消息,如果父窗口不处理的话,一般应该反射该消息到控件,以便控件可以默认处理该消息【这里就是所谓的消息反射】。

 

还有一类消息和窗口无关的,线程消息,通过PostThreadMessage发送线程消息,如:WM_QUIT消息。

 

 

对于以上消息,要清楚PostMessageSendMessage的区别,简单的说PostMessage是发送消息到线程消息循环,是异步过程,SendMessage就相当于直接函数调用,是同步过程。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值