Private Sub Command1_Click()
EnumWindows AddressOf EnumWindowsProc, 0 '枚举窗口
End Sub
'以下代码为添加至模块的代码
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Public Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As Long
Public Declare Function SetWindowPos Lib "user32.dll" (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 Const WM_GETTEXT As Long = &HD
Public Const HWND_TOP As Long = 0
Public Const SWP_SHOWWINDOW As Long = &H40
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long '枚举窗口的回调函数
Dim byteBuf(1 To 1024) As Byte
Dim strTxt1 As String
SendMessage hwnd, WM_GETTEXT, 1024, byteBuf(1)
strTxt1 = StrConv(byteBuf, vbUnicode)
strTxt1 = Left(strTxt1, InStr(strTxt1, Chr(0)) - 1)
Dim r As RECT
GetWindowRect hwnd, r
If 0 = StrComp(strTxt1, "文件A.TXT - 记事本", vbTextCompare) Then
SetWindowPos hwnd, HWND_TOP, 0, 0, r.Right - r.Left, r.Bottom - r.Top, SWP_SHOWWINDOW
End If
If 0 = StrComp(strTxt1, "文件b.txt - 记事本", vbTextCompare) Then
SetWindowPos hwnd, HWND_TOP, 0, 100, r.Right - r.Left, r.Bottom - r.Top, SWP_SHOWWINDOW
End If
EnumWindowsProc = -1
End Function


