可以让你运行WINDOW程序,并等待结束继续运行脚本
2011-06-15 09:48
357 查看
The following routine will allow you to call another program from LotusScript, wait for that program to finish and continue running your script.
The Yield example in Designer help uses an obsolete API call. To illustrate this routine, create a new form and add a hotspot button. Add the code below to your button.
Code
/"Put this code in the declarations section
Declare Function GetActiveWindow Lib /"user32.dll/" () As Long
Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type
Const SEE_MASK_NOCLOSEPROCESS = &H40
Const SW_SHOWNORMAL = 1
Declare Function ShellExecuteEx Lib /"shell32.dll/" Alias /"ShellExecuteExA/"
(lpExecInfo As SHELLEXECUTEINFO) As Long
Const SE_ERR_FNF = 2
Declare Function WaitForSingleObject Lib /"kernel32.dll/" (Byval hHandle As Long, Byval dwMilliseconds As Long) As Long
Const INFINITE = &HFFFF
Const WAIT_TIMEOUT = &H102
/'***************************************************************************
Sub Click(Source As Button)
Dim haWnd As Long /' handle to the active window
haWnd = GetActiveWindow()
Dim sei As SHELLEXECUTEINFO /' structure used by the function
Dim retval As Long /' return value
/' Load the information needed to open C:WindowsCalc.exe into the structure.
/' Size of the structure
sei.cbSize = Len(sei)
/' Use the optional hProcess element of the structure.
sei.fMask = SEE_MASK_NOCLOSEPROCESS
/' Handle to the window calling this function.
sei.hwnd = haaaWnd
/' The action to perform: open the file.
sei.lpVerb = /"open/"
/' The file to open.
sei.lpFile = /"C:windowscalc.exe/"
/' No additional parameters are needed here.
sei.lpParameters = /"/"
/' The default directory -- not really necessary in this case.
sei.lpDirectory = /"C:windows/"
/' Simply display the window.
sei.nShow = SW_SHOWNORMAL
/' The other elements of the structure are either not used or will be set when the function returns.
retval = ShellExecuteEx(sei)
If retval = 0 Then
/' The function failed, so report the error. Err.LastDllError could also be used instead, if you wish.
Select Case sei.hInstApp
Case SE_ERR_FNF
Msgbox /"The application C:WindowsCalc.exe./"
Case Else
Msgbox /"An unexpected error occured./"
End Select
Else
/' Wait for the opened process to close before continuing. Instead of waiting once for a time of INFINITE, this example repeatedly checks to see if the is still open. This allows the DoEvents function to be called, preventing our script from appearing to lock up while it waits.
Do
Doevents
retval = WaitForSingleObject(sei.hProcess, 0)
Loop While retval = WAIT_TIMEOUT
Msgbox /"Calculator has just closed./"
End If
End Sub
The Yield example in Designer help uses an obsolete API call. To illustrate this routine, create a new form and add a hotspot button. Add the code below to your button.
Code
/"Put this code in the declarations section
Declare Function GetActiveWindow Lib /"user32.dll/" () As Long
Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type
Const SEE_MASK_NOCLOSEPROCESS = &H40
Const SW_SHOWNORMAL = 1
Declare Function ShellExecuteEx Lib /"shell32.dll/" Alias /"ShellExecuteExA/"
(lpExecInfo As SHELLEXECUTEINFO) As Long
Const SE_ERR_FNF = 2
Declare Function WaitForSingleObject Lib /"kernel32.dll/" (Byval hHandle As Long, Byval dwMilliseconds As Long) As Long
Const INFINITE = &HFFFF
Const WAIT_TIMEOUT = &H102
/'***************************************************************************
Sub Click(Source As Button)
Dim haWnd As Long /' handle to the active window
haWnd = GetActiveWindow()
Dim sei As SHELLEXECUTEINFO /' structure used by the function
Dim retval As Long /' return value
/' Load the information needed to open C:WindowsCalc.exe into the structure.
/' Size of the structure
sei.cbSize = Len(sei)
/' Use the optional hProcess element of the structure.
sei.fMask = SEE_MASK_NOCLOSEPROCESS
/' Handle to the window calling this function.
sei.hwnd = haaaWnd
/' The action to perform: open the file.
sei.lpVerb = /"open/"
/' The file to open.
sei.lpFile = /"C:windowscalc.exe/"
/' No additional parameters are needed here.
sei.lpParameters = /"/"
/' The default directory -- not really necessary in this case.
sei.lpDirectory = /"C:windows/"
/' Simply display the window.
sei.nShow = SW_SHOWNORMAL
/' The other elements of the structure are either not used or will be set when the function returns.
retval = ShellExecuteEx(sei)
If retval = 0 Then
/' The function failed, so report the error. Err.LastDllError could also be used instead, if you wish.
Select Case sei.hInstApp
Case SE_ERR_FNF
Msgbox /"The application C:WindowsCalc.exe./"
Case Else
Msgbox /"An unexpected error occured./"
End Select
Else
/' Wait for the opened process to close before continuing. Instead of waiting once for a time of INFINITE, this example repeatedly checks to see if the is still open. This allows the DoEvents function to be called, preventing our script from appearing to lock up while it waits.
Do
Doevents
retval = WaitForSingleObject(sei.hProcess, 0)
Loop While retval = WAIT_TIMEOUT
Msgbox /"Calculator has just closed./"
End If
End Sub
相关文章推荐
- 等待外部程序运行结束以后 主程序再继续运行
- 在Windows上让Python脚本像程序一样可以双击运行
- 如何让Delphi调用外部程序并等待其运行信息(如结束)
- 使用database control 配置数据库时,要求在当前oracle主目录中配置监听程序,必须运行Netca以配置监听程序,然后才能继续。或者可以选择继续,但是不要使用database cont
- C++程序通过SpiderMonkey也可以运行javascript脚本了
- [VB]VB启动/结束另一程序(Shell 等待程序运行结束)
- Qt+OpenCV运行时可以编译通过,但总是出程序异常结束。解决方案!
- 我在delphi中用shellExecute启动了一个程序(ftp);然后想做一个等待,只到ftp进程结束,再继续下面的操作,请问如何监控这个进程是否已结束?
- MASM32编程用两种方法运行外部程序并等待其结束
- 解决VS2010控制台程序运行结束不显示请按任意键继续
- CountDownLatch实现主线程等待所有子线程运行结束后再继续执行的实现
- main函数结束后还可以继续运行语句??
- VBShell调用后等待程序运行结束
- Delphi 调用外部程序并等待其运行结束
- 使用vb.net等待外部程序运行完毕才继续
- 等待程序运行结束
- Java后台执行Shell脚本, Java方法不用等待Shell程序执行完成并保证关掉Java程序Shell脚本正常运行
- 如何让Delphi调用外部程序并等待其运行结束
- VB Shell调用后 等待程序运行结束
- VC启动一个程序并等待运行结束