How To Draw In WndProc Events Since Change To Direct2D

Does anybody have any experience of drawing within wndproc events since the transition to Direct2D?

We are moving one of our projects to newer versions of Xojo and we are finding that our code no longer works. The wndproc events are being called and we seem to have a valid device context but nothing gets drawn (we are using win32 API calls such as FillRect & BitBlt).

Better sharing a small sample of the problem.

I can share an example project if required, but since drawing in a wndproc is an advanced topic i’d prefer to wait until someone at least says they have done it.

1 Like

Some people could see your simple and small sample working on Xojo v201xrx but not working in Xojo v2022rx and provide a translation for the current standards. Or tips… But follow your preferred path. :wink:

Check if you can extrapolate differences from your current way based on this:

Honestly @JulianS would be your best bet for this kind of question.

After much hair pulling it turns out not to be a Direct2D issue.

For some reason, the Xojo framework now erases all of the control backgrounds in the window WM_ERASEBKGND message which screws up my drawing. If I filter out that message then control wndproc code operates correctly.

I’m going to query this with Xojo as it might be an unnecessary paint operation they can remove and make things faster.

Xojo has a proprietary image composition engine to take care of control stacking and it per se causes issues in some cases, I guess that such background “painting” (erase) is involved in their “logic” for that. Depending on where you put your component (below some Xojo controls maybe) the image can be messed as Xojo will imagine that some rectangles were painted with some brush before they repaint some upper content. I do remember they rewrote such engine for D2D (trying to decrease flickering, lots of visible repaintings), and that may be the difference you found.

I don’t think they are doing anything as sophisticated as what you describe. As far as I can tell, appears that they are just l using the standard window messages in a slightly different (unexpected) way.

I’ve logged a query to see if I can get some kind of official answer.

Hi @kevin_g ! Don’t know if this helps but I found an issue with the last R3.2 drawing an image with 144 dpi in the windows’ paint event clears the whole window background. Creating a lo-res picture fixed it.

Hi Carsten.

Thanks for the heads-up.

This is a different problem which goes back to 2019r1.1 (possibly earlier).