views:

973

answers:

5

I've a Visual C++ project but I don't be able to refresh the window and redraw itself. I've used

RedrawWindow();
m_ProgressDlg->RedrawWindow();

and also

UpdateData(false);
m_ProgressDlg->UpdateData(false);

but never seems go well.

How can I do?

+1  A: 

::InvalidateRect(hwnd, NULL, TRUE) WinAPI function (or wnd->InvalidateRect(NULL) method) should do the trick: it invalidates client area and causes the system to send WM_PAINT to the window to redraw it. If you want immediate redraw, you should also call UpdateWindow() just after invalidation.

Rageous
InvalidateRect doesn't work immediately, it just causes a WM_PAINT message to get generated eventually. Other messages have priority, so it may be a while before the window repaints. This is usually what you want though - the app shouldn't become unresponsive just because it's constantly repainting itself.
Mark Ransom
Yes, you are right, thanks for a notice - "immediate" left from the previous post version. Fixed.
Rageous
+1  A: 

Looks like you're using MFC.

I believe your app is busy and not processing messages from the queue, so it's not processing the WM_PAINT that would update the window.

Use the RDW_UPDATENOW parameter with RedrawWindow to force the repaint, even when your window is busy.

Mark Ransom
+2  A: 

You could use UpdateWindow in conjunction with InvalidateRect to get an immediate redraw.

lx
A: 

But in release version it doesn't function correctly also if with openeed worspace it seem to go

It's not clear which answer you're responding to. Put your responses into the original question as Edits.
egrunin
A: 

For client area use InvalidateRect + UpdateWindow. If you want to redraw the non-client area of the window, try calling SetWindowPos with SWP_DRAWFRAME | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE.

Alex Jenter