GetWindowRect 没有像我认为的那样工作

GetWindowRect is not working as I thought it should

我正在为 Elite Dangerous 游戏设置覆盖程序。
当移动 window 时,叠加层不想保持游戏的大小 window。
每当移动 window 时,叠加层都会相对于程序展开和缩回,我不希望这样。
这是显示问题的视频 https://youtu.be/DYeHYOOOIkM

我已经在谷歌上搜索了几个小时,试图解决这个问题,但我根本找不到任何答案。
我能找到并修复的只是顶部和左侧位置,而不是扩展问题。

public static extern bool GetWindowRect(IntPtr hwnd, out Rectangle IpRect);

[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true)]
private static extern bool GetWindowInfo(IntPtr hwnd, ref WINDOWINFO pwi);

private Rectangle _newWindowSize;

private void TimerRePositionOverlayWindow_Tick(object sender, EventArgs e)
{
    GetWindowRect(handle, out _newWindowSize);

    Top = _newWindowSize.Top + 31;
    Left = _newWindowSize.Left + 8;
    Width = _newWindowSize.Width;
    Height = _newWindowSize.Height;

    Console.WriteLine($"{_newWindowSize}");
}

我希望尺寸应该与游戏 window 尺寸完全相同。
不扩缩。

因为矩形不是 RECT。它们似乎包含相同的信息,但它们是非常非常不同的对象。

暂时假设您是一种方法,并且您希望一本练习簿将您的数据写入其中。如果我递给你一本练习册,你会知道转动封面打开它并在里面写下你的数据。那你把书还给我。

如果反过来,我给你一本字典,你可以打开封面,然后你把你的数据写在单词定义上,然后把结果还给我。我看着它,但我无法理解数据或文字,因为它们混合在一起。

如果例程需要特定结构,请给它一个。否则,它会把你给它的东西当作它要求的结构,没有人会高兴!

所以你应该做的是:

Encapsulate it: write a method that accepts / returns a Rectangle, but which creates the RECT internally and hands that to the GetWindowRect function.