Home > Mobile >  VSTO Outlook: Detect when Outlook active window is being overlapped by other window desktop app othe
VSTO Outlook: Detect when Outlook active window is being overlapped by other window desktop app othe

Time:01-07

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?

CodePudding user response:

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

CodePudding user response:

Take a look at the following events of the Explorer or Inspector classes from the Outlook object model:

  • BeforeSize - is fired when the user sizes the current window.
  • BeforeMove - is fired when the Outlook window is moved by the user.
  • Deactivate - is fired when an inspector or explorer stops being the active window, either as a result of user action or through program code.
  • Activate - is fired when an inspector or explorer becomes the active window, either as a result of user action or through program code.

None of these events are fired specifically for overlapping, but you may find them helpful.

You may also consider using some Windows API functions for that such as GetForegroundWindow which retrieves a handle to the foreground window (the window with which the user is currently working). But it makes sense only when you know the handle of Outlook window. To get that information you need to cast Outlook windows to the IOleWindow interface which provides the GetWindow method which retrieves a handle of the window, so you could recognize Outlook window handle and any other.

  • Related