Using DirectX and GDI+ in the same form

ketil

Newcomer
Joined
Mar 21, 2006
Messages
1
Hi,

I am experiencing a problem that I cannot resolve when I use DirectX and GDI+ at the same time in a user control.
I have a background drawn with DirectX and something drawn in the foreground with GDI+. All drawing is handled in the controls OnPaint function.
When the form with the control is made visible everything is as expected. Now imagine that, while the form is up, you change focus to a different program running positioned so that it occupies half of the form with my drawing in it, dividing it into two regions, A and B, A being visible and B is hidden from view. The visible part, A, still contains both foreground and background of my drawing while the form is out of focus, but when I change focus back to the form the problem occurs. On changing focus back to the form the background and foreground is displayed as normal in part B, but in part A the background only is visible. It's as if only part A of the form is refreshed, and only the background is refreshed.
When the form is resized both back- and foreground are refreshed as expected.

If I am making myself clear, do you know how I can prevent this?
 
It looks like you are performing your DirectX rendering in the OnPaint method along with the GDI+ rendering. My guess is that what is happening is when OnPaint is called, you render the entire control with DirectX (which will draw over anything on the control, including previous GDI+ rendered graphics) and then do the GDI+ rendering, which is clipped (I don't know whether this is automatic or if you are taking the clip rect into account) to only draw what has been uncovered.

Assuming that this is the case, you simply need to take into account the clip rectangle when you do the DirectX rendering so that you don't draw over part of a control with DirectX that won't be finished with GDI+ because of clipping.
 
Back
Top