为什么我用下面的高度和宽度为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 }
谢谢大家的帮助.
解决方法
原文地址:https://www.jb51.cc/csharp/97706.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。