My program creates random rectanges on the screen. Each time the left mouse button is clicked a new rectange of random size and colour is added to the window. However, when I resize the window, all of the rectanges are deleted – I don’t want this to happen. I don’t understand what the program does when it is resized, is it calling the case WM_PAINT? If so, what do I need to include to ensure the current window state remains when resized.
My program creates random rectanges on the screen. Each time the left mouse button
Share
See my answer to a similar question here about painting using GDI.
https://stackoverflow.com/a/12764607/682404
Basically, when your windows is resized, you should receive a
WM_PAINTmessage from Windows. In your message handler, you need to repaint your form. The answer I linked in has some details about the painting process. Your painting code would look rougly like this:Every time you need to paint your window, you always need to paint from scratch, so you need to store somewhere the coordinates of your rectangles.