- 注册时间
- 2011-3-6
- 最后登录
- 1970-1-1
该用户从未签到
|
发表于 2014-7-10 08:41:06
|
显示全部楼层
这种东西我只给思路,既然你已经设计到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 |
|