Results 1 to 1 of 1

Thread: VB 5,6 - Close window when you know its title - API

  1. #1

    Thread Starter
    Lively Member vb_paladin's Avatar
    Join Date
    May 2003
    Location
    USA
    Posts
    102

    VB 5,6 - Close window when you know its title - API

    This is not my code, I found it on PSC and it was very useful to me.
    VB Code:
    1. '**************************************
    2. ' Name: Close a window
    3. ' Description:Close a window when you know the title of
    4. ' this window.
    5. ' Uses the API FindWindow and PostMessage.
    6. ' By: Marcus Schmitt
    7. '
    8. ' This code is copyrighted and has
    9. ' limited warranties.  Please see [url]http://www.Planet-Sourcecode.com/vb/scripts/Sho
    10. ' wCode.asp?txtCodeId=35934&lngWId=1[/url]
    11. 'for details.'**************************************
    12.  
    13. Option Explicit
    14.  
    15.  
    16. Private Declare Function PostMessage Lib "user32" _
    17.     Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    18.  
    19.  
    20. Private Declare Function FindWindow Lib "user32" _
    21.     Alias "FindWindowA" (ByVal szClass$, ByVal szTitle$) As Long
    22.     Private Const WM_CLOSE = &H10
    23.  
    24.  
    25. Private Sub Command1_Click()
    26.     Dim hWnd, retval As Long
    27.     Dim WinTitle As String
    28.     WinTitle = "Recycle Bin" '<- Title of Window
    29.     hWnd = FindWindow(vbNullString, WinTitle)
    30.     retval = PostMessage(hWnd, WM_CLOSE, 0&, 0&)
    31. End Sub
    Last edited by vb_paladin; Jul 19th, 2003 at 07:08 PM.

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