如何检测窗口内容何时发生变化 [英] How to detect when window content has changed

查看:33
本文介绍了如何检测窗口内容何时发生变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写截屏视频,并且需要检测窗口内容何时发生变化,甚至只选择了文本.此窗口为第三方控件.

I need to write a screencast, and need to detect when window content has changed, even only text was selected. This window is third party control.

推荐答案

有几种方法.

(1) 屏幕投票.

可以轮询屏幕(即创建一个DIB,每个时间段从屏幕到BitBlt),然后按原样发送

You can poll the screen (that is, create a DIB, each time period to BitBlt from screen to it), and then send it as-is

优点:

  • 实施起来非常简单

缺点:

  • 高 CPU 负载.每秒轮询整个屏幕的次数非常繁重(应该传输大量数据).因此它会很重而且很慢.
  • 高网络带宽

(2) 与上面相同,除了现在您对轮询屏幕进行一些分析以查看差异.然后您可以只发送差异(如果没有变化,显然不发送任何内容),另外您可以选择压缩差异流.

(2) Same as above, except now you do some analyzing of the polled screen to see the difference. Then you may send only the differences (and obviously don't send anything if no changes), plus you may optionally compress the differences stream.

优点:

  • 实施起来仍然不太复杂
  • 显着降低网络带宽

缺点:

  • 甚至更高的 CPU 使用率.

(3) 同上,只是你不经常轮询屏幕.相反,您会为您的控件做一些挂钩(例如监视控件收到的 Windows 消息).然后您尝试了解您的控件何时应该重绘自身,并仅在这些情况下进行屏幕轮询.

(3) Same as above, except that you don't poll the screen constantly. Instead you do some hooking for your control (like spying for Windows messages that the control receives). Then you try learn when your control is supposed to redraw itself, and do the screen polling only in those scenarios.

优点:

  • 显着降低 CPU 使用率
  • 仍然可以接受的网络带宽

缺点:

  • 实施变得复杂.诸如注入钩子之类的事情
  • 由于这是基于某种启发式方法 - 您不能保证(一般来说)涵盖所有可能的情况.在某些情况下,您可能会错过更改.

(4)在较低级别挂钩:拦截对绘图函数的调用.由于在用户模式中有大量这样的函数 - 这样做的唯一现实可能性是在内核模式中.

(4) Hook at lower level: intercept calls to the drawing functions. Since there's enormous number of such functions in the user mode - the only realistic possibility of doing this is in the kernel mode.

您可以编写一个虚拟视频驱动程序(镜像"视频驱动程序,或钩住现有的驱动程序)来接收系统中的所有绘图.然后,每当您收到有关特定区域的绘图请求时,您就会知道它已更改.

You may write a virtual video driver (either "mirror" video driver, or hook the existing one) to receive all the drawing in the system. Then whenever you receive a drawing request on the specific area - you'll know it's changed.

优点:

  • 降低 CPU 使用率.
  • 100% 保证拦截所有图纸,没有启发式
  • 更简洁 - 无需在应用/控件中注入钩子

缺点:

  • 这是一个驱动程序开发!除非你有这方面的经验 - 这真是一场噩梦.
  • 更复杂的安装.需要管理员权限,很可能需要重启.
  • CPU 负载和带宽仍然相当可观
  • It's a driver development! Unless you're experienced in it - it's a real nightmare.
  • More complex installation. Need administrator rights, most probably need restart.
  • Still considerable CPU load and bandwidth

(5)继续进行驱动程序开发.只要您现在知道调用了哪些绘图函数 - 您现在就可以切换策略.而不是记住"脏区域并在那里轮询屏幕 - 您可能只是记住"使用所有参数调用的绘图函数,然后在主机端重复"它.

(5) Going on with driver development. As long as you know now which drawing functions are called - you may switch the strategy now. Instead of "remembering" dirty areas and polling the screen there - you may just "remember" the drawing function invoked with all the parameters, and then "repeat" it at the host side.

这样,您根本不必轮询屏幕.您使用矢量"方法(而不是光栅").

By such you don't have to poll the screen at all. You work in a "vectored" method (as opposed to "raster").

然而,这实现起来要复杂得多.一些绘图函数将另一个位图作为参数,而这些位图又是使用另一个绘图函数等绘制的.您必须监视位图和屏幕.

This however is much more complex to implement. Some drawing functions take as parameters another bitmaps, which in turn are drawn using another drawing functions and etc. You'll have to spy for bitmaps as well as screen.

优点:

  • 零 CPU 负载
  • 最佳网络流量
  • 保证一直工作

缺点:

  • 这是最好的驱动程序开发!保证几个月的开发时间
  • 需要最先进的编程,对 2D 绘图有深入的了解
  • 需要在主机上编写代码来绘制"所有记录"命令.
  • It's a driver development at its best! Months of development are guaranteed
  • Requires state-of-the-art programming, deep understanding of 2D drawing
  • Need to write the code at host which will "draw" all the "Recorded" commands.

这篇关于如何检测窗口内容何时发生变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆