VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



turn a color on form transparent

by Matt (8 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

Turn a certain color on the form or controls transparent

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

Rate turn a color on form transparent

' 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

Download this snippet    Add to My Saved Code

turn a color on form transparent Comments

No comments have been posted about turn a color on form transparent. Why not be the first to post a comment about turn a color on form transparent.

Post your comment

Subject:
Message:
0/1000 characters