C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 팁&트릭
C++Builder Programming Tip&Tricks
[422] 실행시킨 프로세스 끝나길 기다리기.
김태선 [jsdkts] 8705 읽음    2004-02-16 16:29
가령 메모장 같은거 실행시킨후 끝나기를 기다리는 겁니다.
원래 델파이 소스인데 빌더용으로 고쳤습니다.

void    WaitFor(void *processHandle)
{
  TMsg msg;
  DWORD ret;

  do
  {
    ret = MsgWaitForMultipleObjects(
        1,              // { 1 handle to wait on }
        (void * const *)&processHandle,  // { the handle }
        false,          // { wake on any event }
        INFINITE,       // { wait without timeout }
        QS_PAINT |      // { wake on paint messages }
        QS_SENDMESSAGE  // { or messages from other threads }
        );
    if (ret == WAIT_FAILED)
        return;         // { can do little here }
    if (ret == (WAIT_OBJECT_0 + 1))
    {
      // Woke on a message, process paint messages only. Calling
      // PeekMessage gets messages send from other threads processed.
      while(PeekMessage(&msg, 0, WM_PAINT, WM_PAINT, PM_REMOVE ))
      {
        DispatchMessage(&msg);
      }
    }
  }
  while(ret != WAIT_OBJECT_0);
}

DWORD winexecAndWait32V2(char *FileName, int Visibility)
{
  char  zAppName[512];
  TStartupInfo StartupInfo;
  TProcessInformation ProcessInfo;
  ULONG  ret;

  strcpy(zAppName, FileName);
  ZeroMemory(&StartupInfo, sizeof(StartupInfo));
  StartupInfo.cb = sizeof(StartupInfo);
  StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow = Visibility;
  if (! CreateProcess(NULL,
    zAppName,           // { pointer to command line string }
    NULL,               // { pointer to process security attributes }
    NULL,               // { pointer to thread security attributes }
    false,              // { handle inheritance flag }
    CREATE_NEW_CONSOLE |// { creation flags }
    NORMAL_PRIORITY_CLASS,
    NULL,               // { pointer to new environment block }
    NULL,               // { pointer to current directory name }
    &StartupInfo,       // { pointer to STARTUPINFO }
    &ProcessInfo))      // { pointer to PROCESS_INF }
  {
    return -1;          // { failed, GetLastError has error code }
  }
  else
  {
    WaitFor(ProcessInfo.hProcess);
    GetExitCodeProcess(ProcessInfo.hProcess, &ret);
    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread);
  }
  return ret;
}

부를때는
  winexecAndWait32V2("C:\\WINNT\\notepad.exe", 1);
박지훈.임프 [cbuilder]   2004-05-15 00:25 X
두둥~ 두둥~
이 게시판에 몇년 전에 올렸던 겁니다. ^^
http://www.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_tip&no=37

+ -

관련 글 리스트
422 실행시킨 프로세스 끝나길 기다리기. 김태선 8705 2004/02/16
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.