home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / POLYEDIT.LZH / MODEL / WINETC.CPP < prev   
C/C++ Source or Header  |  1996-05-22  |  3KB  |  130 lines

  1. //
  2. //        ダイアログ処理関数
  3. //
  4. //        1996.1.16        M.Takatsu
  5. //
  6. #include <owl\owlpch.h>
  7. #pragma hdrstop
  8. #include <toolhelp.h>
  9. #include <io.h>
  10. #include "model.h"
  11.  
  12. extern    TWindow *GetModelWindow(void);
  13. extern char ExecPath[];
  14.  
  15. extern "C" void WinInternalError(char *mess);
  16. extern "C" void WinMessage(char *mess);
  17. extern "C" unsigned long WinGetTimer(void);
  18.  
  19. extern "C" int printf(const char *fmt, ...);
  20.  
  21. void WinExecWait(char *lpszCmdLine, UINT fuCmdShow)
  22. {
  23.     STARTUPINFO StartInfo;
  24.     PROCESS_INFORMATION ProcInfo;
  25.     unsigned long ExitCode;
  26.     long begintime;
  27.  
  28.     memset(&StartInfo, 0, sizeof(STARTUPINFO));
  29.     StartInfo.cb = sizeof(STARTUPINFO);
  30.     StartInfo.wShowWindow = fuCmdShow;
  31.  
  32.     if (CreateProcess(NULL, lpszCmdLine, NULL, NULL,
  33.                       FALSE, 0, NULL, NULL, &StartInfo, &ProcInfo) == FALSE) {
  34.         return;
  35.     }
  36.     CloseHandle(ProcInfo.hThread);
  37.     begintime = WinGetTimer();
  38.     while (GetExitCodeProcess(ProcInfo.hProcess, &ExitCode)
  39.         && ExitCode == STILL_ACTIVE
  40.         && WinGetTimer() < begintime + 60 * 1000) {
  41.         GetModelWindow()->GetApplication()->PumpWaitingMessages();
  42.     }
  43.     CloseHandle(ProcInfo.hProcess);
  44. }
  45.  
  46.  
  47. /*
  48.  *    子プロセスを呼び出す。
  49.  *
  50.  */
  51. void    ChildExec( char *comline, int waitflag, int iconify )
  52. {
  53.     char    *p, filename[F_NAME_LEN];
  54.     int nCmdShow;
  55.     if (iconify) {
  56.         nCmdShow = SW_MINIMIZE;
  57.     } else {
  58.         nCmdShow = SW_SHOWDEFAULT;
  59.     }
  60.     strcpy(filename, ExecPath);
  61.     strcat(filename, comline);
  62.     if ((p = strchr(filename, ' ')) != NULL) {
  63.         *p = '\0';
  64.     }
  65.     if ((p = strchr(filename, '\t')) != NULL) {
  66.         *p = '\0';
  67.     }
  68.     p = filename + strlen(filename);
  69.     if (access(filename, 0) == 0
  70.      || (strcpy(p, ".COM"), access(filename,0) == 0)
  71.      || (strcpy(p, ".EXE"), access(filename,0) == 0)
  72.      || (strcpy(p, ".BAT"), access(filename,0) == 0)
  73.      || (strcpy(p, ".PIF"), access(filename,0) == 0)) {
  74.         if (p-filename> 4 && p[-4] == '.' && toupper(p[-3]) == 'H'
  75.          && toupper(p[-2]) == 'L' && toupper(p[-1]) == 'P') {
  76.             GetModelWindow()->WinHelp(filename, HELP_CONTENTS, 0L);
  77.         } else {
  78.             strcpy(filename, ExecPath);
  79.             strcat(filename, comline);
  80.             if (waitflag) {
  81.                 WinExecWait(filename, nCmdShow);
  82.             } else {
  83.                 WinExec(filename, nCmdShow);
  84.             }
  85.         }
  86.     } else {
  87.         p = comline + strlen(comline);
  88.         if (access(comline, 0) == 0
  89.          && p-comline> 4 && p[-4] == '.' && toupper(p[-3]) == 'H'
  90.          && toupper(p[-2]) == 'L' && toupper(p[-1]) == 'P') {
  91.             GetModelWindow()->WinHelp(comline, HELP_CONTENTS, 0L);
  92.         } else {
  93.             if (waitflag) {
  94.                 WinExecWait(comline, nCmdShow);
  95.             } else {
  96.                 WinExec(comline, nCmdShow);
  97.             }
  98.         }
  99.     }
  100.  
  101. }
  102.  
  103. void    WinMessage(char *mess)
  104. {
  105.     printf("%s\n", mess);
  106. //    GetModelWindow()->MessageBox(mess, "Model", MB_OK);
  107. }
  108.  
  109. static int fatal = 0;
  110.  
  111. void    WinInternalError(char *mess)
  112. {
  113.     WinMessage(mess);
  114.     if (++fatal == 2) {
  115.         exit(1);
  116.     }
  117. }
  118.  
  119. unsigned long WinGetTimer(void)
  120. {
  121. #if 1
  122.     return timeGetTime();
  123. #else
  124.     TIMERINFO info;
  125.     info.dwSize = sizeof(TIMERINFO);
  126.     TimerCount(&info);
  127.     return info.dwmsThisVM;
  128. #endif
  129. }
  130.