VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > vb >
  • vb教程之打开和关闭其他应用

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

相关教程