通过使用此代码,我可以获得活动窗口的标题..
[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;
IntPtr handle = IntPtr.Zero;
StringBuilder Buff = new StringBuilder(nChars);
handle = GetForegroundWindow();
if (GetWindowText(handle, Buff, nChars) > 0)
{
return Buff.ToString();
}
return null;
但是我该如何获取活动窗口的类名呢?
答案 0 :(得分:4)
简单地对GetClassName()进行pinvoke。这将返回窗口的 Windows 类名,它与C#类没有任何关系。无法在另一个进程中获取窗口的C#类名。如果这是一个Winforms应用程序,请查看Managed Spy++ tool可能的黑客攻击。