title: Current program/file name in focus (Windows)
body: <p>I am coding an application in C# that needs to know the current program and files a user has in focus.</p>
  
  <p>I.e. I want to write functions like:</p>
  
  <pre><code>string GetProgramNameCurrentlyInFocus() { ... }
  string GetFilenameCurrentlyInFocus() { ... }
  </code></pre>
  
  <p>Which return the current program executable filename (e.g. "word.exe") or the actual official program name (e.g. "Microsoft Word 2007"), and the current file that is being viewed by the user with the current program (e.g. "C:\Users\Mat\Documents\essay.doc"), respectively.</p>
  
  <p>Products like RescueTime as well as SysInternals can do these things so it is possible.  I can get the title of the current program in focus, but that is not good enough as some programs do not say the program name in the title.</p>
  
  <p>So, does anyone know how to code functions like that? Any tips or places I should look?</p>
  
  <p>Note: I've checked out SysInternal, and despite still being free, the source code is no longer available since Microsoft bought them out.</p>
  
  <p>~Mat</p>