如何获取活动窗口的类名?

通过使用此代码,我可以获得活动窗口的标题..

[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; 

但是我该如何获取活动窗口的类名呢?

只需要调用GetClassName()即可。 这将返回窗口的Windows类名,它与C#类没有任何关系。 无法在另一个进程中获取窗口的C#类名。 如果这是一个Winforms应用程序,请查看Managed Spy ++工具以获取可能的黑客攻击。