dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB5,VB6
Expertise: Intermediate
Jan 29, 2000

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Create TextBox with dithered background

If your video display has 256 colors or less and you assign a dithered color to the BackColor property of a TextBox control, you'll find that the background color under the text inside the TextBox is displayed in a different (solid) color.

To work around this issue, you must trap the WM_CTLCOLOREDIT message, that the control sends to its parent form when its background is about to be redrawn, and you must explicitly set a transparent background for the control. Here's the code that does the job:


' REQUIRES THE MSGHOOK.DLL COMPONENT

Private Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, _
    ByVal nBkMode As Long) As Long

Const WM_CTLCOLOREDIT = &H133
Const TRANSPARENT = 1

Dim WithEvents FormHook As MsgHook
Dim TextHWnd As Long

Private Sub Form_Load()
    Set FormHook = New MsgHook
    FormHook.StartSubclass Me
    TextHWnd = Text1.hWnd
End Sub

Private Sub FormHook_BeforeMessage(uMsg As Long, wParam As Long, lParam As Long, _
    retValue As Long, Cancel As Boolean)
    If uMsg = WM_CTLCOLOREDIT And lParam = TextHWnd Then
       SetBkMode wParam, TRANSPARENT
    End If
End Sub
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date