
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. 总结以上是内存溢出为你收集整理的c# – 为什么我的高度和宽度为0?全部内容,希望文章能够帮你解决c# – 为什么我的高度和宽度为0?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)