get current process name & ID on window

This is a discussion on get current process name & ID on window within the Windows Programming forums, part of the Platform Specific Boards category; hi all, i intend to make a program like task manager. so i want to get process name & ID ...

  1. #1
    sgh
    sgh is offline
    Registered User
    Join Date
    Apr 2008
    Posts
    58

    Question get current process name & ID on window

    hi all,
    i intend to make a program like task manager.
    so i want to get process name & ID to run on window right now.
    i searched sample code and did it, my working is bad.
    i used GetWindowThreadProcessId, getWindow, getnextwindow api function, it doesnt work fine.
    could you show me another idea or code to write for it?
    regards.

  2. #2
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    If you are trying to "recreate task manager" I am assuming you want to get the PID of all the processes running. This thread should help you obtain a handle to the process followed by the name and PID.
    More on Processes (getProcesses)
    I just created a task manager and have asked for help, so lookup threads with getProcesses in the title and variable length argument lists (for adding items to a listView). I would post the whole source code, but I have lost it. Good luck and I hope you can create a function similar to GetProcesses, but returns information about every window running. Task manager is a more arduous task than you might think (adding items to a ListView and obtaining the process User name).
    Also I created my app without ever hearing about those functions.
    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);

  3. #3
    sgh
    sgh is offline
    Registered User
    Join Date
    Apr 2008
    Posts
    58
    thank you for your relply.
    i'll show it More on Processes(getProcesses)..

  4. #4
    sgh
    sgh is offline
    Registered User
    Join Date
    Apr 2008
    Posts
    58
    TerminateProcess function ignore all requires and is forced to end process.
    can anybody write another api function for closing process to solve it?

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,625
    Close the process's main window.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    sgh
    sgh is offline
    Registered User
    Join Date
    Apr 2008
    Posts
    58
    thanks for reply.
    by the way i dont know how to get process's main window well, is it true i use getnextwindow and getwindow for getting it?
    and if i get handle of main window, which api do i write?
    i tried to test it using many ways, but it doesnt work fine.
    can you write me about it in detail?
    regards

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,625
    I don't know how to do it, only that it's possible. Sorry.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    sgh
    sgh is offline
    Registered User
    Join Date
    Apr 2008
    Posts
    58
    i understand you.
    anyway, thanks for reply.
    i did it.

  9. #9
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Quote Originally Posted by sgh View Post
    hi all,
    i intend to make a program like task manager.
    so i want to get process name & ID to run on window right now.
    i searched sample code and did it, my working is bad.
    i used GetWindowThreadProcessId, getWindow, getnextwindow api function, it doesnt work fine.
    could you show me another idea or code to write for it?
    regards.
    I'm just not sure how to interpret "get process name & ID to run on window right now". I'll assume the window that you're referring to is your custom task manager and you want to list the processes in that task manager window. But anyway, here's a link to some code to enumerate processes

  10. #10
    sgh
    sgh is offline
    Registered User
    Join Date
    Apr 2008
    Posts
    58
    hi, bobso327
    i got how to end process and i saw already post like you link.
    then my problem is "end process" when i use terminateprocess api, window is forced to end.
    so i'm trying to end process after getting handle of mainwindow, im not finding properly api.
    if you got it, can you help me?

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,625
    If you have the main window handle, then send a WM_CLOSE message to tell the window to close.
    It's not fail-safe, but it's far better than using termineprocess.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    That's assuming the process has a window

  13. #13
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,625
    If it doesn't have one, then there's no given way of terminating the process without the use of terminateprocess.
    Windows works in terrible ways...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    sgh
    sgh is offline
    Registered User
    Join Date
    Apr 2008
    Posts
    58
    never mind!!! i did it. thanks for your interesting and reply

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 07:14 AM
  2. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM
  3. Adding buttons, edit boxes, etc to the window
    By rainmanddw in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2006, 03:07 PM
  4. input/output
    By dogbert234 in forum Windows Programming
    Replies: 11
    Last Post: 01-26-2005, 05:57 AM
  5. Problem with creating new window, from another window
    By Garfield in forum Windows Programming
    Replies: 6
    Last Post: 01-11-2004, 01:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21