Reputation: 170509
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?
Upvotes: 1
Views: 1315
Reputation: 135375
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 );
}
Upvotes: 5