c++ - 未聚焦时 Direct2D 窗口呈黑色

标签 c++ windows focus hwnd direct2d

我有一个 Direct2D 窗口,在聚焦时可以很好地绘制;但是,当焦点移动到另一个窗口(同一应用程序或另一个)时,整个窗口会变黑。我将问题归结为 ID2D1HwndRenderTarget::Clear 的使用。这个函数对我的应用程序至关重要,因为如果没有它,绘画就会变得相当......奇怪。

有没有一种方法可以让未聚焦的 Direct2D 窗口正常绘制(注意:WM_PAINT 像往常一样被调用,ClearBeginPaint 等都没有错误)

提前致谢。

最佳答案

来自 MSDN,

Handling Device Loss

While your program is running, the graphics device that you are using might become unavailable. For example, the device can be lost if the display resolution changes, or if the user removes the display adapter. If the device is lost, the render target also becomes invalid, along with any device-dependent resources that were associated with the device. Direct2D signals a lost device by returning the error code D2DERR_RECREATE_TARGET from the EndDraw method. If you receive this error code, you must re-create the render target and all device-dependent resources.

请检查链接以获取更多信息。 http://msdn.microsoft.com/en-us/library/ff684174(VS.85).aspx

关于c++ - 未聚焦时 Direct2D 窗口呈黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2608283/

相关文章:

c++ - 在 C/C++ 中正确地从管道获取输出

windows - 如何使我的程序在 Windows Vista 和 Windows 7 中运行?

performance - 您如何找到专注于编码项目/任务的最佳方式?

javascript - 如何在 jQuery 中使用模糊?

c++ - 构造函数生成对象但不为其赋值

c++ - 混淆在C++中实现rehash()函数

c++ - C++ 中包含固定大小数组的队列

javascript - vs代码侧边栏树文件夹结构不起作用

c# - Wpf 自定义窗口,Windows 边缘调整大小功能

jquery - focus() 在 iOS 上的 setTimeout 中不起作用