Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to suspend the current application

how to suspend the current application

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Krauze
    wrote on last edited by
    #1

    In fact Ive called ShellExecute() to execute another application when clicking on the button on the dialog. And I want to suspend the current dialog until the app executed by ShellExecute() finishes its tasks. But I dont know how to do it. Can anyone help? Thanx in advance. PS: I dont know whether WaitForSingleObject() will work.

    A C 2 Replies Last reply
    0
    • K Krauze

      In fact Ive called ShellExecute() to execute another application when clicking on the button on the dialog. And I want to suspend the current dialog until the app executed by ShellExecute() finishes its tasks. But I dont know how to do it. Can anyone help? Thanx in advance. PS: I dont know whether WaitForSingleObject() will work.

      A Offline
      A Offline
      Aescleal
      wrote on last edited by
      #2

      If you WaitForSingleObject on the handle of the spawned process the thread doing the waiting will stop until the spawned app completes. To get the process handle it might be an idea to use ShellExecuteEx as you can find out the handle of the spawned process a bit easier. Cheers, Ash

      K 1 Reply Last reply
      0
      • K Krauze

        In fact Ive called ShellExecute() to execute another application when clicking on the button on the dialog. And I want to suspend the current dialog until the app executed by ShellExecute() finishes its tasks. But I dont know how to do it. Can anyone help? Thanx in advance. PS: I dont know whether WaitForSingleObject() will work.

        C Offline
        C Offline
        Chuck OToole
        wrote on last edited by
        #3

        int RunAppAndWait(char *cmd) // where "cmd" is the command line with args
        {
        PROCESS_INFORMATION ProcInfo;
        STARTUPINFO StartInfo;
        int exit_status = 0;

        memset(&StartInfo, 0, sizeof(StartInfo));
        StartInfo.cb = sizeof(StartInfo);
        if (CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &StartInfo,  &ProcInfo))
        {
        	WaitForSingleObject(ProcInfo.hProcess, INFINITE);	// wait for the command to finish
        	GetExitCodeProcess(ProcInfo.hProcess, (unsigned long \*)&exit\_status);
        	CloseHandle(ProcInfo.hProcess);
        	CloseHandle(ProcInfo.hThread);
        	return exit\_status;
        }
        
        return 1;		// non-zero = failed
        

        }

        K 1 Reply Last reply
        0
        • A Aescleal

          If you WaitForSingleObject on the handle of the spawned process the thread doing the waiting will stop until the spawned app completes. To get the process handle it might be an idea to use ShellExecuteEx as you can find out the handle of the spawned process a bit easier. Cheers, Ash

          K Offline
          K Offline
          Krauze
          wrote on last edited by
          #4

          thanx a lot

          1 Reply Last reply
          0
          • C Chuck OToole

            int RunAppAndWait(char *cmd) // where "cmd" is the command line with args
            {
            PROCESS_INFORMATION ProcInfo;
            STARTUPINFO StartInfo;
            int exit_status = 0;

            memset(&StartInfo, 0, sizeof(StartInfo));
            StartInfo.cb = sizeof(StartInfo);
            if (CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &StartInfo,  &ProcInfo))
            {
            	WaitForSingleObject(ProcInfo.hProcess, INFINITE);	// wait for the command to finish
            	GetExitCodeProcess(ProcInfo.hProcess, (unsigned long \*)&exit\_status);
            	CloseHandle(ProcInfo.hProcess);
            	CloseHandle(ProcInfo.hThread);
            	return exit\_status;
            }
            
            return 1;		// non-zero = failed
            

            }

            K Offline
            K Offline
            Krauze
            wrote on last edited by
            #5

            a really good idea!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups