AllAPI Network - The KPD-Team

 
Allapi Network
 API-Guide
 ApiViewer

 API List

 
API Resources
 Tips & Tricks
 VB Tutorials
 Error Lookup
 
Misc Stuff
 VB examples
 VB Tools
 VB Links
 Top Downloads
 
This Site
 Search Engine
 Contact Form
 

Donate to AllAPI.net

How can I emulate the user pressing the [x] button?

To emulate the user pressing the [x], you need to send a WM_CLOSE message to the target window.

' API Declaration
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
public Const WM_CLOSE = &H10

' API Use....
public Sub CloseAppByHwnd(byval hWnd as Long)

Dim lRet as Long

lRet = PostMessage(hwnd,WM_CLOSE, 0&, 0&)

End Sub

Of course, you may not know the hwnd of the application you're trying to close. No problem, simply use FindWindow:

' API Declaration
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (byval lpClassName as string, byval lpWindowName as string) as Long
' API Use

Dim hwndTarget as Long

hWndTarget = FindWindow(vbNullString,"Microsoft Outlook")

Tip by Duncan Jones.

 

 


Copyright © 1998-2007, The Mentalis.org Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at http://allapi.mentalis.org/