Thread: find hwnd of certian controls on a window.

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155

    find hwnd of certian controls on a window.

    Hey everyone.

    How can I find an element inside of a window of a program? For example, the textarea in notepad.

    I've started off with:
    Code:
    HWND hwnd;
    
    hwnd = FindWindowA ( "notepad", 0 ); //program is in unicode, gotta put the A in front so it'll recognize the quotes.
    Now, how could I find the "Edit" class within the window?

    Thanks,

    Matt
    Last edited by guitarist809; 05-10-2008 at 05:19 PM.
    ~guitarist809~

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You would use GetDlgItem and the ID of that child window, which unfortunately isn't that easy to know.
    Otherwise you would enumerate child windows for the parent window and see if you can sniff out the handle to the child window you seek.
    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.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155
    Quote Originally Posted by Elysia View Post
    You would use GetDlgItem and the ID of that child window, which unfortunately isn't that easy to know.
    Otherwise you would enumerate child windows for the parent window and see if you can sniff out the handle to the child window you seek.
    SPY++ seems to be able to do it so easily, but yet its so tough.

    I am completely lost as far as GetDlgItem goes
    ~guitarist809~

  4. #4
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    Yes Spy++ works amazingly well for this sort of thing. As you are trying to find the hwnd of a control in another process, try the EnumChildWindows Function, passing it the hwnd that you found in FindWindowA.
    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);

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    GetDlgItem(parent, id);
    And you have the handle of your child window. However, you do need to know the id. Each child window will be associated with an id which is used to identify it.
    If you don't know it, then EnumChildWindow is the route you will have to go.
    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
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155
    Honestly, I am not at this level of programming.

    How would I go about doing this (I would have to use the EnumChildWindows function, because I do not have it's ID)
    ~guitarist809~

  7. #7
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    Yeah, you do need to have experience with C to do any Windows programming with it. The hwnd is the handle to the parent window (which you found), and it seems that instead of outputting the handles in some sort of variable/struct it is sending them to a function (lpEnumFunc), the lParam is irrelavent (set it to 0).
    I found an example of using this function from the 5th Edition of Programming Windows used in a MDI app:
    Code:
    case IDM_WINDOW_CLOSEALL:     // Attempt to close all children
                   
         EnumChildWindows (hwndClient, CloseEnumProc, 0) ;
         return 0 ;
    
    
    BOOL CALLBACK CloseEnumProc (HWND hwnd, LPARAM lParam)
    {
         if (GetWindow (hwnd, GW_OWNER))         // Check for icon title
              return TRUE ;
         
         SendMessage (GetParent (hwnd), WM_MDIRESTORE, (WPARAM) hwnd, 0) ;
         
         if (!SendMessage (hwnd, WM_QUERYENDSESSION, 0, 0))
              return TRUE ;
         
         SendMessage (GetParent (hwnd), WM_MDIDESTROY, (WPARAM) hwnd, 0) ;
         return TRUE ;
    }
    Obviously you will want to modify the CloseEnumProc, to check what control the hwnd is referencing and return TRUE. Good Luck!
    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. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  2. Button positioning
    By Lionmane in forum Windows Programming
    Replies: 76
    Last Post: 10-21-2005, 05:22 AM
  3. dont want to use all params
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 02-18-2003, 08:10 AM
  4. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM