How to Cascade Internet Explorer windows on the desktop
Posted on December 4, 2011
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | 'System & API - How to Cascade Internet Explorer windows on the desktop 'In a form Option Explicit Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, _ ByVal lparam As Long) As Long Private Sub cmdCascadeIE_Click() EnumWindows AddressOf WindowEnumerator, 0 End Sub 'In a module: Option Explicit Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _ (ByVal hwnd As Long, ByVal lpString As String, ByVal cch 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 Public Const DX = 20 Public Const DY = 20 Public m_MinX As Long Public m_MinY As Long ' Return False to stop the enumeration. Public Function WindowEnumerator(ByVal app_hwnd As Long, ByVal lparam As Long) As Long Const SWP_NOACTIVATE = &H10 Const SWP_NOZORDER = &H4 Dim targets() As Variant Dim widths() As Variant Dim heights() As Variant Dim buf As String * 256 Dim title As String Dim length As Long Dim i As Integer targets = Array(" - Microsoft Internet Explorer", " - Outlook Express") widths = Array(800, 800) heights = Array(500, 550) If m_MinY = 0 Then m_MinY = Form1.ScaleY(Screen.Height, vbTwips, vbPixels) - 100 - _ heights(LBound(heights)) - 5 * DX m_MinX = 5 * DX End If ' Get the window's title. length = GetWindowText(app_hwnd, buf, Len(buf)) title = Left$(buf, length) ' See if the title contains the target. For i = LBound(targets) To UBound(targets) If InStr(title, targets(i)) > 0 Then SetWindowPos app_hwnd, 0, m_MinX, m_MinY, widths(i), heights(i), _ SWP_NOACTIVATE Or SWP_NOZORDER m_MinX = m_MinX - DX m_MinY = m_MinY + DX Exit For End If Next i WindowEnumerator = True End Function |