See the question and my original answer on StackOverflow

I suggest you take a look at the UI Automation API, that's the best you will ever find, as it was designed for this kind of usage, and forget about raw low-level ole' Windows API :-)

I quote the intro:

UI Automation provides programmatic access to most user interface (UI) elements on the desktop, enabling assistive technology products such as screen readers to provide information about the UI to end users and to manipulate the UI by means other than standard input. UI Automation also allows automated test scripts to interact with the UI.

A goot start is to try the UISpy tool. It will help check the kind of information you will be able to find programmatically before writing any code which at least will ensure you don't waste your time.

It's not so easy to find, here is a link: