Click to See Complete Forum and Search --> : pstmessage and IE??
jmundi64
Nov 19th, 2000, 09:42 AM
Hi, I am using postmessage to close windows, and it is working correctly except when I try to close Internet Explorer, I heard a beep and the window doesn´t close. Anybody can help me?
thanks
May I see the code you are using?
jmundi64
Nov 19th, 2000, 05:44 PM
this is the code......
Private Sub cerrar()
Dim winHwnd As Long
Dim retval As Long
Dim wndName As String
Dim intArchivo
Dim strRuta
Dim ventana
' carga del fichero de configuracion
intArchivo = FreeFile
strRuta = "c:\parche\close.dat"
Open strRuta For Input As intArchivo
Do While Not EOF(intArchivo)
Input #intArchivo, ventana
wndName = ventana
winHwnd = FindWindow(vbNullString, wndName)
Debug.Print winHwnd
If winHwnd <> 0 Then
retval = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
End If
Loop
Close intArchivo
End Sub
Try this:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const WM_CLOSE = &H10
Const WM_DESTROY = &H2
Private Sub Command1_Click()
hWin = FindWindow("IEFrame", vbNullString)
If hWin <> 0 Then
PostMessage hWin, WM_CLOSE, 0, 0
PostMessage hWin, WM_DESTROY, 0, 0
End If
End Sub
jmundi64
Nov 20th, 2000, 07:58 AM
thanks!! but it happens the same
Are you wanting to close all IE windows?
I found this code from this thread (http://forums.vb-world.net/showthread.php?threadid=18454). He says that is closes all IE Windows. Which is what you want to do, correct?
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 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 Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal _
dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function GetWindowThreadProcessId _
Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As _
Long
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" _
(ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Sub Timer1_Timer()
Dim lngIE As Long
Dim strBuffer As String
Dim lngLength As Long
Dim intCount As Integer
Dim lHwnd As Long
Dim lProcess As Long
Dim lExitCode As Long
Dim p As Integer
Do
lngIE = FindWindowEx(0, lngIE, "IEFrame", vbNullString)
lngLength = GetWindowTextLength(lngIE)
strBuffer = Space(lngLength)
Call GetWindowText(lngIE, strBuffer, Len(strBuffer))
If Len(Trim(strBuffer)) > 0 Then
intCount = intCount + 1
End If
Loop Until lngIE = 0
If intCount > 1 Then
For p = 1 To (intCount - 1)
'Get the Window Handle
lHwnd = FindWindow("IEFrame", vbNullString)
'Get the ProcessID
Call GetWindowThreadProcessId(lHwnd, lProcess)
'Get the Process Handle
lProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, lProcess)
'Get the Exitcode
Call GetExitCodeProcess(lProcess, lExitCode)
'Terminate the Process
Call TerminateProcess(lProcess, lExitCode)
Next p
End If
End Sub
jmundi64
Nov 22nd, 2000, 02:41 AM
it works!!!, thank you very much
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.