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. Restarting a running program

Restarting a running program

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
10 Posts 5 Posters 5 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.
  • P Offline
    P Offline
    pma
    wrote on last edited by
    #1

    Hi, how to I restart my program from its own. Now I do it with a batch file, it looks like this: 1) process starts a batch-file 2) process stops 3) batchfile waits 2 seconds 4) batchfile starts the process again Has anybody a better solution ? Thank you, Mario

    2 1 Reply Last reply
    0
    • P pma

      Hi, how to I restart my program from its own. Now I do it with a batch file, it looks like this: 1) process starts a batch-file 2) process stops 3) batchfile waits 2 seconds 4) batchfile starts the process again Has anybody a better solution ? Thank you, Mario

      2 Offline
      2 Offline
      224917
      wrote on last edited by
      #2

      ShellExecute(NULL,"open",MyAppPath,"-r","",SW_SHOW ); PostMessage(hWnd,WM_QUIT,NULL,NULL);


      It's not a bug, it's an undocumented feature.
      suhredayan@omniquad.com

      messenger :suhredayan@hotmail.com

      P J 2 Replies Last reply
      0
      • 2 224917

        ShellExecute(NULL,"open",MyAppPath,"-r","",SW_SHOW ); PostMessage(hWnd,WM_QUIT,NULL,NULL);


        It's not a bug, it's an undocumented feature.
        suhredayan@omniquad.com

        messenger :suhredayan@hotmail.com

        P Offline
        P Offline
        Prakash Nadar
        wrote on last edited by
        #3

        suhredayan® wrote: ShellExecute(NULL,"open",MyAppPath,"-r","",SW_SHOW ); whats -r ???


        God is Real, unless declared Integer.

        2 1 Reply Last reply
        0
        • 2 224917

          ShellExecute(NULL,"open",MyAppPath,"-r","",SW_SHOW ); PostMessage(hWnd,WM_QUIT,NULL,NULL);


          It's not a bug, it's an undocumented feature.
          suhredayan@omniquad.com

          messenger :suhredayan@hotmail.com

          J Offline
          J Offline
          Jitendra gangwar
          wrote on last edited by
          #4

          PostQuitMessage(NULL) would be the better choice then PostMessage(hWnd,WM_QUIT,NULL,NULL); jitendra

          2 1 Reply Last reply
          0
          • J Jitendra gangwar

            PostQuitMessage(NULL) would be the better choice then PostMessage(hWnd,WM_QUIT,NULL,NULL); jitendra

            2 Offline
            2 Offline
            224917
            wrote on last edited by
            #5

            Jitendra gangwar wrote: PostQuitMessage(NULL) would be the better choice then PostMessage(hWnd,WM_QUIT,NULL,NULL); If PostQuitMessage(NULL) is called from within a userinterface thread which is one of the many, within your application. It just posts a WM_QUIT message to the thread’s message queue and returns immediately; the function simply indicates to the system that the thread is requesting to quit at some time in the future.


            It's not a bug, it's an undocumented feature.
            suhredayan@omniquad.com

            messenger :suhredayan@hotmail.com

            J 1 Reply Last reply
            0
            • P Prakash Nadar

              suhredayan® wrote: ShellExecute(NULL,"open",MyAppPath,"-r","",SW_SHOW ); whats -r ???


              God is Real, unless declared Integer.

              2 Offline
              2 Offline
              224917
              wrote on last edited by
              #6

              Mr.Prakash wrote: whats -r ??? Hi Prakash, Missed to explain the paramaters. Can omit "-r", which can be otherwise used to indicate the application was restarted. Please check my signature. :-D


              It's not a bug, it's an undocumented feature.
              suhredayan@omniquad.com

              messenger :suhredayan@hotmail.com

              1 Reply Last reply
              0
              • 2 224917

                Jitendra gangwar wrote: PostQuitMessage(NULL) would be the better choice then PostMessage(hWnd,WM_QUIT,NULL,NULL); If PostQuitMessage(NULL) is called from within a userinterface thread which is one of the many, within your application. It just posts a WM_QUIT message to the thread’s message queue and returns immediately; the function simply indicates to the system that the thread is requesting to quit at some time in the future.


                It's not a bug, it's an undocumented feature.
                suhredayan@omniquad.com

                messenger :suhredayan@hotmail.com

                J Offline
                J Offline
                Jitendra gangwar
                wrote on last edited by
                #7

                suhredayan® wrote: If PostQuitMessage(NULL) is called from within a userinterface thread which is one of the many, within your application. It just posts a WM_QUIT message to the thread’s message queue and returns immediately; the function simply indicates to the system that the thread is requesting to quit at some time in the future. If PostQuitMessage(NULL) is called from within a userinterface thread which is one of the many, within your application. It just posts a WM_QUIT message to the thread’s message queue and returns immediately; the function simply indicates to the system that the thread is requesting to quit at some time in the future. But according to MSDN -- Remarks The WM_QUIT message is not associated with a window and therefore will never be received through a window's window procedure. It is retrieved only by the GetMessage or PeekMessage functions. Do not post the WM_QUIT message using the PostMessage function; use PostQuitMessage.

                U 1 Reply Last reply
                0
                • J Jitendra gangwar

                  suhredayan® wrote: If PostQuitMessage(NULL) is called from within a userinterface thread which is one of the many, within your application. It just posts a WM_QUIT message to the thread’s message queue and returns immediately; the function simply indicates to the system that the thread is requesting to quit at some time in the future. If PostQuitMessage(NULL) is called from within a userinterface thread which is one of the many, within your application. It just posts a WM_QUIT message to the thread’s message queue and returns immediately; the function simply indicates to the system that the thread is requesting to quit at some time in the future. But according to MSDN -- Remarks The WM_QUIT message is not associated with a window and therefore will never be received through a window's window procedure. It is retrieved only by the GetMessage or PeekMessage functions. Do not post the WM_QUIT message using the PostMessage function; use PostQuitMessage.

                  U Offline
                  U Offline
                  User 1017986
                  wrote on last edited by
                  #8

                  PostQuitMessage(0); form within another UI Thread will not exit the application. But PostMessage(hWnd,WM_QUIT,0,0); will be caught by the underlying handlers and the application will get exited for sure, provided its the handle to the main window. so i feel suhredyan's method atleast ensures that the application is exited.

                  J 1 Reply Last reply
                  0
                  • U User 1017986

                    PostQuitMessage(0); form within another UI Thread will not exit the application. But PostMessage(hWnd,WM_QUIT,0,0); will be caught by the underlying handlers and the application will get exited for sure, provided its the handle to the main window. so i feel suhredyan's method atleast ensures that the application is exited.

                    J Offline
                    J Offline
                    Jitendra gangwar
                    wrote on last edited by
                    #9

                    I am agree with you. Thanks for correcting me.

                    P 1 Reply Last reply
                    0
                    • J Jitendra gangwar

                      I am agree with you. Thanks for correcting me.

                      P Offline
                      P Offline
                      pma
                      wrote on last edited by
                      #10

                      Thank you all!

                      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