delphi – 如何定义私人基础应用程序消息?

前端之家收集整理的这篇文章主要介绍了delphi – 如何定义私人基础应用程序消息?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用私人消息在我的应用程序一年像这样:
UM_APP_BASE = WM_APP; // WM_APP is declared as WM_APP = $8000; in "Controls" unit.

然后定义我的私人消息:

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

并在我的课堂上使用它们:

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

(我也使用RegisterWindowMessage来与我的其他应用程序“交谈”,但这是一个不同的故事)

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

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;

如何定义基本消息,以免与Windows / Delphi /其他控件使用的其他消息相冲突?
哪个基本消息对于我的应用程序是首选的?为什么?
我应该使用WM_USER而不是WM_APP吗?请注意,WM_USER基础在Windows中的CommCtrl中也被使用. TB_ENABLEBUTTON = WM_USER 1.等…

我需要一些关于这个问题的见解.

我在我的Delphi帮助API(D5)上看到这个.这显然已经过时了!
这可能是为什么我决定使用WM_APP.
不过,关于两者之间的差异的解释将是很好:)

解决方法

我不知道你的信息来自哪里. MSDN documentation说:

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

WM_USER通过0x7FFFInteger消息供私有窗口类使用.

WM_APP(0x8000)通过0xBFFFMessages可供应用程序使用.

0xC000通过0xFFFFString消息供应用程序使用.

大于0xFFFF保留的系统.

现在,WM_USER范围和WM_APP范围有什么区别?这已经在许多地方被覆盖.例如here is what Raymond Chen has to say.

0x400 .. 0x7FFF (WM_USER .. WM_APP-1): Class-defined messages.

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): Application-defined messages.

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范围内广播消息.

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

猜你在找的Delphi相关文章