800ish WM_PAINT Messages per second?

I'm not even sure where to start.

I put the following code in my WM_PAINT message handler, near the top before the switch:
1
2
3
4
5
if (message==15){
	char t[50];
	OutputDebugString(itoa(tempcounter++,t,10));
	OutputDebugString("\r\n");
}


tempcounter is just a global int

The output window shows an ever-incrementing integer... going up by roughly 800 per second.

I put breakpoints on every InvalidateRect in my code, and at present I'm watching the number increment without hitting any breakpoints.

If I throw a breakpoint in WM_PAINT I don't see anything... I'm not invalidating within my pain function.

This flood of messages is causing my WM_TIMER messages to get dropped.

It started happening after I implemented double buffering to remove screen flicker. If I remove my double buffering code, the problem goes away.

Non-double-buffering code:
1
2
3
4
5
6
7
8
9
10
11
case WM_PAINT:
	hdc=BeginPaint(MsghWnd,&ps);
	if(detailed<0){
		for (int i=0;i<PanelCount;i++)
			if (monitors[i]->IsMyHWND(MsghWnd)){
				monitors[i]->Paint(hdc);  ///calls DrawText a bunch.
			}
	}else{
		monitors[detailed]->Paint(hdc);  /// calls DrawText a bunch.
	}
	EndPaint(MsghWnd,&ps);


Double Buffering Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
case WM_PAINT:
if(detailed<0){
	for (int i=0;i<PanelCount;i++)
		if (monitors[i]->IsMyHWND(MsghWnd)){
			hdc=BeginPaint(monitors[i]->GetHWND(),&ps);
			GetClientRect(monitors[i]->GetHWND(),&rect);
			compatDC=CreateCompatibleDC(hdc);
			compatBitmap=CreateCompatibleBitmap(hdc,rect.right,rect.bottom);
			oldBitmap=SelectObject(compatDC,compatBitmap);
			if (i%2==0)
				FillRect(compatDC,&rect,brush1);
			else
				FillRect(compatDC,&rect,brush2);
			monitors[i]->Paint(compatDC);
			BitBlt(hdc,0,0,rect.right,rect.bottom,compatDC,0,0,SRCCOPY);
			SelectObject(compatDC,oldBitmap);
			DeleteObject(compatBitmap);
			DeleteDC(compatDC);
			EndPaint(monitors[i]->GetHWND(),&ps);
			}
}else{
	hdc=BeginPaint(DetailPanel,&ps);
	GetClientRect(DetailPanel,&rect);
	compatDC=CreateCompatibleDC(hdc);
	compatBitmap=CreateCompatibleBitmap(hdc,rect.right,rect.bottom);
	oldBitmap=SelectObject(compatDC,compatBitmap);
	FillRect(compatDC,&rect,brush1);
	monitors[detailed]->Paint(compatDC);
	BitBlt(hdc,0,0,rect.right,rect.bottom,compatDC,0,0,SRCCOPY);
	SelectObject(compatDC,oldBitmap);
	DeleteObject(compatBitmap);
	DeleteDC(compatDC);
	EndPaint(DetailPanel,&ps);
}


Any ideas?
Last edited on
Additional details, the result of my ongoing debug:

The application resembles an MDI interface... a parent window (HWND hWnd) with a number of child windows (HWND *Panel_hWnd).

Within my WndProc, the HWND being sent to the function is that of my hWnd... which is odd, because it doesn't do -anything-.
Additional debugging info:

The problem occurs in my outer-most IF statement (rather than in the following ELSE statement). If it goes to the else (and starts working with the DetailPanel) then it does not fire off loads of WM_PAINTs.

I must've coded something wrong in the double buffering, but I honestly have no idea.
Most likely the issue is that you have your calls to BeginPaint() and EndPaint() inside the FOR loop, which is incorrect. Have a single pair of these per WM_PAINT.

Also make sure you use the HWND provided by the window message. You cannot call BeginPaint() with a different HWND.
Interesting.

I followed the logic in the debugger very closely, and BeginPaint was only ever being called once (since the IF following the FOR was only ever going to be true for one of the iterations of the loop).

However, moving my BeginPaint outside of the FOR loop did indeed resolve the issue.

You have my thanks... I wouldn't have even thought to try that.
Topic archived. No new replies allowed.