我有个位的C#代码看起来像这样:GetWindowRect()没有返回一个矩形
[DllImport("user32.dll")]
private static extern bool GetWindowRect(IntPtr hWnd, ref Rect rect);
Rect rect = Rect.Zero;
NativeMethods.GetWindowRect(hWnd, ref rect);
然而,当我运行该代码时,rect
变量仍然等于Rect.Zero
(顶/底/左/右都是零),即使GetWindowRect()
返回成功。这个函数调用序列在C++中执行时效果很好,但在C/P/Invoke中调用时不会。
我确定我正在打电话给GetWindowRect()
;那不是问题。问题是GetWindowRect()
总是返回RECT
的{0,0,0,0}
,无论我如何更改函数调用或我如何定义P/Invoke。
http://www.pinvoke.net/default.aspx/user32/getwindowrect.html –
这可能有所帮助:http://stackoverflow.com/a/6415255/301857 –
您能否显示'Rect'的定义? –