如何使用c#识别Windows中用户使用的最后一个UI屏幕? [英] How to identify the Last UI screen used by user in windows using c#?

查看:87
本文介绍了如何使用c#识别Windows中用户使用的最后一个UI屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何识别Windows系统中用户当前使用的UI窗口(屏幕)?我可以使用csrss.exe吗?如果可以,怎么办?还是有另一种方法?

How can i identify the UI window(Screen) that was currently used by user in the windows system? Can i use csrss.exe for that? If so how? Or is there another way?

推荐答案

没有关于您要实现的目标的更多详细信息,很难提出特定的解决方案.

您可以使用user32.dll调用来获取活动窗口和
存放以备后用.

这是一个示例应用程序,它每10秒检查一次当前窗口并将其句柄和标题打印到控制台:

Without more details about what you''re trying to achieve it''s difficult to come up with a specific solution.

You can use user32.dll calls to get the active window and
store that for later use.

Here''s an example application that checks the current window every 10 seconds and prints it''s handle and title to the console:

public class MainClass
{
    [DllImport("user32.dll")]
    private static extern int GetWindowText(IntPtr hWnd, 
                                            StringBuilder text, 
                                            int count);
    [DllImport("user32.dll")]
    private static extern IntPtr GetForegroundWindow();
    public static void Main()
    {
        for(int i = 0; i < 10; ++i)
        {
            IntPtr windowHandle = GetForegroundWindow();
            StringBuilder titleBuffer = new StringBuilder(1024);
            if (GetWindowText(windowHandle, titleBuffer, titleBuffer.Capacity) > 0)
            {
                Console.WriteLine(titleBuffer.ToString());
                Console.WriteLine(windowHandle.ToString());
            }
            Thread.Sleep(1000);
        }
    }
}



希望这会有所帮助,
弗雷德里克(Fredrik)



Hope this helps,
Fredrik


在这个论坛中搜索,其他人问了同样的问题(昨天,我想是这样).

两个人在这么短的时间内问同一个问题有多奇怪.不会做作业吗? :-D
Search in this forum, someone else asked the same question (yesterday, I think) which was answered.

How odd that two people should ask the same question in such a short space of time. Wouldn''t be an assignment, would it? :-D


这篇关于如何使用c#识别Windows中用户使用的最后一个UI屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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