Help VB Get window by title and close it 
Author Message
 Help VB Get window by title and close it

Im looking for some help in finding the right code to find a window by
its title (This will be known) and closing the window.

Im a relative newbie to VB so code examples would be appreciated.

Thanx



Tue, 03 May 2005 18:23:31 GMT  
 Help VB Get window by title and close it
Karl-

Open notepad without changing anything. Open a new VB project, add a command
button and copy in the following:

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
Private Const WM_CLOSE = &H10

Private Sub Command1_Click()

Dim lNotepadHwnd As Long

lNotepadHwnd = FindWindow(vbNullString, "Untitled - Notepad")
PostMessage lNotepadHwnd, WM_CLOSE, 0&, 0&

End Sub

Clicking the button will close Notepad.

The other API's you'll want to check out are FindWindowEx, Sendmessage and
EnumChildWindows

HTH

Matt


Quote:
> Im looking for some help in finding the right code to find a window by
> its title (This will be known) and closing the window.

> Im a relative newbie to VB so code examples would be appreciated.

> Thanx



Tue, 03 May 2005 21:49:37 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Getting title of current window

2. VB closing app vs. Windows closing app

3. How to close VB 4.0 16 bit program when a Crystal report Window is closed

4. closing the Yes/No window when closing a Shelled Window

5. Problems Closing a New Window using window.close()

6. getting a parent window to close

7. How to detect WebBrowser window getting closed

8. Closing Parent Window when the child window closes

9. Access Windows Title bar....Please Help

10. How to access Windows Title Bar??..Help!

11. VB3 Help: How to find Window Title Name?

12. Help : Need to create a window without a Title Bar

 

 
Powered by phpBB® Forum Software