vb窗体的淡出淡入时,让窗体不要总是在最前
下面是淡出淡入的例子,但是运行后,窗体总是在最前,我想让它不要总是保持最前的状态,该如何做呢?
Option Explicit
'SetMouseIn 窗体的句柄,透明度(可选),是否置顶(可选),是否鼠标穿透(可选)
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 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 SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const HWND_TOPMOST = -1
Private Function SetMouseIn(ByVal hwnd As Long, Optional TouMing As Long = 200, Optional Top As Boolean = True, Optional cMouse As Boolean = True) As Long
Dim Ret As Long
Ret = GetWindowLong(hwnd, GWL_EXSTYLE)
Ret = Ret Or WS_EX_LAYERED
If cMouse Then Ret = Ret Or WS_EX_TRANSPARENT
SetWindowLong hwnd, GWL_EXSTYLE, Ret
SetLayeredWindowAttributes hwnd, 0, TouMing, LWA_ALPHA
If Top Then SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End Function
Private Sub Form_Load()
Timer1.Interval = 20
Timer2.Interval = 20
Timer2.Enabled = False
SetMouseIn Me.hwnd, 1, True, False
End Sub
Private Sub Form_Unload(Cancel As Integer)
Timer2.Enabled = True
Cancel = 1
End Sub
Private Sub Timer1_Timer()
Static i As Long
If i > = 250 Then Timer1.Enabled = False
i = i + 5
SetMouseIn Me.hwnd, i, True, False
End Sub
Private Sub Timer2_Timer()
Static i As Long
If i > = 250 Then End
i = i + 5
SetMouseIn Me.hwnd, 255 - i, True, False ' <----------加了个255-i
End Sub
[解决办法]
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
这一句就是将窗体置为最顶层了,把它去掉就会不了