Getting window handle from processes ID?

This is a discussion on Getting window handle from processes ID? within the Windows Programming forums, part of the Platform Specific Boards category; exactly that, how do i get a processes/threads window handle if it has one? easily?!...

  1. #1
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267

    Getting window handle from processes ID?

    exactly that, how do i get a processes/threads window handle if it has one? easily?!
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  2. #2
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    Hey,

    I wanted to do this too some time ago, from the process ID i got from spy++. Heres what i found.

    [quote]

    The OpenProcess function returns a handle to an existing process object.

    HANDLE OpenProcess(
    DWORD dwDesiredAccess, // access flag
    BOOL bInheritHandle, // handle inheritance flag
    DWORD dwProcessId // process identifier
    );

    [\quote]

    I coudnt get this to work though, but maybe you can? I think its the correct function for this but im not 100% sure. Please let me know if you get it working, another thing, dosnt the process id change everytime a program is restarted?

    Hope tha thelps,
    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  3. #3
    Davros
    Guest
    > Getting window handle from processes ID

    I believe the only way to do this is to enumerate through all the windows & compare associated process IDs.

  4. #4
    Unregistered
    Guest
    >I think its the correct function for this but im not 100% sure.

    nope unfortunatly...

    >dosnt the process id change everytime a program is restarted?

    i don't know but i would assume its based on the number of processes run or running.

    >I believe the only way to do this is to enumerate through all the windows & compare associated process IDs.

    i think your right so thats what i did...

    but i got a new question for ya!

    HOW IN THE **** IS THIS A ENDLESS LOOP!!!!!

    if((RepCount < gMaxReps) || gMaxReps == 0)
    {
    PostMessage(AppDlg->ps[AppDlg->SelectedProcess].hwnd[0],WM_KEYDOWN,AppDlg->key[0],0);
    PostMessage(AppDlg->ps[AppDlg->SelectedProcess].hwnd[0],WM_KEYUP,AppDlg->key[0],0); // this function is never reached!!!

    messages are still processed by the app just nothing goes past the first call to PostMessage!!!! it just repeats the same damned lines endlessly!!!!!!! untill another message is needing to be processed! EVEN IN THE DEBUGGER IT IGNORES MY BREAKPOINTS!!!!!GGGGAAAAAAAAAHHHHH!!!!!!!

  5. #5
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    btw: thats me up there!
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with setting text into LTEXT using Window Handle
    By jasperleeabc in forum Windows Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Adding buttons, edit boxes, etc to the window
    By rainmanddw in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2006, 03:07 PM
  3. Strange/false errors
    By Ganoosh in forum Windows Programming
    Replies: 8
    Last Post: 10-20-2005, 04:54 PM
  4. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM

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