VB6.0如何改变整个窗体的透明度?

gcrdf 2010-08-03 03:06:28
想在窗体中添加一个控件,然后,拖后它来改变整个窗体的透明度,如何实现?
...全文
259 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
嗷嗷叫的老马 2010-08-03
  • 打赏
  • 举报
回复
-_-b..........
gcrdf 2010-08-03
  • 打赏
  • 举报
回复
OK!我会了!!!
gcrdf 2010-08-03
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 ameken 的回复:]
VB code

Private Sub Form_Load()
Slider1.Min = 0
Slider1.Max = 255
MakeTransparent Me.hWnd, Slider1.Value
End Sub

Private Sub Slider1_Change()
MakeTransparent Me.hWnd, Slider1.Value
……
[/Quote]
谢谢。不过还差了一点就更完美了。就是程序运行后,需要窗体透明度100%显示的,而现在是0%显示的,我都看不见窗体在哪- -!如何改成100%显示呀?
天-笑 2010-08-03
  • 打赏
  • 举报
回复

[Quote=引用 2 楼 ameken 的回复:]
VB code

'Transparancy API's
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……
[/Quote]

不错
fjm_520 2010-08-03
  • 打赏
  • 举报
回复
强悍 也学习了
Dision LI 2010-08-03
  • 打赏
  • 举报
回复

Private Sub Form_Load()
Slider1.Min = 0
Slider1.Max = 255
MakeTransparent Me.hWnd, Slider1.Value
End Sub

Private Sub Slider1_Change()
MakeTransparent Me.hWnd, Slider1.Value
End Sub

饭送到你口里了,嘿嘿
lxq19851204 2010-08-03
  • 打赏
  • 举报
回复
Private Sub Form_Load()
MakeTransparent Me.hWnd, 50 '调整透明度为第二个参数
End Sub

控件长度为100,拖动中获取的值x
传递到MakeTransparent Me.hWnd, X
gcrdf 2010-08-03
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ameken 的回复:]
VB code

'Transparancy API's
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……
[/Quote]
确实改变了窗体的透明度,我如何随着这个控件的滑动来改变整个窗体的透明度呢?
lxq19851204 2010-08-03
  • 打赏
  • 举报
回复
2L正确。
Dision LI 2010-08-03
  • 打赏
  • 举报
回复

'Transparancy API's
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 UpdateLayeredWindow Lib "user32" (ByVal hWnd As Long, ByVal hdcDst As Long, pptDst As Any, psize As Any, ByVal hdcSrc As Long, pptSrc As Any, crKey As Long, ByVal pblend As Long, 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 GWL_EXSTYLE = (-20)
Private Const LWA_COLORKEY = &H1
Private Const LWA_ALPHA = &H2
Private Const ULW_COLORKEY = &H1
Private Const ULW_ALPHA = &H2
Private Const ULW_OPAQUE = &H4
Private Const WS_EX_LAYERED = &H80000


Public Function isTransparent(ByVal hWnd As Long) As Boolean
On Error Resume Next
Dim Msg As Long
Msg = GetWindowLong(hWnd, GWL_EXSTYLE)
If (Msg And WS_EX_LAYERED) = WS_EX_LAYERED Then
isTransparent = True
Else
isTransparent = False
End If
If Err Then
isTransparent = False
End If
End Function

Public Function MakeTransparent(ByVal hWnd As Long, ByVal Perc As Integer) As Long
Dim Msg As Long
On Error Resume Next


If Perc < 0 Or Perc > 255 Then
MakeTransparent = 1
Else
Msg = GetWindowLong(hWnd, GWL_EXSTYLE)
Msg = Msg Or WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, Msg
SetLayeredWindowAttributes hWnd, 0, Perc, LWA_ALPHA
MakeTransparent = 0
End If
If Err Then
MakeTransparent = 2
End If
End Function

Public Function MakeOpaque(ByVal hWnd As Long) As Long
Dim Msg As Long
On Error Resume Next
Msg = GetWindowLong(hWnd, GWL_EXSTYLE)
Msg = Msg And Not WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, Msg
SetLayeredWindowAttributes hWnd, 0, 0, LWA_ALPHA
MakeOpaque = 0
If Err Then
MakeOpaque = 2
End If
End Function

Private Sub Form_Load()
MakeTransparent Me.hWnd, 50 '调整透明度为第二个参数
End Sub


在你上面图中的控件调用MakeTransparent函数即可
  • 打赏
  • 举报
回复
http://forums.techarena.in/software-development/1092604.htm

7,757

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧