Author : Raghunathan
Date Submitted : 11/15/2006
Category : Windows Operations
Compatibility : VB 6
This code has been accessed 5822 times.
Task : Creating a VB Form with Opacity Control like Windows Forms in .NET Framework, using Win32 Api (Works only with Windows 2000 and above)
Declarations
Code
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Form_Initialize()
If App.PrevInstance Then
MsgBox "Application is Already Running", vbExclamation, "Opaque"
End
End If
End Sub
Private Sub Form_Load()
bTrans = 0
'To Set the Style of the Window as LAYERED so that opacity can be
controlled
lOldStyle = SetWindowLong(Me.hwnd, GWL_EXSTYLE, WS_EX_LAYERED)
Timer1.Enabled = True
Timer1.Interval = 25
'To Disable the Close Button (X) of the Form
Dim hMenu As Long
hMenu = GetSystemMenu(Me.hwnd, False)
DeleteMenu hMenu, 6, MF_BYPOSITION
'To Make the Window On Top Of All The Windows
SetWindowPos Me.hwnd, HWND_TOPMOST, 10, 10, 345, 100, 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
Cancel = True
Timer2.Enabled = True
Timer2.Interval = 25
End Sub
Private Sub Timer1_Timer()
bTrans = bTrans + 5
If bTrans >= 255 Then
Timer1.Enabled = False
Exit Sub
End If
SetLayeredWindowAttributes Me.hwnd, 0, bTrans, LWA_ALPHA
End Sub
Private Sub Timer2_Timer()
bTrans = bTrans - 5
If bTrans <= 0 Then
Timer2.Enabled = False
End
End If
SetLayeredWindowAttributes Me.hwnd, 0, bTrans, LWA_ALPHA
End Sub