title: Trying to get a "button" from a child window
body: <p>I will start by saying that my experience with pinvoke is extremely limited. I know very little of C++, too. But here is my situation...</p>
  
  <p>I have a program in C# that uses pinvoke to get functions like <code>SendMessage</code> and <code>FindWindow</code> and the like from C++. It looks for the name of the window, gets the handles, etc. This works fine right now. I will put the code down a bit lower.</p>
  
  <p>Now I have a situation where I want to find a "button" on one of the child windows. I have the <code>IntPtr</code> of the <strong>Actual Child Window</strong>, at least I think it is. I am very confused about what is a window and what isn't.</p>
  
  <p>I am trying to use <code>EnumChildWindows</code> and <code>FindWindowByCaption</code> and <code>FindWindowEx</code> etc to go through all of the children and find this button. I can get its "caption" with Spy++, but giving that to the <code>FindWindowByCaption</code> does not yield anything. </p>
  
  <p>This is the code that actually finds the parent window. I am sorry if it is confusing, it is being run against very old software.</p>
  
  <p>This is all in C#, using pInvoke. I try to first get the button I want with this method..</p>
  
  <p><code>FindWindowByCaption(IntPtr.Zero, "{{Caption as shown by Spy++}}");</code></p>
  
  <p>This doesn't work, even though I give it the right caption. So I try this... In this example, <code>Handle</code> is the <code>IntPtr</code> of the parent window that contains the button I want to find.</p>
  
  <pre><code>// create a small counter so that we do not try to check
  // too many windows and crash the program.
  int i = 0;
  var previous = new Window();
  var current = new Window();
  
  do {
  
      current = 
          new Window(
              InteropServices.FindWindowEx(
              Handle,
              previous.Handle,
              null, null
          )
      );
      if (current == IntPtr.Zero)
          break;
  
      // add current to list
  
      // continue
      previous = current; // never finds the right button, either.
      ++i;
  } while (i &lt; 500);
  </code></pre>
  
  <p>But even at this, the control I want is never found. Can anyone help me with this? It is getting very frustrating. I can see the <code>Caption</code> in Spy++, I can see that it has a handle. It does not appear to be anything special.</p>