当前位置:编程学习 > C#/ASP.NET >>

C# getwindowRect的问题

我在C#中通过调用getWindowRect来获得其他一个程序窗口的位置,在远程服务器上执行,当我打开远程桌面时,远程该程序,能够正确的得到窗口位置,但是当我关闭远程桌面后,getwindowRect得到的位置居然是负值,请求高手给予解答啊。代码如下:
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# GetWindowRect FindWindow --------------------编程问答-------------------- 我打印了屏幕的分辨率,
Console.WriteLine(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width);
Console.WriteLine(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);

无论有没有关闭远程桌面,分辨率都是一致的,1280* 800 --------------------编程问答-------------------- 怎么没人呢,我自己顶顶 --------------------编程问答--------------------
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,