How to change the background color of an MFC edit control (117778)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++ for Windows, 16-bit edition 1.0
- Microsoft Visual C++ for Windows, 16-bit edition 1.5
- Microsoft Visual C++ for Windows, 16-bit edition 1.51
- Microsoft Visual C++ for Windows, 16-bit edition 1.52
- Microsoft Visual C++, 32-bit Editions 1.0
- Microsoft Visual C++, 32-bit Editions 2.0
- Microsoft Visual C++, 32-bit Editions 2.1
- Microsoft Visual C++, 32-bit Editions 4.0
- Microsoft Visual C++, 32-bit Editions 4.1
- Microsoft Visual C++, 32-bit Enterprise Edition 4.2
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 4.2
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
- Microsoft Visual C++ .NET (2002)
- Microsoft Visual C++ .NET (2003)
This article was previously published under Q117778 Note Microsoft Visual C++ .NET 2002 and Microsoft Visual C++ .NET 2003 support both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code. SUMMARY To change the background color of an edit control in an MFC
application, you must override the OnCtlColor() message-handling function of
the window containing the edit control.
In the new OnCtlColor()
function, set the background color and return a handle to a brush that will be
used for painting the background. This must be done in response to receiving
both the CTLCOLOR_EDIT and CTLCOLOR_MSGBOX messages in the OnCtlColor()
function.
This is also documented in the "Class Library Reference"
under CWnd::OnCtlColor().
Modification Type: | Major | Last Reviewed: | 6/9/2005 |
---|
Keywords: | kbcode kbhowto KbUIDesign KB117778 kbAudDeveloper |
---|
|