c# – 为什么GetWindowText会挂起一个“关闭”的句柄而不是一个
发布时间:2020-12-15 21:16:51 所属栏目:百科 来源:网络整理
导读:使用以下代码 [DllImport("user32.dll",EntryPoint = "GetWindowText",ExactSpelling = false,CharSet = CharSet.Auto,SetLastError = true)] private static extern int GetWindowText(IntPtr hWnd,StringBuilder lpWindowText,int nMaxCount); public stat
使用以下代码
[DllImport("user32.dll",EntryPoint = "GetWindowText",ExactSpelling = false,CharSet = CharSet.Auto,SetLastError = true)] private static extern int GetWindowText(IntPtr hWnd,StringBuilder lpWindowText,int nMaxCount); public static String GetWindowText(IntPtr hWnd) { StringBuilder title = new StringBuilder(MAX_TITLE_LENGTH); int titleLength = WinAPI.GetWindowText(hWnd,title,title.Capacity + 1); title.Length = titleLength; return title.ToString(); } 如果将句柄传递给最近关闭的应用程序,GetWindowText将挂起(IE:永不返回). (这对我来说很奇怪,因为我原以为它会以零值返回) 传入随机句柄(如新的IntPtr(123456))成功并返回没有值. 有人可以解释一下这种行为吗? 解决方法
在这里阅读GetWindowText undercovers的描述:
The secret life of GetWindowText.
我不认为你会得到更好的一个:-)如果你真的想100%确定你不会挂起来调用它,你需要在另一个你自己管理的线程上做(如果你需要的话就杀掉) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |