MFC -> CView::OnDraw Woes

Started by
6 comments, last by JimmyS 12 years, 4 months ago
Hello again.

I'm writing an MFC based application with a splitter window in the client area and a toolbar along the top. Each button in the toolbar represents an editing "Mode" each of which looks different and therefore requires a redraw of the views apon selection. I am using CView::Invalidate() to force a redraw and all seems well... Until...
If I switch modes (click the toolbar buttons) many times (Roughly 10) the View Redraws stall mid-draw and the entire GUI starts to misbehave greatly.
I was wondering if this is something obvious that a seasoned MFC dev might recognise and enlighten me.

My next attempt is to find a way, within the OnDraw Function, to delete any previous MFC WM_ON_DRAW messages and cancel and redraws currently in progress before I start the most current redraw.

unfortunately I don't know how to do this or even if it is possible in MFC.

Any Ideas would be greatly appreciated.
Advertisement
The GUI is single-threaded. I simply check a flag at the start of the draw. If clear, I set it, draw, and clear it. No control's message processing within the draw can then cause the draw to restart. Taken further, if you're animating the draw from a timer or something, you can test the flag to see if you've already got a draw message in the queue.
Thanks for the replay. I already have that proceedure in place. so now I know it's not that problem.

I guess I'm stuck.
Sounds suspiciously like a GDI resource leak somewhere. Make sure you clean up all used GDI resources after use and return the CDC (HDC) in the state it was to begin with.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Considering I am winging it completely, I'd say that is wery likely.

I do save the original pen and select it back in at the end. Anything else I should be looking for?
Difficult to say, but that's a good start.

Restore the old GDI objects in a HDC (sounds like you did that)
Delete any GDI resources you allocate with their proper cleanup functions (there are different)

It's probably easier if you show your code. Some of these leaks are subtle.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

I used GDIView in the past to see and detect any GDI leaks i've could have made in my engine, it's a great tool for that purpose. And it's free.
@Endurion
I am relatively new to this MCF and GDI stuff (And C++ in general)
apparantly the problem was that I was allocating "new" pens and brushes in a loop without deleting them. now that I think about it, it makes total sense.
Before this I was under the impression that everything you allocate is automatically cleaned up when it goes out of scope.
So this has been a good learning process for making all my other code cleaner and more memory efficient.
Guess this goes to show that I fit into that category of C++ developers who can do some pretty cool stuff with it but don't even understand the fundamentals hehe.
Thanks for your help.

@Vortez
GDIView sounds good, I'll have a look at it.
Thanks.

This topic is closed to new replies.

Advertisement