c# – 为什么我的高度和宽度为0?

c# – 为什么我的高度和宽度为0?,第1张

概述为什么我用下面的高度宽度为0: static void Main(string[] args) { Process notePad = new Process(); notePad.StartInfo.FileName = "notepad.exe"; notePad.Start(); IntPtr handle = not 为什么我用下面的高度和宽度为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. 总结

以上是内存溢出为你收集整理的c# – 为什么我的高度和宽度为0?全部内容,希望文章能够帮你解决c# – 为什么我的高度和宽度为0?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1239607.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存