Solved

Run external program in my program

Posted on 1997-12-13
2
184 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
Comment Utility
Use the parameter you would use for ShowWindow: i.e. SW_SHOWNORMAL.

0
 

Expert Comment

by:dlong121497
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now