'类似QQ的自动隐藏窗体 'By:griefforyou Option Explicit
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) 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 HWND_TOPMOST = -1 Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2 Private Const SWP_NOSIZE = &H1 Private Const SWP_SHOWWINDOW = &H40
Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type
Private Type POINTAPI x As Long y As Long End Type
Dim HideFlag As Boolean Dim WindowRect As RECT Dim MousePos As POINTAPI
Private Sub Check1_Click() If Check1.Value = 1 Then SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Else SetWindowPos Me.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE End If End Sub
Private Sub Check2_Click() Timer1.Enabled = Check2.Value End Sub
Private Sub Form_load() Check1.Value = 1 Check2.Value = 1 Timer1.Interval = 500 HideFlag = True Me.Top = -Me.Height + 30 End Sub
Private Sub Timer1_Timer() If Me.WindowState > 0 Then Exit Sub GetWindowRect Me.hwnd, WindowRect GetCursorPos MousePos If MousePos.x >= WindowRect.Left And MousePos.x <= WindowRect.Right And _ MousePos.y >= WindowRect.Top And MousePos.y <= WindowRect.Bottom Then If HideFlag = True Then Me.Top = -15 HideFlag = False End If Else If WindowRect.Top < 5 Then Debug.Print WindowRect.Top Me.Top = -Me.Height + 15 HideFlag = True End If End If End Sub