1 include <Windows.h> 2 QString program = "C:/Windows/System32/notepad.exe"; 3 QProcess *myProcess = new QProcess(); 4 myProcess->setCreateProcessArgumentsModifier([](QProcess::CreateProcessArguments *args) 5 { 6 args->startupInfo->wShowWindow = SW_HIDE; 7 args->startupInfo->dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; 8 } 9 ); 10 myProcess->start(program, QStringList());
第二种方法
1 QString program = "C:/Windows/System32/notepad.exe"; 2 3 STARTUPINFO si; 4 PROCESS_INFORMATION pi; 5 si.cb = sizeof(STARTUPINFO); 6 GetStartupInfo(&si); 7 si.wShowWindow = SW_HIDE; 8 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; 9 10 if (!CreateProcess(NULL, (LPWSTR)program.utf16(),NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi)) 11 { 12 13 }
今天在项目内遇到的问题,需要调用外部程序,但不能显示此程序界面,在网上找了一下,调试出这两种方法。