Hi,
I've found the following code to cycle through all the open windows and retrieve the class name for each window, I want to find all Internet Explorer windows (they have a class name of "IEFrame"
and close them (it's the basis for a popup-defender I'm writing).
I can't figure out why if I pass the title for an IE window to FindWindow it returns a different handle to when I use GetWindow. I don't want to use FindWindow because if I have 3 IE windows open all at the same page it won't differentiate between them.
Can I use GetWindow to return the handle that I'm after?
lngDeskTopHandle = GetDesktopWindow()
lngHand = GetWindow(lngDeskTopHandle, GW_CHILD)
'Loop while there are still open windows.
Do While lngHand <> 0
GetWindowText lngHand, strName, Len(strName)
lngHand = GetWindow(lngHand, GW_HWNDNEXT)
If (Left$(strName, 1) <> vbNullChar) Then
' Is it an Internet Explorer window?
GetClassName lngHand, strName, Len(strName)
If (Left$(strName, 1) <> vbNullChar) Then
If (Left$(strName, InStr(strName, vbNullChar) - 1) = "IEFrame"
Then
' Never gets to this line!!!!! Why???
lngRtn = GetWindowThreadProcessId(lngHand, lngProcID)
lngProc = OpenProcess(PROCESS_ALL_ACCESS, CLng(0), lngProcID)
lngRtn = TerminateProcess(lngProc, CLng(0))
End If
End If
End If
Loop
- Andy
_______________________________
"On a clear disk you can seek forever"
I've found the following code to cycle through all the open windows and retrieve the class name for each window, I want to find all Internet Explorer windows (they have a class name of "IEFrame"
I can't figure out why if I pass the title for an IE window to FindWindow it returns a different handle to when I use GetWindow. I don't want to use FindWindow because if I have 3 IE windows open all at the same page it won't differentiate between them.
Can I use GetWindow to return the handle that I'm after?
lngDeskTopHandle = GetDesktopWindow()
lngHand = GetWindow(lngDeskTopHandle, GW_CHILD)
'Loop while there are still open windows.
Do While lngHand <> 0
GetWindowText lngHand, strName, Len(strName)
lngHand = GetWindow(lngHand, GW_HWNDNEXT)
If (Left$(strName, 1) <> vbNullChar) Then
' Is it an Internet Explorer window?
GetClassName lngHand, strName, Len(strName)
If (Left$(strName, 1) <> vbNullChar) Then
If (Left$(strName, InStr(strName, vbNullChar) - 1) = "IEFrame"
' Never gets to this line!!!!! Why???
lngRtn = GetWindowThreadProcessId(lngHand, lngProcID)
lngProc = OpenProcess(PROCESS_ALL_ACCESS, CLng(0), lngProcID)
lngRtn = TerminateProcess(lngProc, CLng(0))
End If
End If
End If
Loop
- Andy
_______________________________
"On a clear disk you can seek forever"