office的截屏是用的什么技术?

word的插入图片窗口是打印出来的么?
关注者
67
被浏览
34,427

5 个回答

这个问题还是有点复杂的,我折腾了 90 分钟大概搞明白了。 结论:用的是 PrintWindow。

我一开始有两个想法,一是 Office 可以从 DWM 拿截图,二是用 GDI BitBlt。

三个观察:Office 不会显示 UWP/Windows Store apps 的截图;Office 不能获得比自己更高权限 app 的截图;Office 获得的截图具有和 DWM 画出来的不同的边框(Windows 10 上 DWM 永远是开的,包括高对比度模式)。

检验 DWM

根据 Programming the Windows Vista DWM in C# 可以看到 DWM 拿到的图是用户看到的,实际上 DWM 不会给你图,而是会帮你合成到你指定的位置: Is it possible to capture a window with windows 7 DWM thumbnail in it?

检验 BitBlt

搜索 capture window basic theme 之类的,可以搜索到:

PrintWindow() could not print Google Chrome window (Chrome_WidgetWin_1)

Convert PrintWindow to BitBlt to capture screenshot of a specific window

PrintWindow bitmap differs from PrintScreen Key bitmap

PrintWindow and Microsoft Edge

PrintWindow causes flicker, strange artifacts in titlebar

这些现象说明 Office 不是用的 BitBlt 截图的。

猜测

我猜测 Office 用的是 PrintWindow。用 procmon 可以看出来 Office 会在用户想要插入截图的时候 spawn 一堆线程去获取每个窗口的图,目测是 EnumWindows 的 EnumWindowsProc 里面 spawn 的。

轶事

我起初想要禁用 dwm 看看 Office 是不是就没法截图了,于是把 VS debugger attach 到 dwm 上然后点“暂停”(break all),然后屏幕就会卡住,等待一段时间后 Windows 以 VIDEO_TDR_FAILURE 蓝屏结束。

的确是PrintWindow,打个断点直接断下了,office365。