C# getwindowRect的问题
我在C#中通过调用getWindowRect来获得其他一个程序窗口的位置,在远程服务器上执行,当我打开远程桌面时,远程该程序,能够正确的得到窗口位置,但是当我关闭远程桌面后,getwindowRect得到的位置居然是负值,请求高手给予解答啊。代码如下:
运行结果:
test.Program+RectLeft=283 Top=0 Right=930 Bottom=752
1573276
test.Program+RectLeft=283 Top=0 Right=930 Bottom=752
1573276
test.Program+RectLeft=-32000 Top=-32000 Right=-31840 Bottom=-31969
1573276
test.Program+RectLeft=-32000 Top=-32000 Right=-31840 Bottom=-31969
其中上面两条结果是我打开着远程桌面的时候的输出结果
而当我将远程桌面关闭后,就是下面的结果了,求大牛们解释,不甚感激。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using SimulationClick;
namespace test
{
class Program
{
[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll", EntryPoint = "FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
private static extern bool GetWindowRect(IntPtr hwnd, ref Rect lpRect);
public struct Rect
{
public int Left;
public int Top;
public int Right;
public int Bottom;
public override String ToString()
{
return base.ToString() + "Left=" + this.Left + " Top=" + this.Top + " Right=" + this.Right + " Bottom=" + this.Bottom;
}
}
static void Main(string[] args)
{
while (true)
{
IntPtr avd = FindWindow(null, "5554:Weixin");
if (avd == IntPtr.Zero)
{
Console.WriteLine("no window");
}
else
{
Console.WriteLine(avd.ToString());
Rect rect = new Rect();
GetWindowRect(avd, ref rect);
Console.WriteLine(rect.ToString());
}
Thread.Sleep(5000);
}
}
}
}
运行结果:
test.Program+RectLeft=283 Top=0 Right=930 Bottom=752
1573276
test.Program+RectLeft=283 Top=0 Right=930 Bottom=752
1573276
test.Program+RectLeft=-32000 Top=-32000 Right=-31840 Bottom=-31969
1573276
test.Program+RectLeft=-32000 Top=-32000 Right=-31840 Bottom=-31969
其中上面两条结果是我打开着远程桌面的时候的输出结果
而当我将远程桌面关闭后,就是下面的结果了,求大牛们解释,不甚感激。
...全文
相关推荐
c#模仿按键抓抓抓取句柄
c#模仿按键抓抓抓取句柄,用过按键精灵的人都知道里面有个按键抓抓可以抓取到指定的句柄,c#也可以做
C#句柄操作实例遍历窗体、载图
C#句柄开发实例,遍历窗体现在系统中运行的进程窗体、然后通过句柄操作,实现载图,特别说明,一些进程是不可视的,所以截图会黑屏,我们在后面会增加截图以后的OCR实现,请长期关注我们
C#抓取当前桌面完整信息源码
C#抓取当前桌面完整信息源码
用Visual C#调用Windows API函数
用Visual C#调用Windows API函数
C#版显示与隐藏任务栏的功能实现
C#版显示与隐藏任务栏的功能实现 C#版显示与隐藏任务栏的功能实现


