VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Semi transparent form 2000/XP

by Kjhel (1 Submission)
Category: Custom Controls/Forms/Menus
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (7 Votes)

Your standard semi transparent form in Win 2000/XP without the flickering. Comes with fade-in effect.

Assumes
Must be running Win 2000 equivalent or better 1 form needed - copy everything onto it.
API Declarations
Option Explicit
'
' Constants
'
Private Const LWA_ALPHA As Long = &H2
Private Const WS_EX_LAYERED As Long = &H80000
Private Const GWL_EXSTYLE As Long = -20
Private Const SW_SHOW As Long = 5
Private Const RDW_UPDATENOW As Long = &H100
'
' Declarations
'
Private Declare Function RedrawWindow Lib "user32" (ByVal hwnd As Long, _
lprcUpdate As Any, _
ByVal hrgnUpdate As Long, _
ByVal fuRedraw 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 GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex 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
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, _
ByVal nCmdShow As Long) As Long

Rate Semi transparent form 2000/XP

Private Sub Form_Load()
 Trans Me.hwnd, 1, 85
End Sub
Private Sub Trans(lngHwnd As Long, _
     Optional ByVal Speed As Byte = 1, _
     Optional ByVal OpaquePercent As Byte = 85)
Dim Cnt As Long
 On Error Resume Next
 'Layered window
 SetWindowLong lngHwnd, GWL_EXSTYLE, GetWindowLong(lngHwnd, GWL_EXSTYLE) Or WS_EX_LAYERED
 SetLayeredWindowAttributes lngHwnd, 0, 0, LWA_ALPHA
 'Smoothness
 ShowWindow lngHwnd, SW_SHOW
 RedrawWindow lngHwnd, ByVal 0&, ByVal 0&, RDW_UPDATENOW
 'Fade-in effect
 'OpaquePercent range = 0 to 100 [Default = 85]
 'Speed range = 0 to about 5 [Default = 1] (visible difference not much for higher values)
 For Cnt = 0 To OpaquePercent Step Speed
  SetLayeredWindowAttributes lngHwnd, 0, (Cnt / 100) * 255, LWA_ALPHA
 Next Cnt
End Sub

Download this snippet    Add to My Saved Code

Semi transparent form 2000/XP Comments

No comments have been posted about Semi transparent form 2000/XP. Why not be the first to post a comment about Semi transparent form 2000/XP.

Post your comment

Subject:
Message:
0/1000 characters