c# – 为什么我的高度和宽度为0?
发布时间:2020-12-15 18:09:08 所属栏目:百科 来源:网络整理
导读:为什么我用下面的高度和宽度为0: static void Main(string[] args) { Process notePad = new Process(); notePad.StartInfo.FileName = "notepad.exe"; notePad.Start(); IntPtr handle = notePad.Handle; RECT windowRect = new RECT(); GetWindowRect(han
为什么我用下面的高度和宽度为0:
static void Main(string[] args) { Process notePad = new Process(); notePad.StartInfo.FileName = "notepad.exe"; notePad.Start(); IntPtr handle = notePad.Handle; RECT windowRect = new RECT(); GetWindowRect(handle,ref windowRect); int width = windowRect.Right - windowRect.Left; int height = windowRect.Bottom - windowRect.Top; Console.WriteLine("Height: " + height + ",Width: " + width); Console.ReadLine(); } 这是我对GetWindowRect的定义: [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] static extern bool GetWindowRect(IntPtr hWnd,ref RECT lpRect); 这是我对RECT的定义: [StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left; // x position of upper-left corner public int Top; // y position of upper-left corner public int Right; // x position of lower-right corner public int Bottom; // y position of lower-right corner } 谢谢大家的帮助. 解决方法
您正在将进程句柄传递给期望窗口句柄的函数GetWindowRect.当然,这失败了.您应该发送Notepad.MainWindowHandle.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |