如果你的进程创建成功,还要在WaitForSingleObject(stProcessInfo.hProcess, INFINITE)之前调用ClsoeHandle(stProcessInfo.hThread)释放自进程的主线程对象
解决方案 »
- vc++6.0中如何添加消息映射?
- 对话框wm_char的响应
- 请教如何在CListCtrl控件中添加一个右键菜单,并且获取当前鼠标所指示的数据,可以写一下源码吗?
- 我想问问CTreeCtrl中GetSelectedItem的问题.
- 编译通不过
- 菜鸟问个问题,关于ado的问题!?动态连接库的问题!在线等
- Unicode <---> Ansi 互相转换?
- 急!!!!在idl中修饰属性的 属性 proput 和 proputref有什么区别
- 送分问题:怎样在VC++中建立 ACTIVEX DLL(象在VB中那么方便)?
- 如何让程序最小化后成一个小图标?
- 用cmainframewnd::setwindowtext(。。)为什么不能改变窗口的标题呢?
- 金融类主流APP编程语言框架
我还需要判断进程是否结束,何时结束,所以去掉之后就搞不定了,请指教。
解决方法有二:
1。你可以试试timeSetEvent,它用的回调函数是运行在一个独立线程的,缺点是很多API在这里都不能用,只有象PostMessage之类的能用。
2。WaitForSingleObject(stProcessInfo.hProcess, 100);比如100ms就停止一下阻塞,存取消息队列,然后再调一下WaitForSingleObject(stProcessInfo.hProcess, 100);
如果你需要随时检查子进程是否结束,可以定时(Timer)/主线程Idle时用:
if(WaitForSingleObject(stProcessInfo.hProcess, 0) == WAIT_OBJECT_0) {...}
检察,或在子线程中WaitForSingleObject(stProcessInfo.hProcess, INFINITE);
int MessageLoop
(
HANDLE* lphObjects, // handles that need to be waited on
int cObjects // number of handles to wait on
)
{
while( true )
{
// block-local variable
DWORD result ;
MSG msg ; // peek new message
while( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
{
// if have new messages do following process
// If it's a quit message, we're out of here.
if( WM_QUIT == msg.message )
return 1;
// Otherwise, dispatch the message.
DispatchMessage(&msg);
} // Wait for any message sent or posted to this queue
// or for one of the passed handles be set to signaled.
result = MsgWaitForMultipleObjects( cObjects, lphObjects, FALSE, INFINITE, QS_ALLINPUT|QS_TIMER ); // The result tells us the type of event we have.
if( (WAIT_OBJECT_0 + cObjects) == result )
{
// New messages have arrived.
// Continue to the top of the always while loop to
// dispatch them and resume waiting.
continue;
}
else
{
// do yoursomething
// One of the handles became signaled.
DoStuff( result - WAIT_OBJECT_0 ) ;
}
}
} 你在createprocess之后。
调用MessageLoop( &hProcess, 1 );
即可。visit MSDN foe detail
那个DoStuff(..)函数表示你在事件发生后(在你的情况下就是创建的进程结束了)所做的事,你需要定义这个函数。