Thread: how to terminate process from Task Manager -> Processes -> MyApplication.exe

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    58

    how to terminate process from Task Manager -> Processes -> MyApplication.exe

    hello all
    i have simple Win32 gui application ( simple window )
    but when i close the window the application still remains in the task manger processes list
    how can i terminate the process completely with win32 api?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Either the window is simply closing without ever exiting the message loop, or there's another thread still running in the app.
    Post your code for further assistance.

    gg

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    58
    well in my code i have :
    PHP Code:
    case WM_CLOSE :
          
    DestroyWindow(hwnd);
          break;

       case 
    WM_DESTROY :
          
    PostQuitMessage(0);
          break; 
    but i have another thread runing in the background also

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    What about notifying the background thread that it needs to exit as well?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    In your multi-threading programs you should always keep track of their thread ids (this is the microsoft prescribed way of doing things) so you can end them nicely. The alternative (which I have found works better in some instances) is have a KeepAlive() function that is polled by sub-threads (assuming they are looping, of course) and exit accordingly.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Do you pass hwnd in your GetMessage call? If so, pass NULL instead.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by CornedBee View Post
    Do you pass hwnd in your GetMessage call? If so, pass NULL instead.
    I am also curious about it, I always passed null here, even though i have my HWND ready at the time, and it worked, why so?

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    It's a filter parameter. If you pass a HWND to it, it only gives you messages for that window. If you pass NULL, it gives you all messages. WM_QUIT is not a window-specific message; you only get it if you pass NULL. As such, if your main application loop passes the hwnd from CreateWindow, after the window is destroyed the program will hang forever in that GetMessage call, waiting for messages for a window that no longer exists.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    HANDLE Process;
    Process = OpenProcess(PROCESS_ALL_ACCESS , true , GetCurrentProcessId());
    TerminateProcess(Process , 0);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Task Manager: Applications vs Processes
    By Shwick in forum Windows Programming
    Replies: 3
    Last Post: 08-14-2008, 06:47 AM
  2. start and stop a process in task manager
    By valthyx in forum C++ Programming
    Replies: 6
    Last Post: 07-21-2008, 01:12 PM
  3. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM
  4. binary tree of processes
    By gregulator in forum C Programming
    Replies: 1
    Last Post: 02-28-2005, 12:59 AM
  5. Replies: 5
    Last Post: 04-17-2003, 07:07 AM