Thread: Getting window handle from processes ID?

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

    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,263
    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