You actually answered your own question in your response to Originalgriff.
Make an application that simply runs parsing the running applications in windows which is technically called "Enumerating All Processes".
That information is given up by Windows via the Process Status Application Programming Interface (PSAPI).
Enumerating All Processes (Windows)[
^]
So there you have your start point and the coding to start is rather trivial and you can even work out what app is foreground and what apps are background.