读书人

vb能让子窗口透明吗?该如何处理

发布时间: 2013-06-19 10:26:41 作者: rapoo

vb能让子窗口透明吗?
如题。如果是顶级窗口,可以透明,如果是子窗口则无法透明,是这样的吗?

我的测试代码如下:


[解决办法]
都可以透明。
[解决办法]

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
'From******************Transparent****************
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 - Perc) / 100) * 255
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
'To******************Tramsparent****************

’调用
private sub form_laod ()
MakeTransparent Me.hWnd, 5
end if


[解决办法]
呵呵 楼主指的是 MDI 窗体吗? 我没试过,不过理论上还行,抽空来写个代码看看.

不过为何非要指定为子窗体呢?主要目的是啥?

下图是 Form1 Form2 任何一个窗体都可设定透明度与屏蔽指定的透明色

vb能让子窗口透明吗?该如何处理

[解决办法]
楼主不要急着结贴,俺也想看看高人写出的代码是什么样,期待着。
[解决办法]
在此留下一个脚印
看看高人如何编写出来
[解决办法]
vb能让子窗口透明吗?该如何处理有戏看了
[解决办法]
MDI子窗体呀?
[解决办法]
对mdi子窗体的子类化确实有问题,坐等高人
[解决办法]
实测 lxq19851204的代码,子窗口可以透明化。。。
[解决办法]



原窗体的标题栏部分未绘制,实际上是存在的,鼠标可点击拖动.

没有仔细研究里面的规律,也没那本事vb能让子窗口透明吗?该如何处理,有兴趣的自己研究吧

PS,挡控件的问题,可以将这个窗体设置为鼠标穿透样式即可.

鼠标穿透+透明+前置功能的封装模块:

http://www.m5home.com/bbs/forum.php?mod=viewthread&tid=2806&extra=page%3D2
[解决办法]
SetLayeredWindowAttributes实现不了子窗口透明。

读书人网 >VB

热点推荐