Public 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
Public Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function IsWindowVisible Lib "user32" (ByVal hWnd As Long) As Long
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Const SWP_NOSIZE = &H1
Public Const HWND_BOTTOM = 1
Public Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Boolean
If hWnd = 0 Then
EnumWindowsProc = False
Else
If IsWindowVisible(hWnd) Then
Dim tRect As RECT
Call GetWindowRect(hWnd, tRect)
Dim T, L
T = MyRnd(-20, 20)
L = MyRnd(-20, 20)
Call SetWindowPos(hWnd, HWND_BOTTOM, tRect.Left + L, tRect.Top + T, 0, 0, SWP_NOSIZE)
End If
EnumWindowsProc = True
End If
End Function
Public Function MyRnd(ByVal Upper As Long, ByVal Lower As Long) As Long
MyRnd = Int((Upper - Lower + 1) * Rnd() + Lower)
End Function
Public Sub MyEnum()
EnumWindows AddressOf EnumWindowsProc, 0&
End Sub
WIN7下建议别运行。。。窗口太多了。。。我枚举了一下,发现有三百多个。。。呃。。。也可能是我开的程序多吧。。。反正最好XP下搞,要不然卡死我不管。。。如果WIN7下要搞的话建议还是GetTopWindow...