打开和关闭其他应用

发表于:2007-07-14来源:作者:点击数: 标签:
Declare Function FindWindow Lib user32 Alias FindWindowA (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Declare Function SendMessage Lib user32 Alias SendMessageA (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam A
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
打开应用:
Private Sub Command1_Click()
Shell "Calc.exe", vbNormalFocus
End Sub
关闭应用:
Private Sub Command2_Click()
Dim lpClassName As String
Dim lpCaption As String
Dim Handle As Long

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 its existence.
Handle = SendMessage(Handle, WM_SYSCOMMAND, SC_CLOSE, NILL)
End Sub

原文转自:http://www.ltesting.net