在VB6.0中,如何实现窗体透明化?
如题,怎么实现透明化(控件不透明,要是控件也透明的话,不如直接使用Hide算了。)对了,当透明化之后,怎样退出透明化,变为普通样式?...
如题,怎么实现透明化(控件不透明,要是控件也透明的话,不如直接使用Hide算了。)
对了,当透明化之后,怎样退出透明化,变为普通样式? 展开
对了,当透明化之后,怎样退出透明化,变为普通样式? 展开
展开全部
建立一个模块:
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public Const WS_EX_LAYERED = &H80000
Public Const GWL_EXSTYLE = (-20)
Public Const LWA_ALPHA = &H2 '表示把窗体设置成半透明样式
Public Const LWA_COLORKEY = &H1 '表示不显示窗体中的透明色
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
'SetTransparentWindow(hwnd As Long, iTransparency As Integer)参数说明:
'hwnd为所要设置的窗体句柄
'iTransparency为透明度,为0-100的数,0表示不透明,100表示全透明
Public Sub SetTransparentWindow(hwnd As Long, iTransparency As Integer)
Dim rtn As Long
Dim iTransform As Integer
'iTransparency转换成SetLayeredWindowAttributes的第3个参数,即透明程度(取值范围0 --255)
iTransform = Int((100 - iTransparency) * 2.55)
rtn = GetWindowLong(hwnd, GWL_EXSTYLE) '取的窗口原先的样式
rtn = rtn Or WS_EX_LAYERED '使窗体添加上新的样式WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn '把新的样式赋给窗体
SetLayeredWindowAttributes hwnd, 0, iTransform, LWA_ALPHA '注释:把窗体设置成半透明样式 , 第3个参数iTransform表示透明程度,取值范围0 --255, 为0时就是一个全透明的窗体了
End Sub
在form1中直接:
Private Sub Form_Load()
SetTransparentWindow Me.hwnd, 60 '修改其中的60为0,则不透明
End Sub
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public Const WS_EX_LAYERED = &H80000
Public Const GWL_EXSTYLE = (-20)
Public Const LWA_ALPHA = &H2 '表示把窗体设置成半透明样式
Public Const LWA_COLORKEY = &H1 '表示不显示窗体中的透明色
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
'SetTransparentWindow(hwnd As Long, iTransparency As Integer)参数说明:
'hwnd为所要设置的窗体句柄
'iTransparency为透明度,为0-100的数,0表示不透明,100表示全透明
Public Sub SetTransparentWindow(hwnd As Long, iTransparency As Integer)
Dim rtn As Long
Dim iTransform As Integer
'iTransparency转换成SetLayeredWindowAttributes的第3个参数,即透明程度(取值范围0 --255)
iTransform = Int((100 - iTransparency) * 2.55)
rtn = GetWindowLong(hwnd, GWL_EXSTYLE) '取的窗口原先的样式
rtn = rtn Or WS_EX_LAYERED '使窗体添加上新的样式WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn '把新的样式赋给窗体
SetLayeredWindowAttributes hwnd, 0, iTransform, LWA_ALPHA '注释:把窗体设置成半透明样式 , 第3个参数iTransform表示透明程度,取值范围0 --255, 为0时就是一个全透明的窗体了
End Sub
在form1中直接:
Private Sub Form_Load()
SetTransparentWindow Me.hwnd, 60 '修改其中的60为0,则不透明
End Sub
展开全部
’添加Image1 装载背景为蓝色的图片(添加Picture1也可以但Borderstyle设为0,下面的Image1_Click退出改为Picture1_Click)
Option Explicit
'*****************************************透明窗体的API
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 SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cX As Long, ByVal cY As Long, ByVal wFlags 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
Const WS_EX_LAYERED = &H80000
Const GWL_EXSTYLE = (-20)
Const LWA_ALPHA = &H2
Const LWA_COLORKEY = &H1
'********************************************************************
Dim rtn&, transcolor&
Private Sub Form_Load()
transcolor = &HFF0000
Me.BorderStyle = 0
Me.Caption = ""
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
Me.BackColor = transcolor
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd, transcolor, 180, LWA_COLORKEY Or LWA_ALPHA '将扣去窗口中的蓝色背景
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set Form1 = Nothing
End
End Sub
Private Sub Image1_Click()
Unload Me
End Sub
Option Explicit
'*****************************************透明窗体的API
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 SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cX As Long, ByVal cY As Long, ByVal wFlags 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
Const WS_EX_LAYERED = &H80000
Const GWL_EXSTYLE = (-20)
Const LWA_ALPHA = &H2
Const LWA_COLORKEY = &H1
'********************************************************************
Dim rtn&, transcolor&
Private Sub Form_Load()
transcolor = &HFF0000
Me.BorderStyle = 0
Me.Caption = ""
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
Me.BackColor = transcolor
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd, transcolor, 180, LWA_COLORKEY Or LWA_ALPHA '将扣去窗口中的蓝色背景
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set Form1 = Nothing
End
End Sub
Private Sub Image1_Click()
Unload Me
End Sub
参考资料: http://www.vb60.tk/forum.php?mod=viewthread&tid=64&extra=page%3D1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询