在此处查看有关如何使用完整源代码执行此 *** 作的示例:
http://www.csharphelp.com/2006/08/get-current-window-handle-and-caption-with-
windows-api-in-c/
[Dllimport("user32.dll")]static extern IntPtr GetForegroundWindow();[Dllimport("user32.dll")]static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);private string GetActiveWindowTitle(){ const int nChars = 256; StringBuilder Buff = new StringBuilder(nChars); IntPtr handle = GetForegroundWindow(); if (GetWindowText(handle, Buff, nChars) > 0) { return Buff.ToString(); } return null;}
*使用@Doug McClean注释进行 *编辑, 以获得更好的正确性。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)