How to check in C++ if the system is active?

前端 未结 6 1800
温柔的废话
温柔的废话 2021-02-09 10:16

I\'m writing code that need to run only when there is no human activity on the PC, like when the screensaver is running. Any suggestions on how to do this in c++ under windows?<

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-09 11:14

    check at this answer that looks similar.

    However you need to determine exactly was "inactivity" means. That modifies the scope of your question.

    Also check this code

    hdesk = OpenDesktop(TEXT("Screen-saver"),
                        0,
                        FALSE,
                        DESKTOP_READOBJECTS | DESKTOP_WRITEOBJECTS);
    if (hdesk)
    {
       EnumDesktopWindows (hdesk, (WNDENUMPROC)KillScreenSaverFunc, 0);
       CloseDesktop (hdesk);
    }
    
    // ----------------------------------------------------------------
    
    BOOL CALLBACK KillScreenSaverFunc (HWND hwnd, LPARAM lParam)
    {
       PostMessage(hwnd, WM_CLOSE, 0, 0);
       return TRUE;
    }
    

    from here.

提交回复
热议问题