Private Declare Function GetForegroundWindow Lib "user32" () 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 Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Const SWP_NOSIZE = &H1 Private Const HWND_TOPMOST = -1 Private Sub Command1_Click() Timer1.Enabled = False End Sub Private Sub Form_Load() Me.Hide App.TaskVisible = False End Sub Private Sub Timer1_Timer() Dim atWindow As Long Dim myRECT As RECT atWindow = GetForegroundWindow GetWindowRect atWindow, myRECT Randomize WhereGo = Fix(Rnd * 4) Select Case WhereGo Case 0 SetWindowPos atWindow, 0, myRECT.Left + myRnd(), myRECT.Top, 0, 0, SWP_NOSIZE Case 1 SetWindowPos atWindow, 0, myRECT.Left - myRnd(), myRECT.Top, 0, 0, SWP_NOSIZE Case 2 SetWindowPos atWindow, 0, myRECT.Left, myRECT.Top + myRnd(), 0, 0, SWP_NOSIZE Case 3 SetWindowPos atWindow, 0, myRECT.Left, myRECT.Top - myRnd(), 0, 0, SWP_NOSIZE End Select End Sub Private Function myRnd() As Integer Randomize myRnd = Fix(Rnd * 12) End Function |
恶作剧程序:无限窗口抖动(VB源码,纯API练习)
最新推荐文章于 2020-11-26 09:09:38 发布