I'm writing a win32 app that re-paints the client area everytime the user clicks inside of it. Unfortunately after about 25 or 26 clicks the window gets painted white, but the black grid lines still appear.

The WM_PAINT case goes through a for loop and asks another class what should be at that square and displays it.

I've tried adding a timer that repaints the screen whenever a flag is put up, but the same thing happens.

Any ideas? Thanks

I'm writing a win32 app that re-paints the client area everytime the user clicks inside of it. Unfortunately after about 25 or 26 clicks the window gets painted white, but the black grid lines still appear.

The WM_PAINT case goes through a for loop and asks another class what should be at that square and displays it.

I've tried adding a timer that repaints the screen whenever a flag is put up, but the same thing happens.

Any ideas? Thanks

Looks like there is a resource leak in your code. You are probably not releasing the Device Context by using ReleaseDC. If you are using fonts, maybe it is a font that you are not releasing. Post the code for the WM_PAINT event and the clicking event.

I'm not getting the device context, I'm using BeginPaint and EndPaint. I tried using GetDC and ReleaseDC, but instead of messing up after 25 clicks, it messed up immediately. Thanks for the suggestion though. And by mess up, I mean instead of a green grid with black borders, it becomes white with black borders and attempting to move the window paints the whole screen white or green.

Here's my code:

case WM_PAINT:
{
	PAINTSTRUCT ps;
	HDC hdc = BeginPaint(hwnd, &ps);
	//HDC hdc = GetDC(hwnd);
	RECT rect;
	for(int x = 0; x < map.getMaxX(); x++)
		for(int y = 0; y < map.getMaxY(); y++) {
			rect.left = x*BOX;
			rect.top = y*BOX;
			rect.right = rect.left + BOX;
			rect.bottom = rect.top + BOX;
			if(!map.isEmpty(x,y))
				FillRect(hdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH));
			else if(map.isSelect(x,y))
				FillRect(hdc, &rect, CreateSolidBrush(RGB(0,0,255)));
			else if(map.isHighlight(x,y))
				FillRect(hdc, &rect, CreateSolidBrush(RGB(255,255,255)));
			else
				FillRect(hdc, &rect, CreateSolidBrush(background));
			FrameRect(hdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH));
		}
	//ReleaseDC(hwnd, hdc);
	EndPaint(hwnd, &ps);
	return 0;
}

case WM_LBUTTONDOWN:
	map.lclick(LOWORD(lParam)/BOX, HIWORD(lParam)/BOX);
	InvalidateRect(hwnd, 0, 1);
	return 0;
case WM_RBUTTONDOWN:
	map.rclick(LOWORD(lParam)/BOX, HIWORD(lParam)/BOX);
	InvalidateRect(hwnd, 0, 1);
	return 0;

The map class stores information about what to paint in each square and updates the map when the user clicks on a square.

i guess, when u are creating a brush u need to distroy it also using DeleteObject, currently it seems to be a leak.

else if(map.isSelect(x,y))
                FillRect(hdc, &rect, CreateSolidBrush(RGB(0,0,255)));

is it working?? i guess u need to select brush, by using SelectObject.
or else u can use
GetSysColorBrush

i dont have any system rite at this moment, so that i can run your code, but as soon as i will be able to see it running it, may be i reach in a better condition to help u....

Yeah that was it, thanks. I needed to delete each brush I was creating. I'd never needed 400 brushes to be created per frame before. Thanks.

Yeah, that tutorial's a great start. I use Charles Petzold's book more now though. It's amazing. Since my apps are all small I stick to win32. I use java for web apps and when I want something portable. .net just seems too bloated for really small programs. That's just me though.
Thanks for the reply

This question has already been answered. Start a new discussion instead.