VB3 Killing an Application with System Menu Using VBID: Q80186
|
Visual Basic for Windows can use the Windows API SendMessage function to
close any active window that has a system menu (referred to as control box
within Visual Basic for Windows) with the Close option.
You can use the Windows API SendMessage function to post a message to any
window in the environment as long as the handle to the window is known. You
can use the API FindWindow function to determine the handle associated with
the window the user wants to close.
Query on the following words in the Microsoft Knowledge Base for more
information on the FindWindow function:
FindWindow and Visual Basic
Sub Command1_Click()
X% = Shell("Calc.exe")
End Sub
Sub Command2_Click()
Const NILL = 0&
Const WM_SYSCOMMAND = &H112
Const SC_CLOSE = &HF060
lpClassName$ = "SciCalc"
lpCaption$ = "Calculator"
'* Determine the handle to the Calculator window.
Handle = FindWindow(lpClassName$, lpCaption$)
'* Post a message to Calc to end it's existence.
X& = SendMessage(Handle, WM_SYSCOMMAND, SC_CLOSE, NILL)
End Sub
' Enter each of the following Declare statements on one, single line:
Declare Function FindWindow% Lib "user" (ByVal lpClassName As Any,
ByVal lpCaption As Any)
Declare Function SendMessage& Lib "user" (ByVal hwnd%, ByVal wMsg%,
ByVal wParam%, ByVal lParam As Long)
Additional query words: 2.00 3.00
Keywords : kbcode
Version : 1.00 2.00 3.00
Platform : WINDOWS
Issue type :
Last Reviewed: June 18, 1999