判断进程结束问题

chabuduo123 2005-01-02 06:18:56
我这有一段别人delfhi的代码,和我要实现的功能完全一样,不知哪位高手能翻译到vc这边:
if CreateProcess(nil, S_CommandLine, @Security, @Security, True, NORMAL_PRIORITY_CLASS, nil, S_WW2000Dir, StartInfo, ProcessInfo) then begin
repeat
I_AppRunning := WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
Application.ProcessMessages;
until (I_AppRunning <> WAIT_TIMEOUT);
end;
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);

其实关键就是这句:Application.ProcessMessages
...全文
155 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
万年水母 2005-01-08
  • 打赏
  • 举报
回复
你自己看代码吧,这里都是winapi了。基本就是把主框架里的消息处理copy了一份出来。
建议不要在主线程里用WaitForSingleObject,建一个线程等,当返回时就post一个消息到主窗口或者你主要处理的消息线程就行了。那个delphi代码只是为了方便,代码少,如果用vc来做就麻烦了。

function TApplication.ProcessMessage(var Msg: TMsg): Boolean;
var
Handled: Boolean;
begin
Result := False;
if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then
begin
Result := True;
if Msg.Message <> WM_QUIT then
begin
Handled := False;
if Assigned(FOnMessage) then FOnMessage(Msg, Handled);
if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and
not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end
else
FTerminate := True;
end;
end;
chabuduo123 2005-01-08
  • 打赏
  • 举报
回复
solokey 2005-01-05
  • 打赏
  • 举报
回复
这个不让循环死掉,响应其他进程的消息.
chabuduo123 2005-01-05
  • 打赏
  • 举报
回复
chabuduo123 2005-01-04
  • 打赏
  • 举报
回复
顶,秦高手不吝赐教!
chabuduo123 2005-01-03
  • 打赏
  • 举报
回复
谁能翻译到vc这边
solokey 2005-01-02
  • 打赏
  • 举报
回复
Call ProcessMessages to permit Windows to process these messages that are currently in the message queue. ProcessMessages cycles the Windows message loop until it is empty and then returns control to the application.

Note: Neglecting message processing affects only the application calling ProcessMessages, not other applications. In lengthy operations, calling ProcessMessages periodically allows the application to respond to paint and other messages.
Note: ProcessMessages does not allow the application to go idle, whereas HandleMessage does.

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧