首先,在Module中先声明API函数.
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_CLOSE = &H10
Public Const WM_QUIT = &H12
在vb form调用:
启动:
ShellExecute 112, "open", App.Path & "\TxtToSql.exe", "", "", 0
关闭:
Handle = FindWindow(vbNullString, "TxtToSql") 'TxtToSql是exe的标题(TITLE OR CAPITION)
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_CLOSE = &H10
Public Const WM_QUIT = &H12
在vb form调用:
启动:
ShellExecute 112, "open", App.Path & "\TxtToSql.exe", "", "", 0
关闭:
Handle = FindWindow(vbNullString, "TxtToSql") 'TxtToSql是exe的标题(TITLE OR CAPITION)
PostMessage Handle, WM_QUIT, 0&, 0&
本文转自kenty博客园博客,原文链接http://www.cnblogs.com/kentyshang/archive/2006/07/01/440530.html如需转载请自行联系原作者
kenty