代码名称:如何运行一个程序并且等它运行完之后再继续运行你的mapbasic程序

作者/收集者:liuhui_sky

开发环境:MapBasic

代码:

最近忙起来了,没时间在这里乱侃了,给大家一个现成的例子回去研究研究吧,嘿嘿。
'this is an example of how to execute a program and wait until it is terminated to continue on with the
'mapbasic code.

type startupinfo
     cb as integer
     lpreserved as string
     lpdesktop as string
     lptitle as string
     dwx as integer
     dwy as integer
     dwxsize as integer
     dwysize as integer
     dwxcountchars as integer
     dwycountchars as integer
     dwfillattribute as integer
     dwflags as integer
     wshowwindow as integer
     cbreserved2 as integer
     lpreserved2 as integer
     hstdinput as integer
     hstdoutput as integer
     hstderror as integer
end type

type process_information
     hprocess as integer
     hthread as integer
     dwprocessid as integer
     dwthreadid as integer
end type

declare sub shellandwait(byval runprog as string)
declare sub main()

declare function waitforsingleobject lib "kernel32" (byval hhandle as integer, byval dwmilliseconds as integer) as integer
declare function createprocessa lib "kernel32" (byval lpapplicationname as integer, byval lpcommandline as string, byval lpprocessattributes as integer, byval lpthreadattributes as integer, byval binherithandles as integer, byval dwcreationflags as integer, byval lpenvironment as integer, byval lpcurrentdirectory as integer, lpstartupinfo as startupinfo, lpprocessinformation as process_information) as integer
declare function closehandle lib "kernel32" (byval hobject as integer) as integer

sub shellandwait(byval runprog as string)
     dim retval as integer
     dim proc as process_information
     dim startinf as startupinfo
     
     startinf.cb = 68 'len(startinf)
     
     'execute the given path
     retval = createprocessa(0, runprog, 0, 0, 1, &h20, 0, 0, startinf, proc)

     'disable this app until the executed one is done
     retval = waitforsingleobject(proc.hprocess, -1)
     retval = closehandle(proc.hprocess)
end sub

sub main()
 'this is here for testing
 note "start" 
 call shellandwait("regedit.exe")
 note "end"
end sub