| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2890 人关注过本帖
标题:[求助]请问怎么把form窗体变全透明呢??
只看楼主 加入收藏
shengkang0
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2007-3-5
收藏
 问题点数:0 回复次数:12 
[求助]请问怎么把form窗体变全透明呢??
我想把VB窗体全部都是透明的``不是半透明喔```请问有什么办法``??谢谢
搜索更多相关主题的帖子: form 窗体 
2007-03-06 22:15
清澂居士
Rank: 6Rank: 6
等 级:贵宾
威 望:28
帖 子:1237
专家分:7
注 册:2006-12-19
收藏
得分:0 

Option Explicit

'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

Perc = 100
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, 20
End Sub

[此贴子已经被作者于2007-3-6 23:55:12编辑过]


佛曰:\"前世的500次回眸才换来今生的一次擦肩而过\".我宁愿用来世的一次擦肩而过来换得今生的500次回眸.
2007-03-06 23:05
wyfandy
Rank: 1
来 自:深圳
等 级:新手上路
帖 子:376
专家分:0
注 册:2006-12-11
收藏
得分:0 

二楼的方法好像是半透明吧!下面代码是全透明的窗体.
[CODE]Option Explicit
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
Const WS_EX_LAYERED = &H80000
Const GWL_EXSTYLE = (-20)
Const LWA_ALPHA = &H2
Const LWA_COLORKEY = &H1
Private Sub Form_Load()
Dim sty As Long
sty = GetWindowLong(Me.hwnd, GWL_EXSTYLE)
sty = sty Or WS_EX_LAYERED
SetWindowLong Me.hwnd, GWL_EXSTYLE, sty
SetLayeredWindowAttributes Me.hwnd, 0, 0, LWA_ALPHA
End Sub[/CODE]


[此贴子已经被作者于2007-3-7 0:04:19编辑过]


不论什么事,只要认准了一个目标,然后朝之不懈地努力,就一定实现。编程爱好者QQ群:21318556
2007-03-07 00:02
PcrazyC
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:5652
专家分:0
注 册:2006-10-20
收藏
得分:0 
回复:(shengkang0)[求助]请问怎么把form窗体变全透...
AMB7AGvw.rar (2.25 KB) [求助]请问怎么把form窗体变全透明呢??



0为全透明,255为不透明

雁无留踪之意,水无取影之心
2007-03-07 10:56
shengkang0
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2007-3-5
收藏
得分:0 
谢谢各位的帮助!~
2007-03-07 12:16
zhulei1978
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:53
帖 子:1351
专家分:1200
注 册:2006-12-17
收藏
得分:0 
窗体上的控件也变得透明了,能不能让控件不透明。

[此贴子已经被作者于2007-3-7 20:11:14编辑过]



其实我就是改变社会风气,提高少女素质,刺激电影市道,提高年轻人内涵,玉树临风,风度翩翩的整蛊专家,我名叫古晶,英文名叫JingKoo!
2007-03-07 20:10
PcrazyC
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:5652
专家分:0
注 册:2006-10-20
收藏
得分:0 
想实现VISTA界面的效果,我也想,不会

雁无留踪之意,水无取影之心
2007-03-07 20:25
gkimjatl
Rank: 1
等 级:新手上路
帖 子:106
专家分:0
注 册:2007-3-20
收藏
得分:0 


这个是一窗体慢慢载入的程序(从不可见到完全显示)。。


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 GetWindowLong Lib "user32" _
Alias "GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long) _
As Long

Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA As Long = &H2
Private Const WS_EX_LAYERED As Long = &H80000

Private Declare Function SetLayeredWindowAttributes Lib "user32" _
(ByVal hwnd As Long, _
ByVal crKey As Long, _
ByVal bAlpha As Long, _
ByVal dwFlags As Long) _
As Long
Dim i As Long

Private Sub Form_Load()
i = 0
Timer1.Interval = 10
Timer1.Enabled = True
Dim p As Long
p = GetWindowLong(Me.hwnd, GWL_EXSTYLE) '取得当前窗口属性
Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, p Or WS_EX_LAYERED)
'加上一个透明属性
Call SetLayeredWindowAttributes(Me.hwnd, 0, i, LWA_ALPHA)
End Sub

Private Sub Timer1_Timer()
i = i + 8
If i > 255 Then
i = 255
Call SetLayeredWindowAttributes(Me.hwnd, 0, i, LWA_ALPHA)
Timer1.Enabled = False
Else
Call SetLayeredWindowAttributes(Me.hwnd, 0, i, LWA_ALPHA)
End If
End Sub

2007-03-20 22:42
skdyu
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2007-3-26
收藏
得分:0 
谢谢指教!!!!
2007-03-26 16:15
happywxf2008
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-4-10
收藏
得分:0 

真的是难
这么多函数啥的太难了
多练习

2007-04-11 10:39
快速回复:[求助]请问怎么把form窗体变全透明呢??
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033403 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved