gpt4 book ai didi

delphi - 如何定义私有(private)基础应用消息?

转载 作者:行者123 更新时间:2023-12-03 14:36:00 25 4
gpt4 key购买 nike

我一年来一直在我的应用程序中使用私有(private)消息,如下所示:

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

然后定义我的私有(private)消息:

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/其他控件使用的其他消息发生冲突?对于我的应用程序来说,哪个基本消息是首选的私有(private)消息?为什么?
我应该使用 WM_USER 而不是 WM_APP 吗?请注意,Windows 也在 CommCtrl 中使用 WM_USER 基,例如TB_ENABLEBUTTON = WM_USER + 1。等等...

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

<小时/>

我在 Delphi 帮助 API (D5) 上读到了这篇文章。这显然已经过时了!
这可能就是我决定使用 WM_APP 的原因。 不过,关于两者之间差异的解释会很好:)

最佳答案

我不确定您的信息来自哪里。 MSDN documentation说:

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

WM_USER 到 0x7FFF
供私有(private)窗口类使用的整数消息。

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

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

大于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 - 如何定义私有(private)基础应用消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20596047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com