I am painting an jpeg image using IPicture. At first I load it, then if some conditions are met I draw it in the WM_Paint using IPicture::Render function. The problem is that it doesn't draw image if the window is closed by another window, and when I remove the closing window, only that image shows where the window was closing it. I used double buffering but the same problem, and I know that I should use InvalidateRect, But I can't Understand where to use it? Is there a special event like - you have to update your window? I need some place where I can use the InvalidateRect function. Can you help me? Now I tryed using it in the CALLBACK WndProc in the default case of the switch. I just checked it (using double buffering) and the image is drawn imediatly even if there is an other window partially closing it, but I got flickering every time if I resize, move the window or move another window.
The question doesn't really explain the situation very well. However:
Q: At first I load it, then if some conditions are met I draw it in the WM_PAINT
using IPicture::Render
function.
A: Always paint the picture in WM_PAINT
. WM_PAINT
is sent whenever the windows contents are damaged (by the window being resized, or uncovered by other windows) so you MUST paint during WM_PAINT or you will get unnpainted areas.
Q: I know that I should use InvalidateRect, But I can't Understand where to use it? Is there a special event like
A: Windows automatically calls InvalidateRect whenever Windows damages your windows contents (like when you uncover your window, restore your window, or resize your window). This ensures that a WM_PAINT message will be sent to your window. You need to call InvalidateRect() whenever you change the contents of your window - for example when you finish loading a new image you would call InvalidateRect to get windows to send you a `WM_PAINT and the new image would be painted then.