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. Closing application using sendmessage

Closing application using sendmessage

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
9 Posts 3 Posters 1 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
    Pryabu
    wrote on last edited by
    #1

    Hi, I am having a console application. Its a hidden application.I want to close that application.But still it remains in the task manager,its not getting closed. Im using following code : CWnd * cWindow = FindWindow("Afx:400000:8:10011:0:4604cf", NULL); ::SendMessage(cWindow->m_hWnd, WM_QUIT, (WPARAM) 0, (LPARAM) 0); Can anyone please tell me where is the error? Thanks,

    CPalliniC _ 2 Replies Last reply
    0
    • P Pryabu

      Hi, I am having a console application. Its a hidden application.I want to close that application.But still it remains in the task manager,its not getting closed. Im using following code : CWnd * cWindow = FindWindow("Afx:400000:8:10011:0:4604cf", NULL); ::SendMessage(cWindow->m_hWnd, WM_QUIT, (WPARAM) 0, (LPARAM) 0); Can anyone please tell me where is the error? Thanks,

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Why don't you send WM_CLOSE? See "Terminating Windows-Based Application from Another App". :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      P 1 Reply Last reply
      0
      • CPalliniC CPallini

        Why don't you send WM_CLOSE? See "Terminating Windows-Based Application from Another App". :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        P Offline
        P Offline
        Pryabu
        wrote on last edited by
        #3

        How to get class id for a hidden application

        1 Reply Last reply
        0
        • P Pryabu

          Hi, I am having a console application. Its a hidden application.I want to close that application.But still it remains in the task manager,its not getting closed. Im using following code : CWnd * cWindow = FindWindow("Afx:400000:8:10011:0:4604cf", NULL); ::SendMessage(cWindow->m_hWnd, WM_QUIT, (WPARAM) 0, (LPARAM) 0); Can anyone please tell me where is the error? Thanks,

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          Normal console applications do not have a message loop. It is not message driven. It just starts executing the main function until the main function returns. So you cannot send it a windows message. So if the application is running, it should be either waiting on a wait object or waiting for input or running in a loop. So you need to tell us what exactly is going on here.

          «_Superman_»
          I love work. It gives me something to do between weekends.

          Microsoft MVP (Visual C++)

          Polymorphism in C

          P 1 Reply Last reply
          0
          • _ _Superman_

            Normal console applications do not have a message loop. It is not message driven. It just starts executing the main function until the main function returns. So you cannot send it a windows message. So if the application is running, it should be either waiting on a wait object or waiting for input or running in a loop. So you need to tell us what exactly is going on here.

            «_Superman_»
            I love work. It gives me something to do between weekends.

            Microsoft MVP (Visual C++)

            Polymorphism in C

            P Offline
            P Offline
            Pryabu
            wrote on last edited by
            #5

            That console application acts as a watcher. It will open another application.If that application gets crashed,the watcher will again reinvoke that application.While closing the application,that application will close that watcher too.

            _ 1 Reply Last reply
            0
            • P Pryabu

              That console application acts as a watcher. It will open another application.If that application gets crashed,the watcher will again reinvoke that application.While closing the application,that application will close that watcher too.

              _ Offline
              _ Offline
              _Superman_
              wrote on last edited by
              #6

              OK. Now what I want to know is how the watcher is watching the other application. Does it wait on the process handle? Or is it checking for the process existence in a loop?

              «_Superman_»
              I love work. It gives me something to do between weekends.

              Microsoft MVP (Visual C++)

              Polymorphism in C

              P 1 Reply Last reply
              0
              • _ _Superman_

                OK. Now what I want to know is how the watcher is watching the other application. Does it wait on the process handle? Or is it checking for the process existence in a loop?

                «_Superman_»
                I love work. It gives me something to do between weekends.

                Microsoft MVP (Visual C++)

                Polymorphism in C

                P Offline
                P Offline
                Pryabu
                wrote on last edited by
                #7

                it will check that application in a loop

                _ 1 Reply Last reply
                0
                • P Pryabu

                  it will check that application in a loop

                  _ Offline
                  _ Offline
                  _Superman_
                  wrote on last edited by
                  #8

                  That is not a very good design. This is how I would do it. Start a loop with a flag condition. Use CreateProcess or any other API that returns a handle to the newly created process. Use WaitForSingleObject on the process handle. When WaitForSingleObject returns, use GetExitCodeProcess on the process handle. In the watched application, you can return an arbitrary value (eg. 15243) for normal shutdown. So if GetExitCodeProcess returns the arbitrary value, set the flag so that the control comes out of the loop and the watcher also exits.

                  «_Superman_»
                  I love work. It gives me something to do between weekends.

                  Microsoft MVP (Visual C++)

                  Polymorphism in C

                  P 1 Reply Last reply
                  0
                  • _ _Superman_

                    That is not a very good design. This is how I would do it. Start a loop with a flag condition. Use CreateProcess or any other API that returns a handle to the newly created process. Use WaitForSingleObject on the process handle. When WaitForSingleObject returns, use GetExitCodeProcess on the process handle. In the watched application, you can return an arbitrary value (eg. 15243) for normal shutdown. So if GetExitCodeProcess returns the arbitrary value, set the flag so that the control comes out of the loop and the watcher also exits.

                    «_Superman_»
                    I love work. It gives me something to do between weekends.

                    Microsoft MVP (Visual C++)

                    Polymorphism in C

                    P Offline
                    P Offline
                    Pryabu
                    wrote on last edited by
                    #9

                    Thanks a lot.

                    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