Search code examples
c#outlookvstooutlook-addinoffice-addins

VSTO Outlook: Detect when Outlook active window is being overlapped by other window desktop app other than Outlook and also being moved


I am trying to get the Outlook main window (the one currently active) through below piece of code:

dynamic activeWindow = Globals.ThisAddIn.Application.ActiveWindow();

Now, I would like to detect when the active window is overlapped by another window desktop application other than Outlook and also to detect when the Outlook active window is being moved (its position/location is changed). Is there a way to subscribe to such events? If so how?


Solution

  • You can use GetForegroundWindow to figure out which window is in the foreground and determine its parent process using GetWindowThreadProcessId, which you can then compare with the process id of the outlook.exe process.