|
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.
|
|
|
|