【问题标题】:VSTO Outlook: Get the current location of the active Outlook window (inspector or explorer)VSTO Outlook:获取活动 Outlook 窗口(检查器或资源管理器)的当前位置
【发布时间】:2023-02-23 04:26:20
【问题描述】:

我正在处理 VSTO Outlook 加载项,现在我面临一个特定用例,我需要获取当前活动 Outlook 窗口(资源管理器或检查器)的屏幕位置。当然不可能使用任何 Outlook API 机制,但我如何使用 Windows API 函数来做到这一点?任何代码 sn-p 将不胜感激。

【问题讨论】:

    标签: c# outlook vsto outlook-addin office-addins


    【解决方案1】:

    ExplorerInspector Outlook 对象公开Top/Left/Width/Height 属性以及WindowState。无需使用 Windows API 来检索窗口位置。

    【讨论】:

      【解决方案2】:

      您可以使用 GetWindowRect 函数来检索指定窗口的边界矩形的尺寸。尺寸以相对于屏幕左上角的屏幕坐标给出。例如:

      [DllImport("user32.dll")]
      [return: MarshalAs(UnmanagedType.Bool)]
      static extern bool GetWindowRect(HandleRef hWnd, out RECT lpRect);
      
      [StructLayout(LayoutKind.Sequential)]
      public struct RECT
      {
           public int Left;        // x position of upper-left corner
           public int Top;         // y position of upper-left corner
           public int Right;       // x position of lower-right corner
           public int Bottom;      // y position of lower-right corner
      }
      
      Rectangle myRect = new Rectangle();
      
      private void button1_Click(object sender, System.EventArgs e)
      {
           RECT rct;
      
           if(!GetWindowRect(new HandleRef(this, this.Handle), out rct ))
           {
           MessageBox.Show("ERROR");
                   return;
           }
           MessageBox.Show( rct.ToString() );
      
           myRect.X = rct.Left;
           myRect.Y = rct.Top;
           myRect.Width = rct.Right - rct.Left + 1;
           myRect.Height = rct.Bottom - rct.Top + 1;
      }
      

      您还可能会发现 GetWindowPlacement 函数很有帮助,该函数检索显示状态以及指定窗口的恢复、最小化和最大化位置。

      【讨论】:

        猜你喜欢
        • 2022-11-02
        • 1970-01-01
        • 2015-12-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-27
        • 2023-02-10
        • 1970-01-01
        相关资源
        最近更新 更多