怎样在一个程序中调用另外几个应用程序?

来源:互联网 发布:整理数据 英文怎么说 编辑:程序博客网 时间:2024/05/21 17:33

摘自:怎样在一个程序中调用另外几个应用程序?

  
---------------------------------------------------------------  
 
如果你在win32环境下面的话,建议你使用线程函数就可以了。  
HANDLE  CreateThread(  
   LPSECURITY_ATTRIBUTES  lpThreadAttributes,  //  SD  
   DWORD  dwStackSize,                                                //  initial  stack  size  
   LPTHREAD_START_ROUTINE  lpStartAddress,        //  thread  function  
   LPVOID  lpParameter,                                              //  thread  argument  
   DWORD  dwCreationFlags,                                        //  creation  option  
   LPDWORD  lpThreadId                                                //  thread  identifier  
);  
BOOL  TerminateThread(  
   HANDLE  hThread,        //  handle  to  thread  
   DWORD  dwExitCode      //  exit  code  
);  
 
---------------------------------------------------------------  
 
当然你要是使用mfc的话,那就更好办。  
CWinThread封装的还不错的,使用就可以了。  
 
---------------------------------------------------------------  
 
还可以使用  
UINT  WinExec(LPCSTR  lpCmdLine,  UINT  ucmdShow);  
---------------------------------------------------------------  
 
ShellExecute(MyWin  ,  "open","C://Program  Files//Internet  Explorer//iexplore.exe",NULL,NULL,SW_SHOW);  
---------------------------------------------------------------  
 
PROCESS_INFORMATION  pi;  
       STARTUPINFO  si;  
       si.cb  =  sizeof(STARTUPINFO);  
       si.lpReserved  =  NULL;  
       si.lpDesktop  =  NULL;  
       si.lpTitle  =  NULL;  
       si.dwFlags  =  0;  
       si.cbReserved2  =  0;  
       si.lpReserved2  =  NULL;  
       BOOL  bres  =  CreateProcess(NULL,"test  a.txt  b.txt",NULL,NULL,false,  
                                               NORMAL_PRIORITY_CLASS,  
                                               NULL,NULL,&si,&pi);  
if(bres==false)  
{  
AfxMessageBox("CreateProcess  failed");  
}  
else  
{  
CloseHandle(pi.hThread);  
CloseHandle(pi.hProcess);  
}  
---------------------------------------------------------------  
 
TerminateProcess  
The  TerminateProcess  function  terminates  the  specified  process  and  all  of  its  threads.    
 
BOOL  TerminateProcess(  
   HANDLE  hProcess,  //  handle  to  the  process  
   UINT  uExitCode      //  exit  code  for  the  process  
);  
友好的方法是找到那几个程序的main  window,  send  WM_CLOSE  message  to  them.  
---------------------------------------------------------------  
 
CreateProcgress  或者windexe函数  
---------------------------------------------------------------  
 
强烈建议用exec系函数,windows和linux下源代码兼容。 
原创粉丝点击