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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Terminating Process [modified]

Terminating Process [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
6 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.
  • G Offline
    G Offline
    gothic_coder
    wrote on last edited by
    #1

    Hello all.. I'm making an application which terminate other processes in different way, i.e using TerminateProcess, WM_CLOSE, WM_QUIT, SC_CLOSE. Now i'm able to terminate process in all the way, But i need bit explanation in WM_CLOSE, WM_QUIT and SC_CLOSE.. How exactly it closes other process?? I believe there are two conditions which need to be fulfilled. 1> The target process has at least one window. 2> The target process doesn't handle the WM_CLOSE, WM_QUIT, SC_CLOSE message. So i'm doing this to enumerates all top level windows, In LPARAM i'm passing the pid of the target process..

    EnumWindows((WNDENUMPROC)Enum_Terminate_Process, (LPARAM) aiPID[i]);

    And in Enum_Terminate_Process, I'm doing something like this..

    BOOL CALLBACK Enum_Terminate_Process(HWND hWnd, LPARAM lParam)
    {
    DWORD dwID;

    GetWindowThreadProcessId(hWnd, &dwID);
    
    if(dwID == (DWORD)lParam)
    {
                char Title\[MAX\_PATH\];
    
    	Title\[0\] = 0;
    	GetWindowText(hWnd, Title, sizeof(Title));
    
    	if(IsWindowEnabled(hWnd) && Title\[0\]!= 0 && Proc\_Argument\[0\]!= 0)
    	{
                        if(strcmp(Proc\_Argument , "-wmc") == 0)
    			SendMessage(hWnd, WM\_CLOSE, 0, 0 );
    		else if(strcmp(Proc\_Argument , "-wmq") == 0)
    			PostMessage(hWnd, WM\_QUIT, 0, 0);
    		else if(strcmp(Proc\_Argument, "-scl") == 0)
    			PostMessage(hWnd, WM\_SYSCOMMAND,SC\_CLOSE,0);
    		else
    			MessageBox(NULL,"Invalid Arguments", "Error", MB\_OK);				
    	}
    }
    
    return TRUE;
    

    }

    So i need to know whether i'm doing right? Thanks All..

    modified on Monday, September 7, 2009 4:39 AM

    L 1 Reply Last reply
    0
    • G gothic_coder

      Hello all.. I'm making an application which terminate other processes in different way, i.e using TerminateProcess, WM_CLOSE, WM_QUIT, SC_CLOSE. Now i'm able to terminate process in all the way, But i need bit explanation in WM_CLOSE, WM_QUIT and SC_CLOSE.. How exactly it closes other process?? I believe there are two conditions which need to be fulfilled. 1> The target process has at least one window. 2> The target process doesn't handle the WM_CLOSE, WM_QUIT, SC_CLOSE message. So i'm doing this to enumerates all top level windows, In LPARAM i'm passing the pid of the target process..

      EnumWindows((WNDENUMPROC)Enum_Terminate_Process, (LPARAM) aiPID[i]);

      And in Enum_Terminate_Process, I'm doing something like this..

      BOOL CALLBACK Enum_Terminate_Process(HWND hWnd, LPARAM lParam)
      {
      DWORD dwID;

      GetWindowThreadProcessId(hWnd, &dwID);
      
      if(dwID == (DWORD)lParam)
      {
                  char Title\[MAX\_PATH\];
      
      	Title\[0\] = 0;
      	GetWindowText(hWnd, Title, sizeof(Title));
      
      	if(IsWindowEnabled(hWnd) && Title\[0\]!= 0 && Proc\_Argument\[0\]!= 0)
      	{
                          if(strcmp(Proc\_Argument , "-wmc") == 0)
      			SendMessage(hWnd, WM\_CLOSE, 0, 0 );
      		else if(strcmp(Proc\_Argument , "-wmq") == 0)
      			PostMessage(hWnd, WM\_QUIT, 0, 0);
      		else if(strcmp(Proc\_Argument, "-scl") == 0)
      			PostMessage(hWnd, WM\_SYSCOMMAND,SC\_CLOSE,0);
      		else
      			MessageBox(NULL,"Invalid Arguments", "Error", MB\_OK);				
      	}
      }
      
      return TRUE;
      

      }

      So i need to know whether i'm doing right? Thanks All..

      modified on Monday, September 7, 2009 4:39 AM

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      gothic_coder wrote:

      So i need to know whether i'm doing right?

      The above looks fine, so yes you are doing it right. However, it is up to the receiving process to decide how it handles these messages, so you need to check that those processes will terminate correctly on receipt of whichever message they are sent.

      G L 2 Replies Last reply
      0
      • L Lost User

        gothic_coder wrote:

        So i need to know whether i'm doing right?

        The above looks fine, so yes you are doing it right. However, it is up to the receiving process to decide how it handles these messages, so you need to check that those processes will terminate correctly on receipt of whichever message they are sent.

        G Offline
        G Offline
        gothic_coder
        wrote on last edited by
        #3

        Alright.. Thanks for confirming :)

        1 Reply Last reply
        0
        • L Lost User

          gothic_coder wrote:

          So i need to know whether i'm doing right?

          The above looks fine, so yes you are doing it right. However, it is up to the receiving process to decide how it handles these messages, so you need to check that those processes will terminate correctly on receipt of whichever message they are sent.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          No, it's wrong, ... in particular WM_CLOSE.

          L 1 Reply Last reply
          0
          • L Lost User

            No, it's wrong, ... in particular WM_CLOSE.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Please explain.

            D 1 Reply Last reply
            0
            • L Lost User

              Please explain.

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Check his post history. He does not have the capability to explain, only criticize.

              "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              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