vb窗体透明的问题

我的窗体设置了半透明,有没有什么代码使得,鼠标移至半透明状态下的图片时,图片不再半透明窗体半透的代码如下:OptionExplicit'TransparancyAPI's... 我的窗体设置了半透明,有没有什么代码使得,鼠标移至半透明状态下的图片时,图片不再半透明

窗体半透的代码如下:
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
展开
 我来答
来自玄素洞英俊潇洒的绣球花
2010-07-26 · TA获得超过142个赞
知道小有建树答主
回答量:99
采纳率:0%
帮助的人:122万
展开全部
这种东西我只给思路,既然你已经设计到API编程了,那么我相信你应该能理解并能实际操作我说的话。
因为图片是放在控件里的,要让控件不透明或透明,,其方法就是让控件是否透明。
用SetLayeredWindowAttributes是让窗体内所有的控件都透明,然后你又想让个别控件不透明,其思路就存在问题了。
那应该怎么做呢?
只有让控件作为窗体来使用了。。什么意思?你可以自己写控件(只有自己写的控件才好操作),然后在代码里加上相应的透明代码,这样你触发控件事件时将会触发透明代码。控件就会如你要求的透明或不透明。。。
还有,楼主的透明代码麻烦了。。。
我有个精炼的:
Const LWA_COLORKEY = &H1
Const LWA_ALPHA = &H2
Const GWL_EXSTYLE = (-20)
Const WS_EX_LAYERED = &H80000
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 SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Sub Form_Load()
Dim Ret As Long
Ret = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
Ret = Ret Or WS_EX_LAYERED
SetWindowLong Me.hWnd, GWL_EXSTYLE, Ret
'将窗体的透明度设成128(0-255)
SetLayeredWindowAttributes Me.hWnd, 0, 128, LWA_ALPHA
End Sub
科技程序迷
2010-07-25 · TA获得超过2822个赞
知道大有可为答主
回答量:2240
采纳率:0%
帮助的人:1851万
展开全部
在图片框的鼠标移动事件让图片框刷新也许可以
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
远风的梦想家
2010-07-25 · TA获得超过2550个赞
知道大有可为答主
回答量:1389
采纳率:0%
帮助的人:0
展开全部
查了一下MSDN,没有办法设置一个窗口处于半透明状态下,使其中的picturebox或者image为不透明,建议换一个方法,做两个窗体来实现这个问题。API中没有任何参数能做到你要求的那样
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
邪恶圣使
2012-09-02 · TA获得超过235个赞
知道小有建树答主
回答量:682
采纳率:32%
帮助的人:104万
展开全部
双窗体
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 3条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式