挂钩表单重绘
我正在寻找一种方法,用一些直线、弧线等覆盖第三方应用程序的图形输出。应用程序接受窗口句柄,然后在其中显示其输出。
我使用 VC++ 在 Visual Studio 中组合了一个 Windows 窗体应用程序,该应用程序在窗体的 onPaint 方法中绘制(非静态)内容。当然,将此表单的句柄传递给其他应用程序,每次其他应用程序重绘时都会覆盖我的图形内容。
我能否以某种方式加入此重绘过程,以便在其他应用程序重绘之后添加我的图形?用透明面板覆盖表单并在其上绘制可能是另一种选择。但在 Windows 中,控件的真正透明度似乎是其自身的问题......
I'm looking for a way to overlay the graphical output of a third-party application with some lines, arcs etc. The applications accepts a handle of a window in which it will then display its output.
Using VC++ I put together a Windows Forms app in Visual Studio that draws (non-static) stuff in the onPaint-method of a form. Passing this form's handle to the other app, of course, overwrites my graphics stuff every time the other app redraws.
Can I somehow hook into this redrawing process to add my graphics after the other app redraws? Overlaying the form with a transparent panel onto which I draw could be an alternative. But real transparency for controls seem to be a problem of its own in Windows ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有从应用程序收到通知,您将无法轻松完成此操作。如果没有提供它们,则需要使用 SetWindowsHookEx() 设置全局挂钩,以便您可以看到 WM_ERASEBKGND 和 WM_PAINT 消息。这很难做到正确,您无法在托管代码中编写这样的挂钩。因为它需要将DLL注入到目标进程中。
唯一的其他选择是在表单顶部放置透明覆盖层。另一种窗体设置了 TransparencyKey 属性。您需要正确执行此操作的基本代码可以在我的答案中找到 此帖子。您只需要对其进行调整,使其永久有效。
You can't do this easily without getting notifications from the app. Which, if it doesn't provide them, would require setting a global hook with SetWindowsHookEx() so you can see the WM_ERASEBKGND and WM_PAINT messages. That's hard to get right, you cannot write such a hook in managed code. Since it requires injecting a DLL into the target process.
The only other option is that you put a transparent overlay on top of your form. Another form that has its TransparencyKey property set. The basic code you need to get that right is available in my answer in this thread. You just need to tweak it so it is permanent.