Solved

Run external program in my program

Posted on 1997-12-13
2
207 Views
Last Modified: 2010-04-10
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
Comment
Question by:logout
2 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 50 total points
ID: 1176208
Use the parameter you would use for ShowWindow: i.e. SW_SHOWNORMAL.

0
 

Expert Comment

by:dlong121497
ID: 1176209
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question