Home > Software engineering >  MFC interface stuck when call external exe, such as interface to restore exe has been completed
MFC interface stuck when call external exe, such as interface to restore exe has been completed

Time:11-10

//InitStart ();
SHELLEXECUTEINFO ShExecInfo;
ZeroMemory (& amp; ShExecInfo, sizeof (SHELLEXECUTEINFO));//before use best to empty
ShExecInfo. CbSize=sizeof (SHELLEXECUTEINFO);
ShExecInfo. FMask=SEE_MASK_NOCLOSEPROCESS;
ShExecInfo. The HWND=this - & gt; M_hWnd;
ShExecInfo. LpVerb=_T (" open ");
//input to invoke the exe file path
ShExecInfo. LpFile=_T (" C://lix2win//dist//test_sequance_wwz//test_sequance_wwz exe ");
//incoming command line parameter data
ShExecInfo. LpParameters=_T (" NULL ");//if no command line arguments, can be NULL

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- exe files in the current directory (negligible) -- -- -- -- -- -- -- -- -- -- -- -- -- --
//get the current program path
//TCHAR exeFullPath [200].
//GetModuleFileName (NULL, exeFullPath, 100);
////the program run the current path
//TCHAR drive [100], dir [100], fname [100], ext [20].
//_wsplitpath (exeFullPath, drive, dir, fname, ext);
//cstrings dirPath;
//dirPath. The Format (_T (" % s % s "), drive, dir);
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
ShExecInfo. LpDirectory=NULL;//exe directory can be ignored here, write to NULL
ShExecInfo. NShow=SW_HIDE;//here is set to not show exe interface, if set to SW_SHOW, it can display the exe interface
ShExecInfo. HInstApp=NULL;
//call the exe program
ShellExecuteEx (& amp; ShExecInfo);
//close the exe program
If (ShExecInfo hProcess!=NULL)
{
//wait program runs out
WaitForSingleObject (ShExecInfo hProcess, INFINITE);
//close the program
The TerminateProcess (ShExecInfo. HProcess, 0);
ShExecInfo. HProcess=NULL;
}

This is button binding code, the shellexecute method is used to open a wrapper exe, don't move a muscle when running the whole interface have to waiting for the end of the run, could you tell me how to solve this situation

CodePudding user response:

You, isn't about waiting for the program runs out?
WaitForSingleObject (ShExecInfo hProcess, INFINITE);

CodePudding user response:

//wait program runs out
WaitForSingleObject (ShExecInfo hProcess, INFINITE);

Infinite wait ah,
Make a thread to execute the program,

CodePudding user response:

Wait in the UI thread can only be stopped responding, another thread to handle, and then place the results to inform the UI thread

CodePudding user response:

The
refer to the third floor of schrodinger cat replies:
wait in the UI thread can only be stopped responding, another thread to handle, and then place the results to inform the UI thread

Exe is another thread to call

CodePudding user response:

The
refer to the third floor of schrodinger cat replies:
wait in the UI thread can only be stopped responding, another thread to handle, and then place the results to inform the UI thread

I keep waiting for operation interface that commented BuKa forehead, exe can normal running in the background, so also is solved

CodePudding user response:

reference 5 floor Divinova reply:
Quote: refer to the third floor of schrodinger cat replies:

Wait in the UI thread can only be stopped responding, another thread to handle, and then place the results to inform the UI thread

I keep waiting for operation interface that commented BuKa forehead, exe can normal running in the background, so also is solved

If you just start an exe and don't need to do any follow-up actions (and exe communication, waiting for the end of the program is running as a result, etc.), that there is no need to wait
  • Related