创建父窗口的 DLL 插件无法正确处理消息

发布于 2024-07-04 07:12:57 字数 348 浏览 8 评论 0原文

我正在创建一个插件框架,我的应用程序在其中加载一系列插件 DLL,然后创建一个新窗口并将此新窗口的句柄传递给插件。 然后,插件可以使用此句柄创建自己的 GUI。

一切似乎都进展顺利。 唯一的问题是,当我在插件小部件(例如编辑框)上按 TAB 时,它不会跳转到另一个小部件。 我发现有些 Windows 消息被传递了,而另一些则没有。 WM_KEYDOWN 被传递给其他键,因为我可以在编辑框中键入,但此消息不处理 TAB 键。

希望有人指点一下。

我使用 Borland VCL 和 CBuilder,但我认为我可以使用 WIN32 下的任何框架来创建这些插件,因为它们永远不知道它们的父窗口是如何创建的。

I'm creating a plugin framework, where my application loads a series of plugin DLL's, then creates a new window and pass this new window's handle to the plugin. The plugin can, then, use this handle to create their own GUI.

Everything seems to be working very well. The only problem is that when I press TAB on a plugin widget (An editbox, for example), it doen't jump to another widget. I figured out that some Windows messages are passed, and some others aren't. The WM_KEYDOWN is passed for other keys, because I can type on the editbox, but this message doesn't handle TAB key.

Hope somebody has a hint.

I'm using Borland VCL with CBuilder, but I think I could use any framework under WIN32 to create these plugins, since they never know how their parent windows were created.

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

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

发布评论

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

评论(4

以往的大感动 2024-07-11 07:12:57

我相信您必须采取以下步骤:

  1. 子类您的编辑控件(以及根据需要的其他控件)。
  2. 在编辑控件的 WndProc 中捕获 WM_KEYDOWN 消息。
  3. 检查当前是否按住了 Shift 键(使用 GetKeyState 或类似的)。
  4. 调用 GetWindow,将句柄传递给您的编辑控件以及 GW_HWNDPREV 或 GW_HWNDNEXT 取决于是否按住 Shift。 这将为您提供应该接收焦点的窗口的句柄。
  5. 调用 SetFocus 并传入窗口句柄在步骤 4 中得到。

确保处理编辑控件是多行的情况,因为您可能希望显示真正的制表符而不是移动到下一个控件。

希望有帮助!

I believe you'll have to take the following steps:

  1. Subclass your edit controls (and other controls as needed).
  2. Capture the WM_KEYDOWN message in your edit control's WndProc.
  3. Check to see if the shift key is currently held down (using GetKeyState or similar).
  4. Call GetWindow, passing in a handle to your edit control and either GW_HWNDPREV or GW_HWNDNEXT depending on whether shift is held down. This will give you the handle to the window that should receive focus.
  5. Call SetFocus and pass in the window handle you got in step 4.

Make sure you handle the case where your edit controls are multiline, as you might want to have a real tab character appear instead of moving to the next control.

Hope that helps!

晨曦÷微暖 2024-07-11 07:12:57

我相信您的每个 dll 和 exe 中都有不同的 VCL 实例。 dll 中的类与 exe 中的类不同,即使它们的调用方式相同。 此外,全局变量(应用程序、屏幕)在它们之间不共享。 内存也不是,因为它们都有自己的内存管理器。

解决方案是让 dll 和 exe 共享 VCL 库和内存管理器。 我不是 BCB 开发人员,而是 Delphi 开发人员。 在 Delphi 中,我们只使用 rtl 和 vcl 作为运行时包。 也许你可以做 BCB 等价的事情。

I believe you suffer from having a different instance of the VCL in each of your dlls and exes. Classes from the dll are not the same as the ones from your exe, even if they are called the same. Also global variables (Application, Screen) are not shared between them. Neither is the memory since they both have their own memory manager.

The solution is to have the dlls and the exe share the VCL library and the memory manager. I am not a BCB developer, but a Delphi developer. In Delphi we would just use the rtl and the vcl as runtime packages. Maybe you could do the BCB equivalent.

北渚 2024-07-11 07:12:57

DLL 有其自己的 TApplication 对象。

提供统一的密钥处理。 当 DLL 加载时。
将 DLL::TApplication 分配给 EXE::TApplication
退出时请务必执行相反的操作。

——

迈克尔

A DLL has its own TApplication object.

to provide uniform key handling. when the DLL Loads.
assign the DLL::TApplication to the EXE::TApplication
Be sure to do the reverse on exit.

--

Michael

自此以后,行同陌路 2024-07-11 07:12:57

这确实是一个非常复杂的问题。

当您点击 TAB 时,仅当这些控件属于模态对话框时,焦点才会跳转到另一个控件。 事实上,有一些按钮,如 ESC、LEFT、RIGHT、DOWN、UP、TAB,模态对话框消息函数以特殊方式处理。 如果您希望这些键与非模式对话框或任何其他窗口以类似的方式运行,您应该更改消息处理函数并在内部使用 IsDialogMessage。 您将找到有关 IsDialogMessage 函数的更多信息在 MSDN 中,为了更好地理解这些内容,您也可以检查 对话框部分。

并且,正如之前提到的,您应该设置 WS_TABSTOP 和 WS_GROUP 样式(需要时)。

祝你好运!

It's very complex matter indeed.

When you hit TAB focus jumps to another control only when these controls belong to a Modal Dialog Box. In fact there are some buttons like ESC, LEFT, RIGHT, DOWN, UP, TAB which modal dialog message function treats in a special way. If you want these keys to behave in similar way with modeless dialog box or any other window you should change you message processing function and use IsDialogMessage inside. You'll find more information about IsDialogMessage function in MSDN also to better understand this stuff you may check as well Dialog Boxes section.

And, as was mentioned before, you should set WS_TABSTOP and WS_GROUP styles when needed.

Good luck!

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