Click here to Skip to main content
15,887,376 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

when I debug an MFC application and if I put a break point in OnPaint().This

function continously calling while debugging.My doubt is that it is happening only

while i am debugging the code.

Thanks in advance
Posted
Updated 26-May-20 22:32pm

This is because your application is hitting a break point Visual Studio is firing up and repainting the screen you step through your code and your application window gets focused again and needs a repaint.

Try bringing up your application and Visual Studio side by side (non overlapping windows).
 
Share this answer
 
Comments
kutz 2 24-Nov-11 8:07am    
If I put a message box in that function(OnPaint()) and build it in debug mode or release mode.Then i run the application it will show the message box only at one time.Please note that the above case(My question) is not happening with visual studio 2010
It's normal: it happens beacuse the debugger window overlaps the 'painted one' (and then the latter overlaps the debugger window itself) hence making the system generating new WM_PAINT messages.
 
Share this answer
 
v2
Any time your window gets overlapped with another window, minimized, maximized or re-size WM_PAINT message is sent to your application by Operating System, and its handler ONPaint() gets called. While debugging your may be encounter with any of these situations.

This[^]is very useful article for analyzing your problem.

Regards
 
Share this answer
 
You might have some endless loop in your "onPaint" function, such that you always set some value which calls "Invalidate" which will cause an "onPaint" call.


If that's the case you can register to the "Invalidated" event, and add there a breakPoint.

I'm using 2 screens, so the debugger doesn't cause WM_PAINT to be called, and the above helped me to find the stackTrace which caused the endless "onPaint".
 
Share this answer
 

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