WM_USER VS WM_APP [英] WM_USER vs WM_APP

查看:152
本文介绍了WM_USER VS WM_APP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的工作线程发送一个用户定义的消息到UI线程消息队列,但我不知道我是否应该使用 WM_USER WM_APP 。为 WM_APP 文档说:

I want the worker threads to send a user-defined message to the UI thread message queue, but I am not sure if I should use WM_USER or WM_APP. The documentation for WM_APP says:

通过0xBFFF WM_APP

WM_APP through 0xBFFF

可以使用的消息由应用程序。

Messages available for use by applications.

所以,我应该用 WM_APP

推荐答案

微软在它的API真的保守,所以当你看到邮件WM_APP通过0xBFFF的不与系统消息发生冲突:那就需要在Windows API的重大变化对被breaked该规则,和许多其他应用程序将无法生存。

Microsoft is really conservative on its APIs, so you can be confident when you see that messages WM_APP through 0xBFFF do not conflict with system messages : it would need a major change in Windows API for that rule to be breaked, and many other applications would not survive.

唯一相关的问题是:你需要在WM_USER范围或WM_APP范围内使用的消息

The only relevant question is : do you need to use messages in the WM_USER range or in the WM_APP range ?

MSDN说:

在第二范围的消息号(通过0x7FFF的WM_USER)可以定义和应用程序使用到的专用窗口类内发送消息。这些值不能被用于定义在整个申请有意义的信息,因为某些predefined窗口类已经在此范围内确定的值。例如,predefined控制类,如按钮,编辑框,列表框和组合框可能会使用这些值。在此范围内的邮件的不应该被发送到其他应用程序,除非应用程序已经被设计成交换消息和相同的含义附加到邮件中的号码。

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, LISTBOX, and COMBOBOX 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.

第三范围(0x8000的通过0xBFFF)留言编号为应用程序的私人信息使用。在此范围内的邮件不会与系统消息发生冲突。

(强调矿)

如果你明确地发布到被设计用来处理他们在一个特定的方式,而不是一个Windows控件的子类的窗口这些消息,你可以使用WM_USER范围。如果他们要由消息循环直接处理(这是WM_QUIT为例),或者如果有疑问,请使用WP_APP范围。

If you explicitly post those messages to a window that is designed to handle them in a specific way and is not a subclass of a Windows control, you can use WM_USER range. If they are to be handled directly by the message loop (as is WM_QUIT for example), or if in doubt, do use the WP_APP range.

换个说法:因为你并不需要很多这样的消息,并按照您希望他们后到UI线程的消息队列,只需使用一个在尚未使用您的应用程序WM_APP范围,并且一定要对于后期的维护记录下来。

Said differently : as you do not need a lot of such messages and as you want the post them to the UI thread message queue, simply use one in the WM_APP range that is not already used by your application, and be sure to document it for later maintenance.

这篇关于WM_USER VS WM_APP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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