简体   繁体   English

VSTO Outlook:检测 Outlook 活动时 window 与 Outlook 以外的其他 window 桌面应用程序重叠并移动

[英]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:我正在尝试通过以下代码获取 Outlook main window(当前处于活动状态的那个):

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).现在,我想检测活动 window 何时与 Outlook 以外的另一个 window 桌面应用程序重叠,并检测 Outlook 活动 window 何时被移动(其位置/位置已更改)。 Is there a way to subscribe to such events?有没有办法订阅此类事件? If so how?如果是这样怎么办?

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.您可以使用GetForegroundWindow找出哪个 window 在前台,并使用GetWindowThreadProcessId确定它的父进程,然后您可以与 outlook.exe 进程的进程 ID 进行比较。

Take a look at the following events of the Explorer or Inspector classes from the Outlook object model:从 Outlook object model 查看ExplorerInspector类的以下事件:

  • BeforeSize - is fired when the user sizes the current window. BeforeSize - 当用户调整当前 window 的大小时触发。
  • BeforeMove - is fired when the Outlook window is moved by the user. BeforeMove - 当 Outlook window 被用户移动时触发。
  • Deactivate - is fired when an inspector or explorer stops being the active window, either as a result of user action or through program code. Deactivate - 当检查员或资源管理器不再处于活动状态时触发 window,无论是由于用户操作还是通过程序代码。
  • Activate - is fired when an inspector or explorer becomes the active window, either as a result of user action or through program code. Activate - 当检查员或资源管理器成为活动 window 时触发,无论是作为用户操作的结果还是通过程序代码。

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).您也可以考虑使用一些 Windows API 函数,例如GetForegroundWindow ,它检索前台 window(用户当前正在使用的 window)的句柄。 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.但是,只有当您知道Outlook window的手柄时才有意义其他。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM