Capturing a child window

This is a discussion on Capturing a child window within the Windows Programming forums, part of the Platform Specific Boards category; I use this: Code: HWND hOW = FindWindow("ExploreWClass", NULL); SetWindowText(hOW, "I'v got only the bar!"); It captures the main window ...

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Post Capturing a child window

    I use this:

    Code:
     
     HWND hOW = FindWindow("ExploreWClass", NULL);
     SetWindowText(hOW, "I'v got only the bar!");
    It captures the main window only, I can capture a child window such as a button or edit box though. How do I capture a child window?

    Thanks, August

  2. #2
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Perhaps you could use EnumChildWindows to find the child window you want?

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I am not fimilar with the second argument type.
    Could you show me how to use it?

    EnumChildWindows(hOW, ??????, lParam);

  4. #4
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    The 2nd argument is to a callback function that looks like this.

    For example,

    Code:
    BOOL CALLBACK EnumChildProc( HWND hwnd, LPARAM lParam )
    {
      int* count = (int*) lParam ;
      
      (*count)++;
      
      return TRUE ; // get next child window if it exists
    }
    And I call EnumChildWindows like this.

    Code:
              int count = 0 ;
              EnumChildWindows( hwnd, EnumChildProc, (LPARAM)&count ) ;
              TCHAR buffer[100];
              wsprintf( buffer, "%d", count );
              MessageBox( hwnd, buffer, "Number of Child Windows", MB_OK );
              return 0;

  5. #5
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I tried to compile your script but I got the error:

    Quote Originally Posted by Dev-C++
    `EnumChildProc' undeclared (first use in this function)

  6. #6
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Did you define EnumChildProc?

    Is it in scope?

  7. #7
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Okay, now I did it, it tells me the number of child windows in a parent window.

    int count = 0 ;
    HWND hMainForm = FindWindow("SysListView32", NULL);
    EnumChildWindows( hMainForm, EnumChildProc, (LPARAM)&count ) ;
    TCHAR buffer[100];
    wsprintf( buffer, "%d", count );
    MessageBox( hwnd, buffer, "Number of Child Windows", MB_OK );
    return 0;

    That is neat, but how to I get the handle for each one of those windows?

  8. #8
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Take a look at the hwnd parameter for EnumChildProc .

  9. #9
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Okay, I got it now. Thanks Dante Shamest!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 09:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 11:17 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM

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