HOWTO: Display Text on a Dithered Background in a TextBoxLast reviewed: September 25, 1997Article ID: Q174301 |
The information in this article applies to:
SUMMARYWhen a dithered color is selected as the background of a TextBox, the background around the text is displayed as a different, solid color when the display is set for 256 colors or less. To work around this limitation, you must hook the WM_CTLCOLOREDIT message and set the text background color to TRANSPARENT. This is not a trivial alternative, and using a solid background color is recommended if at all possible.
MORE INFORMATIONWARNING: ANY USE BY YOU OF THE SAMPLE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this sample code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. WARNING: Failure to unhook a window before its imminent destruction will result in application errors, Invalid Page Faults, and data loss. This is due to the fact that the new WindowProc function being pointed to no longer exists, but the window has not been notified of the change. Always unhook the sub-classed window upon unloading the sub-classed form or exiting the application. This is especially important while debugging an application that uses this technique within the Microsoft Visual Basic 5.0 Development Environment. Pressing the END button or selecting End from the Run menu without unhooking will cause an Invalid Page Fault and close Microsoft Visual Basic. A TextBox control cannot draw text with a dithered background color, but it can draw text with a transparent background color. If the background of the control is dithered, this achieves the same visual effect. (Note the distinction between the background of the text and the background of the control. It is simple to get the control's background dithered; the problem is getting the text background dithered as well.) From the SDK perspective, the answer is simple; handle the WM_CTLCOLOREDIT message in the parent and call SetBkMode() to set the background mode to TRANSPARENT. This is less simple in Visual Basic. The following application consists of a form with a single Textbox control and a code module:
REFERENCESFor additional information, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q16879 TITLE : HOWTO: Hook Into a Window's Messages Using AddressOf Keywords : VBKBCtrl VBKBInt VBKBStd VBKBTextBox VBKBWinAPI Version : WINDOWS:5.0 Platform : WINDOWS Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |