VC常用代码之创建进程

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

作者:朱金灿

来源:http://blog.csdn.net/clever101

 

           创建进程是编程开发的常用操作。Windows中的创建进程采用API函数CreateProcess实现。下面是一个使用例子:

#include <Windows.h>#include <string>int _tmain(int argc, _TCHAR* argv[]){ STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); std::string strCmdLine = "ping www.baidu.com";  // Start the child process.  if( !CreateProcess( NULL,   // No module name (use command line)  (LPSTR)strCmdLine.c_str(),        // Command line  NULL,           // Process handle not inheritable  NULL,           // Thread handle not inheritable  FALSE,          // Set handle inheritance to FALSE  0,              // No creation flags  NULL,           // Use parent's environment block  NULL,           // Use parent's starting directory   &si,            // Pointer to STARTUPINFO structure  &pi)           // Pointer to PROCESS_INFORMATION structure  )  {  printf( "CreateProcess failed (%d)\n", GetLastError() );  return 1; } // Wait until child process exits. WaitForSingleObject( pi.hProcess, INFINITE ); // Close process and thread handles.  CloseHandle( pi.hProcess ); CloseHandle( pi.hThread );   getchar();   return 0;}

        使用上面的方式创建进程会出现一个控制台界面。要隐藏这个控制台界面,只需要将CreateProcess函数的第六个参数设为CREATE_NO_WINDOW,比如上面对应的代码应改为:

 if( !CreateProcess( NULL,   // No module name (use command line)  (LPSTR)strCmdLine.c_str(),        // Command line  NULL,           // Process handle not inheritable  NULL,           // Thread handle not inheritable  FALSE,          // Set handle inheritance to FALSE  CREATE_NO_WINDOW,              // No creation flags  NULL,           // Use parent's environment block  NULL,           // Use parent's starting directory   &si,            // Pointer to STARTUPINFO structure  &pi)           // Pointer to PROCESS_INFORMATION structure  )  {  printf( "CreateProcess failed (%d)\n", GetLastError() );  return 1; }
           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
这里写图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值