为什么在 XP(但不是 Vista 或 Windows 7)上显示 DirectShow 窗口可能需要 WS_CLIPCHILDREN?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2399216/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why might WS_CLIPCHILDREN be necessary for the display of DirectShow window on XP (but not Vista or Windows 7)?
提问by Middleware
I wrote a program to play MPEG video on a window (of course, DirectShow will open its own window as the sub-window of that window). On Windows Vista and 7, the program works fine. But on XP, the video is only visible when I set the WS_CLIPCHILDREN
style on the outer window (i.e. not the DirectShow one). Is this a bug in XP or some model change in Vista?
我写了一个程序在一个窗口上播放MPEG视频(当然DirectShow会打开自己的窗口作为那个窗口的子窗口)。在 Windows Vista 和 7 上,该程序运行良好。但是在 XP 上,只有当我WS_CLIPCHILDREN
在外部窗口(即不是 DirectShow 的)上设置样式时,视频才可见。这是 XP 中的错误还是 Vista 中的某些模型更改?
回答by Shog9
Actually, it sounds like a bug in your code...
实际上,这听起来像是您代码中的错误...
WS_CLIPCHILDREN affects the drawing of the parent window. More specifically, it prevents it from drawing in the areas occupied by its children. So if you're re-drawing the parent on a regular basis and WS_CLIPCHILDREN isn'tset, you'll end up stomping on the child window's display...
WS_CLIPCHILDREN 影响父窗口的绘制。更具体地说,它阻止它在其子项占据的区域中绘图。因此,如果您定期重新绘制父级且未设置WS_CLIPCHILDREN,则最终会踩踏子窗口的显示...
As for why this might affect XP and not Vista or Win7, well... This is just a guess, but many video players on XP used a feature provided by most video cards known as "overlays": essentially, the window was filled with a key color and this was then recognized by the hardware as indicating the area on screen where the video would be displayed. Since the window itself would not be repainted often (it would need to be filled with the key color initially and when resized, but wouldn't be repainted for every frame in the video), allowing the parent to draw over it could seriously mess up your output!
至于为什么这可能会影响 XP 而不是 Vista 或 Win7,嗯……这只是一个猜测,但 XP 上的许多视频播放器使用了大多数显卡提供的称为“覆盖”的功能:本质上,窗口充满了一种关键颜色,然后硬件将其识别为指示屏幕上将显示视频的区域。由于窗口本身不会经常重新绘制(它需要在最初和调整大小时填充关键颜色,但不会为视频中的每一帧重新绘制),允许父级绘制它可能会严重混乱你的输出!
Potential solutions
潜在的解决方案
Use WS_CLIPCHILDREN on your parent window. This is almost always a good idea anyway.
If you have custom painting code for your parent window, modify it to manually avoid drawing over the area occupied by the child.
在父窗口上使用 WS_CLIPCHILDREN。无论如何,这几乎总是一个好主意。
如果您的父窗口有自定义绘制代码,请修改它以手动避免在子窗口占用的区域上绘制。