Results 1 to 4 of 4

Thread: Closing Window By Handle?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    I know its easy,

    How do you close a window by its
    handle?

  2. #2
    Guest
    This will close the Calculator.

    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()
    
        'Find the hWnd of the Calculator
        hParent = FindWindow("SciCalc", "Calculator")
                 'FindWindow(Class, Caption)
        'If found then...
        If hParent <> 0 Then 'close it
            PostMessage hParent, WM_CLOSE, 0, 0
            PostMessage hParent, WM_DESTROY, 0, 0
        End If
        'Closed
    End Sub

  3. #3
    Addicted Member morphman2000's Avatar
    Join Date
    Oct 2000
    Location
    Europe, The Netherlands
    Posts
    254

    Red face SIMPLE!

    Private Sub Command1_Click()
    Unload Me
    End Sub

    That's all

    bye

    dennie

  4. #4
    Guest

    Re: SIMPLE!

    Originally posted by morphman2000
    Private Sub Command1_Click()
    Unload Me
    End Sub

    That's all

    bye

    dennie

    This will only close your own program, not any other applications.

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