[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

Run external program in my program

Dear
      I want to run an external program in my window
      program, for example Mshearts.exe.      
      Using WinExec, I don't know the parameter
      Would you give me the answer or coding?


void CDeliverDlg::OnScheduleButton()
{
      // TODO: Add your control notification handler code here
      WinExec("Mshearts.exe",??);
}
0
logout
Asked:
logout
1 Solution
 
Tommy HuiCommented:
Use the parameter you would use for ShowWindow: i.e. SW_SHOWNORMAL.

0
 
dlong121497Commented:
Heres a way to start a program and either wait for to complete or continuing with the main process:

/************************************************************/
/* Execute a (DOS) command string or start a windows module */
/* The flag 'waitforit' causes the parent program to wait   */
/* until execution of the child completes if it is true.    */
/* otherwise the child is started and run concurrently.     */
/* The funtion returns the instance handle of the child.    */
/************************************************************/

HINSTANCE Cexecute_command(int waitforit,char *s)
   {
   unsigned int retval;
   int          r,inlist;
   LPSTR        com_str[256];
   char         ts[256];
   FILE         *ff;

#ifdef __WIN32__

   PROCESS_INFORMATION pi;
   STARTUPINFO         si;
   DWORD               exitcode;

#else

   TASKENTRY    lpte;
   HINSTANCE    task_instance;

#endif

   lstrcpy(com_str,s);

#ifndef __WIN32__

   task_instance=WinExec(com_str,SW_SHOWNORMAL);

   if(!waitforit)
      {
      return(task_instance);
      }

   /* Wait until the task has disappeared from the task list */

   lpte.dwSize=sizeof(TASKENTRY);
   while(TRUE)
      {
      inlist=FALSE;
      retval=TaskFirst(&lpte);
      if(!retval) break;                         /* If no first task, something is wrong */
      if(lpte.hInst==task_instance) inlist=TRUE;
      while((lpte.hNext)&&(!inlist))             /* Already found or still looking */
         {
         retval=TaskNext(&lpte);
         if(!retval) break;
         if(lpte.hInst==task_instance)
            {
            inlist=TRUE;
            break;
            }
         }
      if(!inlist) break;
      }
   return(task_instance);

#else

   /* Initialise the 'startup info' structure */

   si.cb=sizeof(si);
   si.lpReserved=NULL;
   si.lpDesktop=NULL;
   si.lpTitle=NULL;
   si.dwX=0;
   si.dwY=0;
   si.dwXSize=0;
   si.dwYSize=0;
   si.dwXCountChars=0;
   si.dwYCountChars=0;
   si.dwFillAttribute=0;
   si.dwFlags=0;
   si.wShowWindow=0;
   si.cbReserved2=0;
   si.lpReserved2=NULL;
   si.hStdInput=0;
   si.hStdOutput=0;
   si.hStdError=0;

   r=CreateProcess(NULL,
                   com_str,
                   NULL,
                   NULL,
                   FALSE,
                   (DWORD)NULL,
                   NULL,
                   NULL,
                   &si,            // Startup info
                   &pi);

   if(waitforit)
      {
      while(TRUE)
         {
         GetExitCodeProcess(pi.hProcess,&exitcode);
         if(exitcode != STILL_ACTIVE) break;
         }
      }
   return((HINSTANCE)0);
#endif
   }

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now