我试图将WPF表单显示为在VSTO Excel中弹出,并且“弹出”窗口必须与父Excel处于相同的位置和大小。我正在尝试下面的代码,但是由于某些原因,我没有得到实际位置。有人可以帮忙吗
更新-如果我的屏幕分辨率等级为100%,则以下代码可以正常工作。如果不等于100%,我就无法获得准确位置
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
About about = new About();
RECT r = new RECT();
if (GetWindowRect((IntPtr)Globals.ThisAddIn.Application.ActiveWindow.Hwnd, ref r))
{
about.Top = r.Top;
about.Left = r.Left;
}
var helper = new System.Windows.Interop.WindowInteropHelper(about);
helper.Owner = (System.IntPtr)Globals.ThisAddIn.Application.Hwnd;
about.ShowDialog();