Too many WM_PAINT

Nov 11, 2010 at 1:21am
Hi.

My application is getting some ridiculous amount of WM_PAINT messages. I made the program outup to a file the messages on the message loop, and I'm getting something like 20 paint messages each 10 miliseconds.

First of all, I'm using OpenGL and the Windows API in C.

I was trying to use PeekMessage to do some kind of "idle" function, but the queue never gets empty. I've already tried removing WM_PAINT from my WndProc, but it still keeps dispatching the endless paint messages.

I know it may be hard to tell without seeing the code, but I'm looking for some tips to what can be causing this.
Nov 11, 2010 at 1:25am
Please provide your PeekMessage loop, your WndProc method and the constructor to your window.
Nov 11, 2010 at 1:43am
Message loop:

1
2
3
4
5
6
7
8
9
10
11
12
MSG msg;
running = true;

do
{
	while(PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	// idle function here
} while(running);


WndProc is a big switch that transfers each message to a specific function (like WM_PAINT to onPaint). I've already tried removing all case clauses and leaving "case WM_PAINT" empty, but that didn't work.

What do you mean by "constructor to your window"?
Nov 11, 2010 at 1:47am
You're not validating the window.

There are two ways to do this. The best way is with BeginPaint() and EndPaint()

1
2
3
4
5
6
7
8
9
// this is from memory -- I might be wrong on some details...
case WM_PAINT:
  PAINTSTRUCT ps;
  HDC dc = BeginPaint(hwnd,&ps);

  // do drawing to 'dc' here -- or don't

  EndPaint(hwnd,&ps);
  break;


Do this even if you don't do any drawing to the DC.

If you are drawing to the DC, don't use GetDC()/ReleaseDC() from WM_PAINT
Nov 11, 2010 at 2:08am
Thanks, that solved my problem. I'm really becoming a fan of this forum, people always helped me much faster than I expected. Thanks again.


But just to make sure I'm doing this right: I added that to my onPaint function and the window stopped drawing its content (because I'm not invalidating it, right?). So, I used my idle function (that now works) and a timer to invalidate it at 10 miliseconds intervals, and now everything works fine.
Topic archived. No new replies allowed.