I am writing an image processing program for which I need to crop the image. I need to display a selection rectangle for this purpose and update its dimensions in the OnMouseMove() function. Also I need to repaint the window because the previously drawn rectangle should be erased (otherwise this causes a filled rectangle to be drawn). But this causes flickering of the window as my OnPaint() function takes some time to paint the window. How can I display the selection rectangle (is there any other way) without my window contents flickering and also update the selection rectangle's contents on mouse move.