Thread: More on Processes (getProcesses)

  1. #16
    Registered User
    Join Date
    Apr 2008
    Posts
    58
    Quote Originally Posted by Elysia View Post
    Code:
    TerminateProcess(OpenProcess(PROCESS_TERMINATE,FALSE,PID),0) //Where PID is a int (or UNIT)
    Another (better) way to close a process is to close its main window or send close to all of its windows. That way it will exit the way it should. I don't remember exactly how to to enumerate windows for a given process/thread.
    elysia,
    you mentioned to use getwindow, getnextwindow api, i guess
    what about it?

  2. #17
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    That use of terminate process was an example to Terminate the process with only its identifier.
    ExitProcess is another api function that is similar to TermimateProcess but I don't think that is waht you are looking for. If you want to tell notepad to close and then give notepad the option of doing something first (getting user input), the only way I can think of is to use its handle in a call to SendMessage and send the process a WM_CLOSE message. As the handle should be one to its main window (definitely not a child window) it should be the same as the user clicking on the X button or going File>Exit in notepad. I haven't done this before so I am not sure of it, but it should work in theory. Try it, I would like to see if it works
    //added:
    I think Elysia is referring to look at EnumChildWindows which from msdn: "The EnumChildWindows function is more reliable than calling GetWindow in a loop. An application that calls GetWindow to perform this task risks being caught in an infinite loop or referencing a handle to a window that has been destroyed."
    Last edited by P4R4N01D; 04-30-2008 at 03:36 AM. Reason: EnumChildWindows
    long time no C; //seige
    You miss 100% of the people you don't C;
    Code:
    if (language != LANG_C && language != LANG_CPP)
        drown(language);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 34
    Last Post: 05-27-2009, 12:26 PM
  2. Processes not dying
    By Elkvis in forum Linux Programming
    Replies: 12
    Last Post: 04-23-2008, 08:59 AM
  3. binary tree of processes
    By gregulator in forum C Programming
    Replies: 1
    Last Post: 02-28-2005, 12:59 AM
  4. Computer Processes.... Which can be stopped?
    By Sevrin in forum Tech Board
    Replies: 3
    Last Post: 06-08-2003, 08:13 PM
  5. Unix processes
    By J-Dogg in forum Linux Programming
    Replies: 1
    Last Post: 03-24-2003, 05:42 PM