Results 1 to 7 of 7

Thread: pstmessage and IE??

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    4

    Exclamation

    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

  2. #2
    Guest
    May I see the code you are using?

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    4
    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


  4. #4
    Guest
    Try this:

    Code:
    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

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    4
    thanks!! but it happens the same

  6. #6
    Guest
    Are you wanting to close all IE windows?
    I found this code from this thread. He says that is closes all IE Windows. Which is what you want to do, correct?

    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 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

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    4
    it works!!!, thank you very much

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