时间:2021-07-01 10:21:17 帮助过:50人阅读
- <br>using System.Runtime.InteropServices; <br> <br>然后写API引用部分的代码,放入 class 内部 <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br>[DllImport("user32.dll")] <br>private static extern int GetWindowRect(IntPtr hwnd,out Rect lpRect); <br> <br>这个函数有两个个参数,第一个参数是指定窗口句柄;第二个参数接收窗口的左上角和右下角的屏幕坐标,它是Rect结构。Rect结构定义如下: <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br>public struct Rect <br>{ <br>public int Left; <br>public int Top; <br>public int Right; <br>public int Bottom; <br>} <br>演示代码: <br>IntPtr hwnd = FindWindow("", "计算器"); <br>Rect rect = new Rect(); <br>GetWindowRect(hwnd, out lpRect); <br></li><li> </li><li> </li></ol></pre></li></ol></pre>