Have a break point / outputdebugstring in erase background and paint and see when you minimize and maximize which one is called and what happens.

Also try seeing the resizing of window and if you graph is correct.