您的位置:首页 > 其它

当在程序中运行DOS命令时如何隐藏DOS窗口并判断其结束

2007-09-26 14:54 531 查看
问:我想在程序中运行有关DOS命令,可又不想让用户看到DOS窗口,并想判断一下DOS命令是否已运行结束,难死我了?
答:你的要求也太高了,这样试试吧:

第一步:定义全局外部函数:

Function long ShellExecuteA (long hwnd, string lpOperation ,String lpFile, String lpParameters, String lpDirectory, Long nShowCmd) Library "shell32.dll"

Function long FindWindowA (String lpClassName , String lpWindowName ) Library "user32.dll"

Function boolean IsWindow (Long hwnd ) Library "user32.dll"

[用API函数,可以隐藏应用程序的窗口,但是调用bat批处理命令时需要先建立一个PIF(批处理命令的快捷键方式)文件指定执行完成后关闭窗口(其中的一个属性),否则窗口不会自行关闭。]

第二步:在窗口上建立按扭,clicked事件中包含如下Script:

ulong ll_handle,lu_return

string ls_path

SetPointer(HourGlass!) //设置鼠标指针
//运行DOS批处理命令的快捷键方式,并将其窗口隐藏
lu_return = ShellExecutea(handle(parent), "open", "xxx.pif", "", ls_path, 0)
//最后一个参数改为 4,可以显示执行情况,0为隐藏窗口
if lu_return>32 then
ll_handle = 0
//循环至DOS窗口打开
Do While ll_handle = 0
ll_handle = FindWindowA("tty","xxx")
yield()
loop
//等待DOS窗口关闭
Do While isWindow(ll_handle)
Yield()
Loop
//应用执行完成
MessageBox("提示信息", "运行完毕!")
end if

文章引用自:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: