Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an app that is doc/view in nature and uses CMDIFrameWndEx and CMDIChildWndEx respectively.

The app uses four different document template so I change things so that the new menu will be a popup menu from which one can choose which document to lunch.The implication of this is that the client area of the main window is plain and with black (or perhaps dark grey) in colour at lunch, that is before any childframe is lunched via new or open. (clicking new or superimposed the white background of the child fram on it as expected.)

I did not like this so I overrode OnPaint so that it will render a JPEG image to the client area of the main window.

The problem is that my override works but it is immediately overridene by another code that I have not been able to track.

I see the rendered JPEG image then subsequently the black initial black background returns and stays.

How do I prevent my OnPaint operation from being overriden?
Which function/program is most likely responsible for the override?
Is such an override-causing function/program overrideable?
Posted
Updated 31-Jul-15 17:05pm
v2

1 solution

Please see my past answers:
MFC Drawed lines is disappeared[^],
Zooming Panning 2D vector graphics C++[^].

They should explain your the mechanism. You can find MFC-specific wrappers of the Windows Invalidate* API yourself.

The part "How do I prevent my OnPaint operation from being overridden?" does not seem to make much practical sense, just don't override what you don't want to override, or allow the users of your class to override what they want, because it makes a lot of sense. At the same time, I guess you need to learn this: https://msdn.microsoft.com/en-us/library/0w2w91tf.aspx[^].

[EDIT — in response to the follow-up question]

Please see my comment below on flicker, WM_ERASEBKGND and double buffering.
This CodeProject article can help you to understand further detail: Flicker Free Drawing In MFC[^].

—SA
 
Share this answer
 
v2
Comments
Gbenbam 1-Aug-15 6:31am    
Clearly my question is not clear. Its title which was meant to give people the idea that its a painting problem is not really apt.I will edit it.


Well. I actually wrote the repaintg code on receipt of WM_PAINT message. This means that every time my prigram receives the said message the rendering is done.At least that is what i expect of code that responds to the WM_PAINT message. The strange thing is that the black bacground is shown subsequent to each WM_PAINT repainting.

I suspect that what is happening is that MFC displays a default view with.black bacground when all the child windows have been closed.
Sergey Alexandrovich Kryukov 1-Aug-15 8:59am    
Yes. There are two methods to fight this thing, flicker:
1) override handling the message WM_ERAREBKGND.
2) use double buffering.
Are you getting the idea?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900