Firemonkey - 消息处理

发布于 2025-01-03 01:21:56 字数 716 浏览 4 评论 0原文

我目前正在尝试开发一个基于 Firemonkey 的项目。我使用 Firemonkey 是因为它的 UI 功能,因为该项目由许多较小的应用程序组成,每个应用程序都有 3D 方面。我目前仅使用 FMX 框架开发/部署到 Windows,但以后可能会跨平台。

我通过在后台构建 VCL Windows 应用程序来执行非常具体的操作,然后构建 FMX 前端,解决了遇到的大多数问题。但是,这只适用于您只想执行应用程序来执行其设计目的的操作,因此可以使用参数执行应用程序。在其中一个应用程序中,我发现需要使用消息(或类似的东西)。例如,在我的 FMX 应用程序中,如果我单击“button1”,我希望它向后台 VCL 应用程序发送消息以执行“action1”,而不是使用参数执行它。

一个很好的例子是在后台应用程序中使用 VCL TMediaPlayer,前端 FMX 应用程序用于显示信息并提供播放、暂停等控制。这样它本质上就成为一个具有 VCL 功能的 FMX UI。

到目前为止,我还没有找到关于如何使用 Firemonkey 处理消息(例如,在 VCL 中,它们是通过“SendMessage”或“PostMessage”或类似的东西完成的)的任何内容,无论是通过本地帮助文件,或通过广泛的谷歌搜索。我发现的所有内容都与电子邮件有关(大概是因为我的大多数搜索词中都有“消息”一词)。

任何人都可以为我指明如何使用 Firemonkey/FMX 处理消息的正确方向吗?

问候, 斯科特·普里查德

I'm currently trying to develop a project based upon Firemonkey. I'm using Firemonkey for it's UI features as the project consists of many smaller applications, each with a 3D aspect to it. I'm currently only developing/deploying to Windows with the FMX framework, but may go cross-platform at a later date.

I've gotten around most issues I've come across by building a VCL Windows application in the background to perform a very specific action, and then building an FMX frontend. However, this is only suitable when you only want to execute the application to perform that action it's designed to do, and thus can execute the application with parameters. In one of the applications, i've come upon the need to use messages (or something similar). For example, in my FMX application, if i click "button1", i want it to send a message to the background VCL application to perform "action1", rather than execute it with parameters.

A good example could be using the VCL TMediaPlayer in the background application, with the front-end FMX application being used to display the information and provide control of play, pause, etc. Such that it essentially becomes an FMX UI with VCL ability.

I've so far been unable to find anything on how messages (e.g. in VCL, they'd be done with "SendMessage" or "PostMessage" or something similar) are handled with Firemonkey, either through the local help file, or through extensive Googling. Everything i've turned up has been related to email (presumably because of the word "Message" in most of my search terms).

Can anyone point me in the right direction on how messages would be handled with Firemonkey/FMX?

Regards,
Scott Pritchard

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧时模样 2025-01-10 01:21:56

我的理解是 Firemonkey 不是基于传统窗口的,因此向 Firemonkey 控件发送窗口消息通常不是一个选项。尽管某些控件确实使用窗口(最值得注意的是 TCommonCustomForm),因此您可以使用 FMX.Platform.Win 中的 FmxHandleToHWND() 函数需要时从 TFmxHandle 中提取 HWND 的单元。我不知道如何在 FMX 控件中接收和自定义处理窗口消息(如果可能的话)。

Windows 下的 Firemonkey 可以访问 Win32 API,因此应该没有什么可以阻止您向其他窗口控件(例如 VCL UI)发送窗口消息。在 uses 子句中包含 Winapi.Windows 单元以访问 Win32 API 函数,就像在 VCL 应用程序中一样。

更新:由于 FireMonkey 不会公开对发送到表单窗口的消息的访问权限,因此您必须手动子类化窗口,以便在 FireMonkey 看到消息之前接收消息。您可以重写 Form 的 CreateHandle() 方法,先调用 inherited 方法创建窗口,然后使用 FmxHandleToHWND() 获取 < code>HWND 您可以对其进行子类化。请务必先重写 DestroyHandle() 方法以删除子类,然后再调用 inherited 释放 HWND

My understanding is that Firemonkey is not based on traditional windows, so sending window messages to Firemonkey controls is not usually an option. Although some controls do use windows (most notibly, TCommonCustomForm), so you can use the FmxHandleToHWND() function in the FMX.Platform.Win unit to extract an HWND from a TFmxHandle when needed. I have no clue how to receive and custom process window messages in FMX controls, if that is even possible.

Firemonkey under Windows has access to the Win32 API, so there should be nothing stopping you from sending window messages to other windowed controls, such as your VCL UI. Include the Winapi.Windows unit in your uses clause to access Win32 API functions, just like you would in a VCL application.

UPDATE: because FireMonkey does not expose access to messages that are sent to a Form's window, you have to manually subclass the window in order to receive messages before FireMonkey sees them. You can override the Form's CreateHandle() method, call the inherited method first to create the window, then use FmxHandleToHWND() to get the HWND that you can subclass. Be sure to also override the DestroyHandle() method to remove the subclass before then calling inherited to release the HWND.

呆头 2025-01-10 01:21:56

目前,FireMonkey 没有可用于发送和发布消息的消息处理程序。

有可能使用 FireMonkey 等内部工作的侦听器来连接事物,但没有任何记录。

因此,这就是我所做的:

我创建了自己的自定义“消息”类。我创建该类的实例,并将它们从我需要的任何线程添加到线程安全列表中。在主线程上,我有一个计时器来检查列表并处理“消息”。

Currently, FireMonkey doesn't have a message handler that you can use to send and post messages.

There is a possibility of hooking things up using listeners like FireMonkey works internally, but none of it is documented.

So, instead, here's what I've done:

I created my own custom "message" class. I create instances of the class and add them to a thread-safe list from any thread I need to. On the main thread, I have a timer that checks the list and processes the "messages".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文