Results 1 to 5 of 5

Thread: Hide/Show all IE windows (RESOLVED)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    Resolved Hide/Show all IE windows (RESOLVED)

    Hey All,

    I found the following code in the forums to hide/show the active IE window...

    VB Code:
    1. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    2. Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    3.  
    4. Private Sub Command1_Click()
    5.     Dim hApp As Long
    6.     hApp = FindWindowEx(0, 0, "IEFrame", vbNullString)
    7.     ShowWindow hApp, 0 'change 0 to 1 to show it again
    8. End Sub
    9.  
    10. Private Sub Command2_Click()
    11.     Dim hApp As Long
    12.     hApp = FindWindowEx(0, 0, "IEFrame", vbNullString)
    13.     ShowWindow hApp, 1 'change 0 to 1 to show it again
    14. End Sub

    Can someone please show me how to put this in a loop to hide/show all open
    IE windows?

    Any help would be appreciated.

    Thanks,
    Ron
    Last edited by rdcody; May 29th, 2005 at 05:19 PM.

  2. #2
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Hide/Show all IE windows

    Try this: (i put this in a module but it will work if its not )

    VB Code:
    1. Option Explicit
    2.  
    3. Private g_TheCollWin As Collection
    4.  
    5. Private Declare Function EnumWindows Lib "user32.dll" ( _
    6.     ByVal lpEnumFunc As Long, _
    7.     ByVal lParam As Long) As Boolean
    8. Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" ( _
    9.     ByVal hWnd As Long, _
    10.     ByVal lpString As String, _
    11.     ByVal cch As Long) As Long
    12. Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" ( _
    13.     ByVal hWnd As Long) As Long
    14. Private Declare Function ShowWindow Lib "user32.dll" ( _
    15.     ByVal hWnd As Long, _
    16.     ByVal nCmdShow As Long) As Long
    17. Private Declare Function SetForegroundWindow Lib "user32.dll" ( _
    18.     ByVal hWnd As Long) As Long
    19.  
    20. Private Sub Hide_Window(ByVal strWindowTitle As String)
    21.     Set g_TheCollWin = New Collection
    22.     g_TheCollWin.Add strWindowTitle
    23.     Call EnumWindows(AddressOf EnumWindowsProc, ByVal 0&)
    24. End Sub
    25.  
    26. Public Function EnumWindowsProc(ByVal lngHwnd As Long, ByVal lngParam As Long) As Boolean
    27.     Dim strSave As String
    28.     Dim lngRet As Long
    29.     Dim varTheItem As Variant
    30.     lngRet = GetWindowTextLength(lngHwnd)
    31.     If lngRet > 0 Then
    32.         strSave = Space$(lngRet)
    33.         Call GetWindowText(lngHwnd, strSave, lngRet + 1)
    34.         For Each varTheItem In g_TheCollWin
    35.             If InStr(1, strSave, varTheItem, vbTextCompare) > 0 Then
    36.                 Call SetForegroundWindow(lngHwnd)
    37.                 Call ShowWindow(lngHwnd, 0)
    38.             End If
    39.         Next
    40.     End If
    41.     EnumWindowsProc = True
    42. End Function

    For its call:

    VB Code:
    1. Hide_Window("Microsoft Internet Explorer")

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    Re: Hide/Show all IE windows

    Hey thanks RyanJ...it seems to work just fine.

  4. #4
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Hide/Show all IE windows

    Quote Originally Posted by rdcody
    Hey thanks RyanJ...it seems to work just fine.

    Great, glad to help

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  5. #5
    Hyperactive Member Dmitri K's Avatar
    Join Date
    Sep 2002
    Location
    West Palm Beach, FL
    Posts
    444

    Re: Hide/Show all IE windows (RESOLVED)

    There is another way without subclassing.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Const GW_HWNDNEXT = 2
    4. Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
    5. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    6. Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    7. Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    8.  
    9. Private Sub Command1_Click()
    10. Dim ret As Long, hwnd As Long
    11. Dim title As String
    12. Dim sSave As String
    13.  
    14. title = "Untitled - Notepad"
    15. sSave = title
    16. hwnd = FindWindow(vbNullString, title)
    17. Do Until hwnd = 0
    18.   If sSave = title Then Debug.Print hwnd & " " & sSave
    19.   hwnd = GetWindow(hwnd, GW_HWNDNEXT)
    20.   If hwnd Then
    21.     ret = GetWindowTextLength(hwnd)
    22.     sSave = Space(ret)
    23.     GetWindowText hwnd, sSave, ret + 1
    24.   End If
    25. Loop
    26.  
    27. End Sub

    You get the general idea, if you need to compare classes, use getclasname API (I think)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width