I am trying to write a program which starts itself as a DETACHED_PROCESS
when the user hits the close botton in the title bar and following is the code for handling the WM_CLOSE
message:
case WM_CLOSE:
CreateProcess(NULL, szPath, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL,
&si, &pi); // szPath contains the path of the same calling process
return 0;
but the process is getting terminated without creating a new instance of itself. Why?
Also, when I do the same for WM_DESTROY
message, the program creates 25 new instances of itself instead of creating just one. Why?
DETACHED_PROCESS
flag means is that a console process won't actually be attached to a console. Using that flag doesn't make much sense with a GUI application. – Cody Gray 37 mins agoWM_DESTROY
as that will be called for all controls too, not the form. You'd need to check thewParam
orlParam
to check if the main form is being closed. – slugonamission 27 mins ago