title: Windows: how to get a list of all visible windows?
body: <p><em>(by all mean do re-tag with the relevant technology: I don't know which ones they are :)</em></p>
  
  <p>I'll probably come later with more detailed questions, about specific details but for now I'm trying to grasp the "big picture": I'm looking for a way to enumerate "real visible windows" on Windows.  By "real visible window" I mean just that: what a user would call a "window".  I need a way to get a list of all these visible windows, in Z-order.</p>
  
  <p><em>Note that I <strong>do</strong> really need to do that. I've already done it on OS X (where it is a real headache to do, especially if you want to support OS X 10.4, because OS X doesn't have convenient windows API) and now I need to do it under Windows.</em></p>
  
  <p>Here's an example, suppose there are three visible windows on the screen, like this:</p>
  
  <pre><code> +------------------------------------------+
   |                                          |
   |           +=============+                |
   |           |             |                |
   |           |    A   +--------------------------+
   |           |        |                          |
   |    C      |        |             B            |
   |           |        +--------------------------+
   |           |             |                |
   +-----------|             |----------------+
               |             |
               +-------------+
  </code></pre>
  
  <p>Then I need to get back a list like this:</p>
  
  <pre><code> windows B is at (210,40)
   windows A is at (120,20)
   windows C is at (0,0)
  </code></pre>
  
  <p>Then if the user (or the OS) brings the window A to the front, it becomes:</p>
  
  <pre><code> +------------------------------------------+
   |                                          |
   |           +=============+                |
   |           |             |                |
   |           |    A        |---------------------+
   |           |             |                     |
   |    C      |             |        B            |
   |           |             |---------------------+
   |           |             |                |
   +-----------|             |----------------+
               |             |
               +-------------+
  </code></pre>
  
  <p>And I get (ideally) a callback giving me this:</p>
  
  <pre><code>windows A is at (120,20)
  windows B is at (210,40)
  windows C is at (0,0)
  </code></pre>
  
  <p>Doing this under OS X requires the use of amazingly weird hacks (like mandating the user to turn on <em>"Enable Access for assistive device"</em>!) but I've done it under OS X and it works (under OS X, I didn't manage to get a callback everytime some window changes occurs, so I'm polling, but I got it to work).</p>
  
  <p>Now I want to do this under Windows (I really do, no question about it) and I've got a few questions:</p>
  
  <ul>
  <li><p>can this be done?</p></li>
  <li><p>are there well documented Windows APIs (and working as per their specs) allowing to do that?</p></li>
  <li><p>is it easy to register a callback everytime a window changes? (if it is resized, moved, brought to back/front or if a new window pops-up, etc.)</p></li>
  <li><p>what would the gotchas be?</p></li>
  </ul>
  
  <p>I know this question is not specific, which is why I've tried to describe my problem as clearly as possible (including nice ASCII art for which you can upvote this): for now I'm looking at the "big picture".  I want to know what doing such a thing involves under Windows.</p>
  
  <p>Bonus question: imagine you'd need to write a tiny <em>.exe</em> writing the windows names/position/size to a temporary file everytime there's a window change on screen, how long would such a program be approximately in your language of choice and how long would you need to write it?</p>
  
  <p><em>(once again, I'm trying to get the "big picture" to understand what is at work here)</em></p>