views:

135

answers:

2

Hi all,

I have a Direct2D window which paints fine when in focus; however, when focus moves to another window (same application or another), the entire window goes black. I pinned the issue down to the use of ID2D1HwndRenderTarget::Clear. This function is vital to my application as without it, painting becomes rather... weird.

Is there a way an un-focused Direct2D window can paint as normal (note: WM_PAINT is being called as usual, as is Clear, BeginPaint, etc. all without error)

Thanks in advance.

+1  A: 

With my experience with DirectX, if the screen turns back its because DX lost the device it was 'painting' to. This happens a lot - for instance - when switching between a full-screen DirectX window to another application, and vice-versa.

So what you need to do is re-intialize the DX device so it can resume painting operations.

This might help some more (not my website, but a quick Google search turned it up)

http://www.programmersheaven.com/2/FAQ-DIRECTX-Avoid-task-switching

Jeffrey Kern
the link is broken.
young
+1  A: 

From 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.

Please check the link for more info. http://msdn.microsoft.com/en-us/library/ff684174(VS.85).aspx

young