-
Continuous WM_PAINT
I am making a small Visual C++ program. It's supposed to generate a random number, ask the user for a number, compare the number with the generated number, and open a new window telling the user if he is correct or incorrect.
Now, I am using a painted window to display output. in WM_PAINT, I first get the window's area, then paints a filled rectangle and text to the window's hdc (which I obtained in WM_CREATE using the GetDC function). The problem is, the window KEEPS on repainting itself and I ran out of GDI resources in like ten seconds. Does anyone know what caused this WM_PAINT loop?
-
Call ValidateRect(hWnd, NULL) as the last line of your WM_PAINT handler. It tells windows to stop senting WM_PAINT until it needs to be done again. Otherwise, windows will send WM_PAINT until it gets a ValidateRect().
Z.
-
better yet, call BeginPaint and EndPaint in the WM_PAINT handler.