views:

293

answers:

1

I have a Win32 GUI application that has several edit controls (plain old "EDIT" classname).

The logic is that the user is to fill the edit box selected by the application. To make it clearer which one is to be filled now I want to somehow highlight the "current" edit box. Then, when the user has done input and asked the application to proceed the edit box would have to become "usual" again.

The ideal way would be to paint its background with a color of choice. How could I achieve this or similar selection - maybe I could substitute the brush used to paint the control temporarily? If it's not possible with edit control what replacement controls available in Windows starting with Win2k are out there?

+3  A: 

You can handle the WM_CTLCOLOREDIT notification in the parent window for the edit controls. The notification is sent when the edit control is about to be drawn. So in general, you would use RedrawWindow or something to force a redraw, then handle the inevitable control colour notification. In this, you set the fore and back colour for the device context which is passed in with the notification:

LRESULT OnControlColorEdit(HWND hwnd, DWORD msg, WPARAM wParam, LPARAM lParam)
{
   if( !toHighlight ) {
       return DefWindowProc( hwnd, msg, wParam, lParam );
   }
   HDC dc = reinterpret_cast<HDC>(wParam);
   ::SetBkColor(dc, whatever);
   ::SetTextColor(dc, whatever);
   HBRUSH brush = // create a solid brush of necessary color - should cache it and destroy when no longer needed
   return reinterpret_cast<LRESULT>( brush );
}
1800 INFORMATION
I believe you need to return an HBRUSH (rather than zero) in order to paint the background of the control. See the comment at the end of http://msdn.microsoft.com/en-us/library/bb761691(VS.85).aspx
RichieHindle
Yes, a brush should be returned each time. Meanwhile the general idea works just fine. Thanks a lot.
sharptooth
yeah sorry that was more or less off the cuff, thanks for the edit
1800 INFORMATION
Instead of creating a brush for this, you can use SetDCBrushColor and return the DC brush. See http://blogs.msdn.com/410031.aspx
Michael Dunn