查找 EXE 窗口是否处于活动状态

发布于 2024-09-12 06:29:28 字数 114 浏览 7 评论 0原文

当我运行我的 exe 并使其空闲时,我的一个项目有不同的要求 (即没有点击,min,max),一段时间(定时器)后它应该自动关闭。如果有人在特定时间之前单击,则计时器必须重置为同一时间段。 如何判断exe是否空闲?

I have a different requirement in one of my projects, when I run my exe and make it idle
(i.e. without click, min, max), after a period of time (timer) it should be automatically closed. If anyone clicked before the particular time, the timer must reset for the same period.
How can I find out whether the exe is idle or not?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓬勃野心 2024-09-19 06:29:28

您可能想查看 < code>Application.Idle 事件(注意:据我所知,仅适用于 WinForms 应用程序)。

如果您将它与一个计时器结合起来,只要您的应用程序收到输入,您就停止/重置计时器,这应该会给您带来您想要的东西。

You might want to take a look at the Application.Idle event (Note: Only applicable to a WinForms application, as far as I'm aware).

If you combine it with a timer that you stop/reset whenever your application receives input, that should give you pretty much what you're looking for.

穿越时光隧道 2024-09-19 06:29:28

公共类 GlobalMouseHandler : IMessageFilter

{

    public delegate void EventHandlerForActiveState();

    public event EventHandlerForActiveState onActive;

    public event EventHandlerForActiveState onStateChanged;

    private const int WM_KEYDOWN = 0x100;

    //private const int WM_HSCROLL = 0x114;

    //private const int WM_VSCROLL = 0x115;        

    private const int WM_LBUTTONDOWN = 0x201;

    private const int WM_LBUTTONUP = 0x202;

    private const int WM_RBUTTONDOWN = 0x204;

    private const int WM_RBUTTONUP = 0x205;

    //private const int WM_MBUTTONDBLCLK = 0x209;

    private const int WM_MOUSEWHEEL = 0x20A;

    private const int WM_GETMINMAXINFO = 0x024;

    public bool PreFilterMessage(ref Message m)

    {

        if (m.Msg == 275)

        {

            return false;

        }

        switch (m.Msg)

        {

            case WM_LBUTTONDOWN:

                if (onActive != null)

                    onActive();

                break;

            case WM_LBUTTONUP:

                if (onActive != null)

                    onActive();

                break;

            case WM_RBUTTONDOWN:

                if (onActive != null)

                    onActive();

                break;

            case WM_RBUTTONUP:

                if (onActive != null)

                    onActive();

                break;

            case WM_MOUSEWHEEL:

                if (onActive != null)

                    onActive();

                break;

            //case WM_ACTIVATE:

            //    if (onActive != null)

            //        onActive();

            //    break;

            case WM_KEYDOWN:

                if (onActive != null)

                    onActive();

                break;

            case WM_GETMINMAXINFO:

                if (onStateChanged != null)

                    onStateChanged();

                break;



            //case WM_HSCROLL:

            //    if (onActive != null)

            //        onActive();

            //    break;

            //case WM_VSCROLL:

            //    if (onActive != null)

            //        onActive();

            //    break;

        }

        return false;

    }

}

GlobalMouseHandler 句柄 = new GlobalMouseHandler();
handle.onActive += new GlobalMouseHandler.EventHandlerForActiveState(handle_onActive);
Application.AddMessageFilter(句柄);
我使用了这个类并完成了这个。

public class GlobalMouseHandler : IMessageFilter

{

    public delegate void EventHandlerForActiveState();

    public event EventHandlerForActiveState onActive;

    public event EventHandlerForActiveState onStateChanged;

    private const int WM_KEYDOWN = 0x100;

    //private const int WM_HSCROLL = 0x114;

    //private const int WM_VSCROLL = 0x115;        

    private const int WM_LBUTTONDOWN = 0x201;

    private const int WM_LBUTTONUP = 0x202;

    private const int WM_RBUTTONDOWN = 0x204;

    private const int WM_RBUTTONUP = 0x205;

    //private const int WM_MBUTTONDBLCLK = 0x209;

    private const int WM_MOUSEWHEEL = 0x20A;

    private const int WM_GETMINMAXINFO = 0x024;

    public bool PreFilterMessage(ref Message m)

    {

        if (m.Msg == 275)

        {

            return false;

        }

        switch (m.Msg)

        {

            case WM_LBUTTONDOWN:

                if (onActive != null)

                    onActive();

                break;

            case WM_LBUTTONUP:

                if (onActive != null)

                    onActive();

                break;

            case WM_RBUTTONDOWN:

                if (onActive != null)

                    onActive();

                break;

            case WM_RBUTTONUP:

                if (onActive != null)

                    onActive();

                break;

            case WM_MOUSEWHEEL:

                if (onActive != null)

                    onActive();

                break;

            //case WM_ACTIVATE:

            //    if (onActive != null)

            //        onActive();

            //    break;

            case WM_KEYDOWN:

                if (onActive != null)

                    onActive();

                break;

            case WM_GETMINMAXINFO:

                if (onStateChanged != null)

                    onStateChanged();

                break;



            //case WM_HSCROLL:

            //    if (onActive != null)

            //        onActive();

            //    break;

            //case WM_VSCROLL:

            //    if (onActive != null)

            //        onActive();

            //    break;

        }

        return false;

    }

}

GlobalMouseHandler handle = new GlobalMouseHandler();
handle.onActive += new GlobalMouseHandler.EventHandlerForActiveState(handle_onActive);
Application.AddMessageFilter(handle);
I used this class and done this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文