| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 475 人关注过本帖
标题:调用程序运行的问题
只看楼主 加入收藏
rip32
Rank: 1
等 级:新手上路
帖 子:67
专家分:0
注 册:2008-10-10
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
调用程序运行的问题
调用了外部的一个EXE程序进行计算,我要在程序运行的时候出现一个提示框:程序正在运行
我现在的代码是这样的
        Dim pid As Long
        pid = Shell(App.Path & "\dai.exe", vbMinimizedFocus)
        '判断计算是否完成
        hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid)
        Do
        Call GetExitCodeProcess(hProcess, ExitCode)
        DoEvents
        Loop While ExitCode = STILL_ALIVE
        Call CloseHandle(hProcess)
        MsgBox ("计算已经结束")
这段代码只是可以当程序完成的时候出现一个提示,说计算完成,但是不能显示程序运行的状态。请问在里面什么位置伽依据代码就可以了?加什么样的呢?谢谢
搜索更多相关主题的帖子: 运行 
2009-07-26 18:48
bczgvip
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:66
帖 子:1310
专家分:5312
注 册:2009-2-26
收藏
得分:0 
??????
详细.
2009-07-26 18:59
rip32
Rank: 1
等 级:新手上路
帖 子:67
专家分:0
注 册:2008-10-10
收藏
得分:0 
回复 2楼 bczgvip
就是在那里面加依据代码,然调用的程序运行的过程中给出一个提示框,说“程序正在运行”。运行结束给出提示“运行结束”。现在后边的功能实现了,前边的没有啊!
2009-07-26 19:55
bczgvip
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:66
帖 子:1310
专家分:5312
注 册:2009-2-26
收藏
得分:20 
Option Explicit

Private Declare Function OpenProcess Lib "kernel32" _
                ( _
                ByVal dwDesiredAccess As Long, _
                ByVal bInheritHandle As Long, _
                ByVal dwProcessId As Long _
                ) As Long

Private Declare Function CloseHandle Lib "kernel32" _
                ( _
                ByVal hObject As Long _
                ) As Long
   
Private Declare Function WaitForSingleObject Lib "kernel32" _
                ( _
                ByVal hHandle As Long, _
                ByVal dwMilliseconds As Long _
                ) As Long

Private Const SYNCHRONIZE = &H100000
Private Const INFINITE = &HFFFFFFFF

'PROCESS_ALL_ACCESS All possible access rights for a process object.
'PROCESS_CREATE_PROCESS Required to create a process.
'PROCESS_CREATE_THREAD Required to create a thread.
'PROCESS_DUP_HANDLE Required to duplicate a handle using DuplicateHandle.
'PROCESS_QUERY_INFORMATION Required to retrieve certain information about a process, such as its exit code and priority class (see GetExitCodeProcess and GetPriorityClass).
'PROCESS_SET_QUOTA Required to set memory limits using SetProcessWorkingSetSize.
'PROCESS_SET_INFORMATION Required to set certain information about a process, such as its priority class (see SetPriorityClass).
'PROCESS_TERMINATE Required to terminate a process using TerminateProcess.
'PROCESS_VM_OPERATION Required to perform an operation on the address space of a process (see VirtualProtectEx and WriteProcessMemory).
'PROCESS_VM_READ Required to read memory in a process using ReadProcessMemory.
'PROCESS_VM_WRITE Required to write to memory in a process using WriteProcessMemory.
'SYNCHRONIZE Required to wait for the process to terminate using the wait functions.

Private Sub Command1_Click()
    'Dim pId&, pHnd&
    '声明pId    变量存储Process Id
    '声明pHnd   变量存储Process Handle
    'pId = Shell("Notepad", vbNormalFocus)
    'Shell传回Process Id
    'pHnd = OpenProcess(SYNCHRONIZE, 0, pId)
    '取得 Process Handle
   
    Dim pHnd& '进程句柄
    pHnd = OpenProcess(SYNCHRONIZE, 0, Shell("Notepad", vbNormalFocus))
   
    If pHnd <> 0 Then
        '程序正在运行
        Call WaitForSingleObject(pHnd, INFINITE)
        '无限等待,直到程序结束
        Call CloseHandle(pHnd)
        MsgBox ("记事本已经关闭!")
    End If
End Sub
2009-07-26 20:24
快速回复:调用程序运行的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.050194 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved