在VB6.0中,如何实现窗体透明化?

如题,怎么实现透明化(控件不透明,要是控件也透明的话,不如直接使用Hide算了。)对了,当透明化之后,怎样退出透明化,变为普通样式?... 如题,怎么实现透明化(控件不透明,要是控件也透明的话,不如直接使用Hide算了。)
对了,当透明化之后,怎样退出透明化,变为普通样式?
展开
 我来答
jxjj2009
2010-10-23 · TA获得超过1483个赞
知道小有建树答主
回答量:1108
采纳率:0%
帮助的人:872万
展开全部
建立一个模块:

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
烟花坑zZ
2010-10-23 · TA获得超过1196个赞
知道小有建树答主
回答量:542
采纳率:0%
帮助的人:755万
展开全部
’添加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

参考资料: http://www.vb60.tk/forum.php?mod=viewthread&tid=64&extra=page%3D1

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式