VB无所不能之四:制作透明和半透明窗体- Java程序员,上班那点事儿 ...
函数声明:

Declare Function SetLayeredWindowAttributes Lib "user32" () Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

hwnd是透明窗体的句柄,
crKey为颜色值,
bAlpha是透明度,取值范围是[0,255],
dwFlags是透明方式,可以取两个值:当取值为LWA_ALPHA时,crKey参数无效,bAlpha参数有效;
当取值为LWA_COLORKEY时,bAlpha参数有效而窗体中的所有颜色为crKey的地方将变为透明
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" () Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" () Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function SetLayeredWindowAttributes Lib "user32" () Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Private Const WS_EX_LAYERED = &H80000
Const GWL_EXSTYLE = () Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1

Sub Form_Load() Sub Form_Load()
        Dim rtn As Long
        rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
        rtn = rtn Or WS_EX_LAYERED
        SetWindowLong hwnd, GWL_EXSTYLE, rtn
        SetLayeredWindowAttributes hwnd, 0, 100, LWA_ALPHA
End Sub
GetWindowLong Lib "user32" Alias "GetWindowLongA" () GetWindowLong Lib "user32" Alias "GetWindowLongA" ( GetWindowLong Lib "user32" Alias "GetWindowLongA" () GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long    
SetWindowLong Lib "user32" Alias "SetWindowLongA" () SetWindowLong Lib "user32" Alias "SetWindowLongA" ( SetWindowLong Lib "user32" Alias "SetWindowLongA" () SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long    
SetLayeredWindowAttributes Lib "user32" () SetLayeredWindowAttributes Lib "user32" ( SetLayeredWindowAttributes Lib "user32" () SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long    

Private Const WS_EX_LAYERED = &H80000    
Const GWL_EXSTYLE = () Const GWL_EXSTYLE = (-20)    
Private Const LWA_ALPHA = &H2    
Private Const LWA_COLORKEY = &H1    

Sub Form_Load() Sub Form_Load()
        Dim rtn As Long
        BorderStyler = 0
        rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
        rtn = rtn Or WS_EX_LAYERED
        SetWindowLong hwnd, GWL_EXSTYLE, rtn
        SetLayeredWindowAttributes hwnd, &HFF0000, 0, LWA_COLORKEY                '将扣去窗口中的蓝色
End Sub

发表于 @ 2010年04月13日 17:16:00 | | | |

郑重声明:资讯 【VB无所不能之四:制作透明和半透明窗体- Java程序员,上班那点事儿 ...】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——