Jump to content
  • Advertisement
Sign in to follow this  
JimmyS

MFC -> CView::OnDraw Woes

This topic is 2568 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
@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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!