WM_PAINT trouble

So I have this code in WM_PAINT case:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
HDC hdc=GetDC(hWnd);
RECT rc={5,10,120,400};
SelectObject(hdc,GetStockObject(DEFAULT_GUI_FONT));
SetBkMode(hdc,TRANSPARENT);
SetTextColor(hdc,RGB(0,0,0));
long fHeight=-MulDiv(12,GetDeviceCaps(hdc,LOGPIXELSY),72);
HFONT hF=CreateFont(fHeight,0,0,0,FW_NORMAL,0,0,0,0,0,0,0,0,L"Times New Roman");
HGDIOBJ hPrevFont=SelectObject(hdc,(HGDIOBJ)hF);
for(int i=0;i<27;i++)
{
	if(rc.top+25>=400)
	{
		rc.top=10;
		rc.left+=250;
		rc.right=rc.left+120;
	}
	wstring str=props[i].first;
	DrawText(hdc,str.c_str(),str.length(),&rc,DT_CENTER|DT_WORDBREAK);
	rc.top+=25;
}
SelectObject(hdc,hPrevFont);
ReleaseDC(hWnd,hdc);


basicaly it lists multiple options. But I also have a number-only edit boxes, upon inputing a non-number character the text gets redrawn, making it thicker and thicker(eventualy it becomes very ugly), same happens if you move the window. Now I've guessed that the DrawText function draw upon already visible text(I've used it to get transparent text background)

One option would be painting the backgound to original color everytime WM_PAINT occured...But I don't know how(I also can't seem to find it on google), can anyone help with that? Or maybe pass an alternative?
Last edited on
This is not quite the correct way to do things in response to a WM_PAINT message.
You should at least call BeginPaint and EndPaint functions - these are very important in relation to WM_PAINT.

1
2
3
4
5
6
7
8
9
10
case WM_PAINT:
{
    PAINTSTRUCT psPaint;
    HDC hdc = BeginPaint( hwnd, &psPaint );

    //Do your painting/drawing here

   EndPaint (hwnd, &psPaint);
   return 0;
}


As well as filling in the paintstruct, the BeginPaint
function also sends the WM_ERASEBKGND message
to the window.

One of the things the EndPaint function does, is to release the
DC that you got from the BeginPaint function.

The WM_PAINT messahe should return zero, otherwise the system
will assume painting has not been completed and will keep
sending you WM_PAINT messages.

You can read all of this on MSDN, and other tutorials on the web.
Okay that solved it, thanks!
Topic archived. No new replies allowed.