[转帖]在PB中调用外部程序并判断其运行结束
在PB中经常要调用外部程序并等待此程序运行结束后显示相关信息。如我们要备份Adaptive Server Anywhere 6.0数据库,在备份结束后显示"备份完成!"的提示信息,如果在调用备份程序dbbackup后马上用messagebox显示提示信息,那么程序运行时则会出现这种情况: dbbackup备份程序还在运行,"备份完成!"的提示就已经显示了,显然不符合我们的设想。对于这种情况,我们可以借助API函数FindWindowA()、IsWindow()和PB本身函数yield()来解决。<P>声明API函数:<BR>Function long FindWindowA (String lpClassName , String lpWindowName ) Library "user32.dll" <BR>Function boolean IsWindow (Long hwnd ) Library "user32.dll"</P>
<P>调用:<BR>ulong ll_handle<BR>int li_loop</P>
<P>SetPointer(HourGlass!) //设置鼠标指针<BR>//运行备份数据库程序dbbackup,并使其最小化<BR>run("dbbackup -c ~"uid=dba;pwd=sql; dbf=D:\Sybase\Adaptive Server Anywhere 6.0\asademo.db~" d:\backup", Minimized!)</P>
<P>ll_handle = 0<BR>//循环至dbbackup窗口打开<BR>Do While ll_handle = 0<BR>ll_handle = FindWindowA("tty","dbbackup")<BR>yield() //<BR>loop <BR>//等待dbbackup窗口关闭<BR>Do While isWindow(ll_handle)<BR>Yield()<BR>Loop<BR>//应用执行完成<BR>MessageBox("提示信息", "备份完成!")<BR></P> 这个估计最近会用到,不错.
页:
[1]