Search Tools Links Login

turn a color on form transparent


Visual Basic 6, or VB Classic

Turn a certain color on the form or controls transparent

Original Author: Matt

Inputs

Send the sub in module the form name or just me
and the color to make transparent
TransForm Me, rgb(0,0,0) Makes everything black on the form transparent

Side Effects

none yet

API Declarations

'windows 2000 only
'in module
'constants for transparency subs
Const LWA_COLORKEY = &H1
Const LWA_ALPHA = &H2
Const GWL_EXSTYLE = (-20)
Const WS_EX_LAYERED = &H80000
'api's for transparency subs
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public Sub TransForm(frmTrans As Form, transColor As Long)
Dim Ret As Long
Ret = GetWindowLong(frmTrans.hWnd, GWL_EXSTYLE)
Ret = Ret Or WS_EX_LAYERED
SetWindowLong frmTrans.hWnd, GWL_EXSTYLE, Ret
SetLayeredWindowAttributes frmTrans.hWnd, transColor, 255, LWA_COLORKEY
End Sub
Public Sub untransForm(frmunTrans As Form)
Dim Ret As Long
Ret = GetWindowLong(frmunTrans.hWnd, GWL_EXSTYLE)
Ret = Ret Or WS_EX_LAYERED
SetWindowLong frmunTrans.hWnd, GWL_EXSTYLE, Ret
SetLayeredWindowAttributes frmunTrans.hWnd, 0, 255, LWA_ALPHA
End Sub

Code

' in form with 2 command buttons
'cmdMakeTransparent
'cmdNoTransparency
Private Sub cmdMakeTransparent_Click()
'transform formname or me for current form, color which could be
'vbWhatever or rgb(r,g,b) or long number value
TransForm Me, vbWhite 'set the see through color to white

End Sub
Private Sub cmdNoTransparency_Click()
untransForm Me 'set nothing to transparent
End Sub

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 95 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.