|
发表于 2020-8-15 11:00:01
|
显示全部楼层
Attribute VB_Name = "ModOnTop"
'*************************************************************************
'**模 块 名:ModOnTop
'**说 明:将窗体放到Z轴最上层,设置窗体透明度,鼠标是否能穿透
'**创 建 人:马大哈
'**日 期:2003年12月17日
'**修 改 人:
'**日 期:2006年11月8日
'**描 述:http://www.m5home.com
'**版 本:V1.4
'*************************************************************************
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 Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long,
ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const LWA_ALPHA = &H2
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Private Const WS_EX_TRANSPARENT As Long = &H20&
Private Const SWP_NOSIZE& = &H1
Private Const SWP_NOMOVE& = &H2
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const HWND_BROADCAST = &HFFFF&
Private Const HWND_TOP = 0
Public Sub OnTop(ByVal tForm As Form, Optional ByVal Top As Boolean = True, Optional TouMing As Long = 255, Optional cMouse As Boolean = False)
'*************************************************************************
'**参 数 名:Top
'**说 明:是否将窗体放到Z轴最上层
'**参 数 名:TouMing
'**说 明:窗体透明度(WIN2000及以上有效)
'**参 数 名:cMouse
'**说 明:鼠标是否能穿透
'*************************************************************************
Dim Ret As Long
Ret = GetWindowLong(tForm.hwnd, GWL_EXSTYLE)
Ret = Ret Or WS_EX_LAYERED
If cMouse Then Ret = Ret Or WS_EX_TRANSPARENT
SetWindowLong tForm.hwnd, GWL_EXSTYLE, Ret
If TouMing < 0 Then TouMing = 0
If TouMing > 255 Then TouMing = 255
SetLayeredWindowAttributes tForm.hwnd, 0, TouMing, LWA_ALPHA
If Top = True Then
SetWindowPos tForm.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
Else
SetWindowPos tForm.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End If
End Sub
*************************************************
这个只能让程序实现半透明,鼠标穿透,不响应WIN+D
但无法实现播放视频也半透明.一旦有半透明效果,视频就无法显示了....... |
|