Get the Handle of another process
<p>I have a windows form application in which I am trying to catch the name or ID of the previous process that had the focus. Example:</p>

<p>Lets say I am reading an email in Microsoft Outlook, and then I activate my application. I'd like my application to know that the previous process that had the focus was "OUTLOOK".</p>

<p>I've tried to override void WndProc(ref Message m) and listen to windows messages like WM_ACTIVATE or VM_APPACTIVATE but it seems that the message only returns the previous handle on the same thread only.</p>

<p>I've also tested the solution of having a timer that uses the getforegroundWindow function of user32.dll but the interval has to be very low to be efficient and this is too much CPU consuming.</p>

<p>Any suggestion would be very appreciated,
Thanks.</p>
