我这有一段别人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

解决方案 »

  1.   

    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.
      

  2.   

    你自己看代码吧,这里都是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;