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:
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
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Sub Command1_Click()
Dim hApp As Long
hApp = FindWindowEx(0, 0, "IEFrame", vbNullString)
ShowWindow hApp, 0 'change 0 to 1 to show it again
End Sub
Private Sub Command2_Click()
Dim hApp As Long
hApp = FindWindowEx(0, 0, "IEFrame", vbNullString)
ShowWindow hApp, 1 'change 0 to 1 to show it again
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
Re: Hide/Show all IE windows
Try this: (i put this in a module but it will work if its not :))
VB Code:
Option Explicit
Private g_TheCollWin As Collection
Private Declare Function EnumWindows Lib "user32.dll" ( _
ByVal lpEnumFunc As Long, _
ByVal lParam As Long) As Boolean
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" ( _
ByVal hWnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" ( _
ByVal hWnd As Long) As Long
Private Declare Function ShowWindow Lib "user32.dll" ( _
ByVal hWnd As Long, _
ByVal nCmdShow As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32.dll" ( _
ByVal hWnd As Long) As Long
Private Sub Hide_Window(ByVal strWindowTitle As String)
Set g_TheCollWin = New Collection
g_TheCollWin.Add strWindowTitle
Call EnumWindows(AddressOf EnumWindowsProc, ByVal 0&)
End Sub
Public Function EnumWindowsProc(ByVal lngHwnd As Long, ByVal lngParam As Long) As Boolean
Dim strSave As String
Dim lngRet As Long
Dim varTheItem As Variant
lngRet = GetWindowTextLength(lngHwnd)
If lngRet > 0 Then
strSave = Space$(lngRet)
Call GetWindowText(lngHwnd, strSave, lngRet + 1)
For Each varTheItem In g_TheCollWin
If InStr(1, strSave, varTheItem, vbTextCompare) > 0 Then
Call SetForegroundWindow(lngHwnd)
Call ShowWindow(lngHwnd, 0)
End If
Next
End If
EnumWindowsProc = True
End Function
For its call:
VB Code:
Hide_Window("Microsoft Internet Explorer")
Cheers,
RyanJ
Re: Hide/Show all IE windows
Hey thanks RyanJ...it seems to work just fine. :)
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
Re: Hide/Show all IE windows (RESOLVED)
There is another way without subclassing.
VB Code:
Option Explicit
Private Const GW_HWNDNEXT = 2
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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 GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Sub Command1_Click()
Dim ret As Long, hwnd As Long
Dim title As String
Dim sSave As String
title = "Untitled - Notepad"
sSave = title
hwnd = FindWindow(vbNullString, title)
Do Until hwnd = 0
If sSave = title Then Debug.Print hwnd & " " & sSave
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
If hwnd Then
ret = GetWindowTextLength(hwnd)
sSave = Space(ret)
GetWindowText hwnd, sSave, ret + 1
End If
Loop
End Sub
You get the general idea, if you need to compare classes, use getclasname API (I think)