Results 1 to 4 of 4

Thread: If window open then close it

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287
    Hi,

    Does anybody know how I can detect if there is a window open with the name “window” and then close that window if it is open? I’m quite sure this can be done with the windows APIs but I don’t have a clue how? Thanks
    rino_2
    Visual Basic, HTML
    Please Visit my Site: Richard's VB Site

  2. #2
    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 SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Const WM_CLOSE = &H10
    Const WM_DESTROY = &H2
    
    Private Sub Command1_Click()
    
        'Get the hWnd of the Window named Calculator
        MyHwnd = FindWindow(vbNullString, "Calculator")
        'If it's found then close it
        If MyHwnd <> 0 Then
            SendMessage MyHwnd, WM_CLOSE, 0&, 0&
            SendMessage MyHwnd, WM_DESTROY, 0&, 0&
        End If
    
    End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Thumbs up Thanks!

    Thanks for the help Megatron!
    rino_2
    Visual Basic, HTML
    Please Visit my Site: Richard's VB Site

  4. #4
    Guest
    Code:
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Const WM_CLOSE = &H10
    Const WM_DESTROY = &H2
    
    Private Sub Command1_Click()
    
        'Get the hWnd of the Window named Calculator
        MyHwnd = FindWindow(vbNullString, "Calculator")
        'If it's found then close it
        If MyHwnd <> 0 Then
            SendMessage MyHwnd, WM_CLOSE, 0&, 0&
            SendMessage MyHwnd, WM_DESTROY, 0&, 0&
        End If
    
    End Sub

    a few days ago I tried this with IE,
    I used the class IEFrame, and all it did was disable IE, and it wouldnt allow me to close it normally i had to end-task it.

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