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