如何定义私有基础应用程序消息? [英] How to define private base Application messages?

查看:98
本文介绍了如何定义私有基础应用程序消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一年来一直在应用程序中使用私人消息,如下所示:

I'm was using private messages in my application for year like this:

UM_APP_BASE = WM_APP; // WM_APP is declared as WM_APP = $8000; in "Controls" unit.

,然后定义我的私人消息:

and then defined my private messages:

UM_EXPLORER_MSG = UM_APP_BASE + 1;
UM_LICENSE_CHANGE_MSG = UM_APP_BASE + 2;
etc...

并在我的课程中像这样使用它们:

And use them like this in my class:

procedure UMLicenseChanged(var Message: TMessage); message UM_LICENSE_CHANGE_MSG;

(我也使用RegisterWindowMessage与其他应用程序对话",但这是另一回事了)

(I also use RegisterWindowMessage to "talk" to my other applications but that is a different story)

我不记得是什么让我决定首先使用WM_APP而不是WM_USER作为基础的.
文档说:

I don't remember what made me decide to use WM_APP rather than WM_USER as base in the first place.
The docs says:

WM_USER常量用于区分消息值 保留供Windows使用的值和可以由 应用程序以在私有窗口类中发送消息.有 五个消息编号范围:

The WM_USER constant is used to distinguish between message values that are reserved for use by Windows and values that can be used by an application to send messages within a private window class. There are five ranges of message numbers:

Range   Meaning
0 through WM_USER - 1   Messages reserved for use by Windows.
WM_USER through 0x7FFF  Integer messages for use by private window classes.
0x8000 through 0xBFFF   Messages reserved for future use by Windows.
0xC000 through 0xFFFF   String messages for use by applications.
Greater than 0xFFFF Reserved by Windows for future use.

这意味着WM_APP被保留供Windows以后使用". 另一方面,Delphi使用该范围内的CM_BASE = $B000;.还有CN_BASE = $BC00;

Which means that WM_APP is "reserved for future use by Windows". On the other hand Delphi uses CM_BASE = $B000; which is in that range. and also CN_BASE = $BC00;

如何定义基本消息,以使其不会与Windows/Delphi/其他控件同时使用的其他消息相冲突? 我的应用程序首选哪个基本消息作为私有消息?为什么?
我应该使用WM_USER而不是WM_APP吗?请注意,Windows也在CommCtrl中使用WM_USER base. TB_ENABLEBUTTON = WM_USER + 1.等等

How do I define the base message so it wont collide with other messages used both by Windows/Delphi/Other controls? Which base message is preferred as private for my application? and why?
Should I use WM_USER instead of WM_APP? Note that WM_USER base is used in CommCtrl by Windows also e.g. TB_ENABLEBUTTON = WM_USER + 1. etc...

我需要对这个问题有一些见识.

I need some insights on this issue.

我在Delphi帮助API(D5)上阅读了此内容.这显然已经过时了!
这可能就是为什么我决定使用WM_APP.
的原因. 尽管如此,关于两者之间的区别的解释还是不错的:)

I read this on my Delphi help API (D5). which is obviously obsolete!
This is probably why I have decided to use WM_APP.
Still, an explanation about the difference between the two would be nice :)

推荐答案

我不确定您的信息来自何处. MSDN 文档说:

I'm not sure where your information comes from. The MSDN documentation says:

0到WM_USER –1
消息保留供系统使用.

0 through WM_USER –1
Messages reserved for use by the system.

WM_USER到0x7FFF
整数消息,供私有窗口类使用.

WM_USER through 0x7FFF
Integer messages for use by private window classes.

WM_APP(0x8000)到0xBFFF
消息可供应用程序使用.

WM_APP (0x8000) through 0xBFFF
Messages available for use by applications.

0xC000到0xFFFF
供应用程序使用的字符串消息.

0xC000 through 0xFFFF
String messages for use by applications.

大于0xFFFF
由系统保留.

Greater than 0xFFFF
Reserved by the system.

现在,WM_USER范围和WM_APP范围之间有什么区别?这已经在许多地方讨论过了.例如,这是雷蒙德·陈(Raymond Chen)所说的.

Now, what is the difference between the WM_USER range, and the WM_APP range? This has been covered in many places. For instance, here is what Raymond Chen has to say.

0x400 .. 0x7FFF(WM_USER .. WM_APP-1):类定义的消息.

这些消息的含义由 窗口类. (非正式地:由致电RegisterClass的人 该窗口类.)例如,WM_USER + 1消息表示 TB_ENABLEBUTTON,如果窗口是工具栏控件,则表示 如果是工具提示控件,则为TTM_ACTIVATE;如果为工具提示控件,则为DM_SETDEFID 它是一个对话框.如果您创建了自己的控件,则意味着 其他完全不同的东西.由于任何人都可以创建 消息在此范围内,操作系统不知道 参数表示并且无法执行自动编组.

The meanings of these messages is determined by the implementor of the window class. (Informally: By the person who calls RegisterClass for that window class.) For example, the WM_USER+1 message means TB_ENABLEBUTTON if the window is a toolbar control, but it means TTM_ACTIVATE if it is a tooltip control, and it means DM_SETDEFID if it is a dialog box. If you created your own control, it would mean something else completely different. Since anybody can create a message in this range, the operating system does not know what the parameters mean and cannot perform automatic marshalling.

0x8000 .. 0xBFFF(WM_APP ... MAXINTATOM-1):应用程序定义的消息.

这些消息的含义由应用程序确定 创建了窗口. (非正式地:由致电者 CreateWindow.)此消息区域是在Windows 95中创建的,以确保 子类化窗口并生成自定义消息的应用程序 不会干扰window中的窗口类创建的新消息 未来版本.同样,由于任何人都可以在此创建消息 范围,操作系统不知道参数的含义,并且 无法执行自动编组.

The meanings of these messages is determined by the application that created the window. (Informally: By the person who calls CreateWindow.) This message region was created in Windows 95 to ensure that applications which subclass a window and generate custom messages will not interfere with new messages created by the window class in future versions. Again, since anybody can create a message in this range, the operating system does not know what the parameters mean and cannot perform automatic marshalling.

这一切的主要目的是,如果您在WM_USER范围内定义消息,那么请准备好让应用程序中的其他控件自己使用这些相同的消息.例如,您不得广播WM_USER范围内的消息.

The main thing to take from all this is that if you define messages in the WM_USER range, then be prepared for other controls in your application to have their own use for those same messages. For instance, you must not broadcast messages in the WM_USER range.

另一方面,对于应用程序中所有不同的窗口类,WM_APP范围内的消息都具有相同的含义.

On the other hand, messages in the WM_APP range are intended to have the same meaning for all different window classes in an application.

这篇关于如何定义私有基础应用程序消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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