Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    System Messages & Screen Savers

    General and Desktop
    1
    1
    2303
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      Morbius last edited by

      I am trying to implement an app that can detect when a screen-saver is running, among other functions. It has some similarity to "KidLogger":http://kidlogger.net/, which is open-source, but is payware. In it, he defines a OnSysCommand() by overriding a MFC
      class:

      @void CMainWndDlg::OnSysCommand(UINT nID, LPARAM lParam)
      {
      if (nID==SC_SCREENSAVE)
      AddLOG_message( etc.
      @

      The thing about it is, when I test the freeware app and set my computer to go into a screen-saver, it catches it, even when it is not the foreground app. I have also seen attempts to do this in Qt, but they seem to never get the system messages when the detecting app is not the foreground app. I have tried:

      @bool myScreenSaverEventFilter(void * message, long * result)
      {
      MSG * msg = static_cast<MSG *>(message);

      if (msg && msg->message == WM_SYSCOMMAND) 
      {
            if (msg->wParam == SC_SCREENSAVE || msg->wParam == SC_MONITORPOWER) 
            {
                *result = 1;
      
                qDebug()<<"detected screen saver";
            }
      }
      
      return false;
      

      }
      @

      with

      @int main(int argc, char *argv[])
      {
      int res=0;

      QApplication a(argc, argv);
      
      a.setEventFilter(myScreenSaverEventFilter);
      
      etc.
      

      @

      However, this only detects the screen-saver when my app is in the foreground. Likewise, I have also tried:

      @class ScreenSaverDetectingApp : public QApplication
      {
      public:
      #ifdef _WIN32
      bool systemEventFilter(MSG *msg, long *result)
      {
      if(msg->message == WM_SYSCOMMAND)
      {
      if(msg->wParam == SC_SCREENSAVE || msg->wParam == SC_MONITORPOWER)
      {
      qDebug()<<"detected screen saver";
      *result = 0;
      }
      }

          return false;
      

      }
      #endif
      };
      @

      @int main(int argc, char *argv[])
      {
      int res=0;

      ScreenSaverDetectingApp a(argc, argv);
      
      etc.
      

      @

      Both of these only detect a screen-saver when the app is in the foreground. It seems system level messages are being filtered out before an app gets to process them, unless it is in the foreground. Why is this? Is there a work-around? This is essentially the same question as here:

      "Listening to screen saver and power save events on Windows":http://www.qtcentre.org/threads/13395-Listening-to-screen-saver-and-power-save-events-on-Windows

      It never got answered. I hope I have done more research that helps highlight the problem.

      I could use:

      @ BOOL bResult = SystemParamtersInfo(SPI_GETSCREENSAVERRUNNING, etc.@

      However, this will not work in Qt as is. One must recompile it with XP dependency, and this is the only instance in which I need it.

      It appears I will have to detect the class name of the foreground app; but that may not work for a custom screen-saver using a custom class name.

      Does anybody have a way to detect system event messages when the app is NOT in the foreground; or some other better way to detect a screen-saver?

      1 Reply Last reply Reply Quote 0
      • First post
        Last post