在窗口出现之前拦截并隐藏它

发布于 2024-10-06 05:56:35 字数 524 浏览 0 评论 0原文

我正在开发一个应用程序的(进程内)插件,作为我的插件的一部分,我想用我自己的工具提示替换应用程序的工具提示。但是,没有可用的 API 可供我执行此操作,因此我决定进入低级别。

我知道工具提示的窗口类,但问题是,如何检测它的创建以及之后如何关闭它?

到目前为止,我想做的是:

  1. 在WM_CREATE 上创建一个系统范围的钩子
  2. 当捕获时,检查 WM_CREATE 目标的类和进程
  3. 验证它确实是我关心的窗口:
    • 如果该进程是我的插件所在的进程
    • 如果类的类型正确
    • 如果焦点是正确的应用程序(如果有多个应用程序)
  4. 将 WM_DESTROY 发送到创建的窗口并创建我自己的窗口位于其位置,

听起来怎么样?假设确实没有 API 来处理工具提示,是否有更简单的方法来满足我的需要?

谢谢!

PS 标记为 C++/C#,因为我打算用这两种语言编写它(C++ 用于系统范围的钩子,C# 用于其他所有语言)

I am developing a (in-process) plug-in to application and as part of my plug-in I want to replace the application's tool-tips with my own. However, there is no API available for me to do so, so I've decided to go low-level.

I know the window class of the tool tip, but the question is, how do I detect it being created and how do I close it afterward?

Here's what I thought to do so far:

  1. Create a system-wide hook on WM_CREATE
  2. When caught, check the class and the process of the WM_CREATE target
  3. Verify it is indeed the window I care about:
    • If the process is the one my plug-in is sitting in
    • And if the class is of the correct type
    • And if the correct application is in focus (in case of multiple applications)
  4. Send a WM_DESTROY to the created window and create my own window at its position instead

How does it sound? Assuming there is indeed no API to handle the tooltips, is there a simpler way for what I need?

Thanks!

P.S Tagged as C++/C# as I intend to write it in these 2 languages (C++ for system-wide hook, C# for everything else)

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

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

发布评论

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

评论(2

月下凄凉 2024-10-13 05:56:35

如果您知道要阻止的窗口的类型,则只需将其子类化并在您自己的 WndProc 中处理销毁即可。将 GetClassLongPtr()GCL_WNDPROC 在工具提示类上,使用 SetClassLongPtr()GCL_WNDPROC 设置您自己的 WndProc 并让它在 WM_CREATE 上调用 DestroyWindow() 并调用旧的 <代码>WndProc 其余的..

If you know the type of the window you want to block, you can simply subclass it and handle the destruction in your own WndProc. Use GetClassLongPtr() with GCL_WNDPROC on the tooltip class, use SetClassLongPtr() with GCL_WNDPROC to set your own WndProc and have it call DestroyWindow() on WM_CREATE and call the old WndProc for the rest..

看春风乍起 2024-10-13 05:56:35

这行不通。考虑您要替换其工具提示的应用程序的视图,并假设您可以告诉它销毁窗口。当应用程序决定需要关闭工具提示时会发生什么?它没有新窗口的句柄,它有您已销毁的旧窗口的句柄。是时候出问题了。

如果您希望其顺利工作,您的插件系统需要明确支持替换工具提示。也许插件框架的可选部分可以是 RequestTooltip 函数。如果它不存在,或者返回 null,或者其他什么,则使用默认的工具提示,否则使用插件提供的工具提示。

This won't work. Consider the view of the application that you're replacing the tooltips of and assuming that you could tell it to destroy windows. What will happen when the app decides that it needs to close the tooltip? It doesn't have the handle of your new window, it has the handle of the old window, which you've destroyed. Time for things to go wrong.

Your plugin system needs to explicitly support replacing the tooltips if you want this to work smoothly. Perhaps an optional part of the plugin framework could be a RequestTooltip function. If it doesn't exist, or returns null, or whatever then the default tooltips are used, otherwise your plugin provided ones are used.

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