如何获得活动窗口的类名? [英] How do I get the classname of the active window?

查看:74
本文介绍了如何获得活动窗口的类名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

By using this code I can get the title of the active window..

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

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

But how should I do to get the classname of the active window?

推荐答案

只需pinvoke GetClassName().这将返回窗口的 Windows 类名称,它与C#类无关.无法在另一个进程中获取窗口的C#类名.查看托管Spy ++工具,如果这是一个Winforms应用.

Simply pinvoke GetClassName(). This returns the Windows class name for a window, it doesn't have anything to do with a C# class. Getting the C# class name for a window in another process is not possible. Take a look at the Managed Spy++ tool for possible hacks if this is a Winforms app.

这篇关于如何获得活动窗口的类名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆