BCB 如何隐藏DOS窗口 - C++ Builder / Windows SDK/API
程序用有用system(xxxx)来下DOS指令,只有一行执行的很快,但是DOS窗口有闪过,如何才能让这个窗口隐藏不闪过呢?
之前用ShellExecute 函数来调用 xxx.bat文件,并设置为SW_HIDE,不会有窗口,能达到预期效果。
但是因为只有一行指令,且每次可能不一样,如果每次都出创建bat文件,在调用感觉比较麻烦,所以有以上问题,谢谢各位高手的解答!
[解决办法]
CreateProcess为终极大法:)
[解决办法]
WinExec 也可吧
[解决办法]
看我05年的贴,用的是CreateProcess
http://topic.csdn.net/t/20050326/17/3883795.html
[解决办法]
我来抢点分。
void __fastcall TForm1::Button1Click(TObject *Sender){TStringList *S1=new TStringList();AnsiString Command="net view";RunCmd(Command,S1) ;Memo1->Lines->AddStrings(S1);}//---------------------------------------bool __fastcall RunCmd(AnsiString cmd,TStringList *stringlist){ TMemoryStream *memstream=new TMemoryStream(); AnsiString rn="\\r\\n"; PROCESS_INFORMATION proc; STARTUPINFO start; SECURITY_ATTRIBUTES sa; long ret; unsigned long lngBytesread; HANDLE hReadPipe,hWritePipe; char *strBuff=(char *)malloc(256); if(strBuff==NULL) { return false; } sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.bInheritHandle=true; sa.lpSecurityDescriptor=NULL; ret=CreatePipe(&hReadPipe,&hWritePipe,&sa,0); if(ret==0) { //创建管道失败 return false; } memset(&start,0x00,sizeof(STARTUPINFO)); start.cb=sizeof(STARTUPINFO); start.dwFlags=STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; start.hStdOutput=hWritePipe; start.hStdError=hWritePipe; bool retc=CreateProcess(NULL,cmd.c_str(),NULL,NULL,true, 0, 0, NULL, &start, &proc); if(!retc) { return false; } CloseHandle(hWritePipe); unsigned long len; memstream->Position=0; while(true) { memset(strBuff,0x00,256); GetFileSize(hReadPipe,&len); ret = ReadFile(hReadPipe, strBuff, 256, &lngBytesread,NULL); if(ret==0) { break; } else { memstream->Write(strBuff,lngBytesread); } } CloseHandle(proc.hProcess); CloseHandle(proc.hThread); CloseHandle(hReadPipe); memstream->Position=0; free(strBuff); stringlist->LoadFromStream(memstream); memstream->Clear(); delete memstream; return true;}