In plain Win32 programming(No MFC) ,i wanted to change an edit control's foreground color(text color) and the entire edit control's background color. So i intercepted the wm_paint message and wm_ctlcoloredit.Code is

wm_ctlcoloredit

HDC hdc=(HDC)wParam;
//COLORREF forecolor and backcolor are already defined
SetBkMode(hdc,OPAQUE);
SetTextColor(hdc,forecolor);
SetBkColor(hdc,backcolor);

wm_paint

HDC thdc;
PAINTSTRUCT ps;
thdc=BeginPaint(hwnd,&ps); //hwnd is handle of the edit control
RECT r;
r.top = 0;
r.left = 0;
r.bottom = height - 4; //height is height of edit control
r.right = width - 4; //width is widthof edit control
FillRect(thdc,&r,CreateSolidBrush(backcolor));
EndPaint(mem->hwnd,&ps);


THE PROBLEM:-

Let us say the backcolor is yellow.When the form has loaded, the edit control is filled with a yellow color and no text. However when i click the edit control it becomes ok and the text,forecolor and backcolor are displayed correctly. If i minimize and then maximize , same problem reoccurs. How do i fix this? (I am NOT intercepting wm_lbuttonup or any click messages so problem doesnt seem to relate to the click). Help.