Semi Transparent Form using VB6

后端 未结 2 2009
鱼传尺愫
鱼传尺愫 2020-12-19 22:47

Is it possible to create a form that is semi transparent, It should be visible over any open windows, not hidden behind ? Please guide!

2条回答
  •  一生所求
    2020-12-19 23:09

    'function to make transparent'
    
    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 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 Const G = (-20)
    Private Const LWA_COLORKEY = &H1        'to trans'
    Private Const LWA_ALPHA = &H2           'to semi trans'
    Private Const WS_EX_LAYERED = &H80000
    
    Private Sub Form_Activate()
        Me.BackColor = vbBlue
        Trans 1
    End Sub
    
    Private Sub Trans(Level As Integer)
        Dim Msg As Long
        Msg = GetWindowLong(Me.hwnd, G)
        Msg = Msg Or WS_EX_LAYERED
        SetWindowLong Me.hwnd, G, Msg
        SetLayeredWindowAttributes Me.hwnd, vbBlue, Level, LWA_COLORKEY
    End Sub
    

提交回复
热议问题