fire event if screensaver starts

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sanjana

    fire event if screensaver starts

    hi i want to fire an event if the screen saver starts up
    i have done it using a timer tick event where i have used the api
    function to detect if screensaver has started..but this means
    continuous polling at each timer click..

    private void tick(object sender, System.EventArg s e)
    {
    const int SPI_GETSCREENSA VERRUNNING = 114;
    int screenSaverRunn ing = -1;
    // is the screen saver running?

    int ok = SystemParameter sInfo(SPI_GETSC REENSAVERRUNNIN G, 0, ref
    screenSaverRunn ing, 0);

    if (ok == 0)
    {
    Console.WriteLi ne("Call to SystemParameter sInfo failed.");

    }
    if (screenSaverRun ning != 0)
    {
    // screen saver is running
    MessageBox.Show ("screensave r runs");

    }
    else
    {
    }
    }





    is there a better way of doing something like no use of timer..
    i want someting like-- if screensaver starts then a event gets fired
    and if screen saver stops another event gets fired..this wud avoid
    getting in the loop of timer tick event..
    So my question is "is it possible to just fire events if screen saver
    starts or stops without using timer ??"

  • Larry Lard

    #2
    Re: fire event if screensaver starts


    sanjana wrote:[color=blue]
    > hi i want to fire an event if the screen saver starts up[/color]

    There doesn't seem to be a Framework way of dealing with this, which
    means you're going to have to do it the old-fashioned way.

    Note that there isn't normally a global message sent when the
    screensaver starts - only the active top level window gets a
    WM_SYSCOMMAND message, with wParam set to SC_SCREENSAVE. So to be
    notified of screensaver startup whether you are the active top level
    window or not, you need to create a hook that catches that message then
    sends a broadcast message of your own to all top level windows.

    The full info is here in this Ask Dr GUI #48 article from way back:

    <http://msdn.microsoft. com/library/default.asp?url =/archive/en-us/dnaraskdr/html/drgui48.asp>

    The other alternative, as you have found, is to poll
    SystemParameter sInfo.

    --
    Larry Lard
    Replies to group please

    Comment

    • Ignacio Machin \( .NET/ C# MVP \)

      #3
      Re: fire event if screensaver starts

      Hi,



      There you will find a demo, it's in german or something like that, but the
      code is easy to understand :)

      I never used it though.


      cheers,

      --
      Ignacio Machin,
      ignacio.machin AT dot.state.fl.us
      Florida Department Of Transportation



      "sanjana" <sudnya@gmail.c om> wrote in message
      news:1123061947 .230973.80570@g 14g2000cwa.goog legroups.com...[color=blue]
      > hi i want to fire an event if the screen saver starts up
      > i have done it using a timer tick event where i have used the api
      > function to detect if screensaver has started..but this means
      > continuous polling at each timer click..
      >
      > private void tick(object sender, System.EventArg s e)
      > {
      > const int SPI_GETSCREENSA VERRUNNING = 114;
      > int screenSaverRunn ing = -1;
      > // is the screen saver running?
      >
      > int ok = SystemParameter sInfo(SPI_GETSC REENSAVERRUNNIN G, 0, ref
      > screenSaverRunn ing, 0);
      >
      > if (ok == 0)
      > {
      > Console.WriteLi ne("Call to SystemParameter sInfo failed.");
      >
      > }
      > if (screenSaverRun ning != 0)
      > {
      > // screen saver is running
      > MessageBox.Show ("screensave r runs");
      >
      > }
      > else
      > {
      > }
      > }
      >
      >
      >
      >
      >
      > is there a better way of doing something like no use of timer..
      > i want someting like-- if screensaver starts then a event gets fired
      > and if screen saver stops another event gets fired..this wud avoid
      > getting in the loop of timer tick event..
      > So my question is "is it possible to just fire events if screen saver
      > starts or stops without using timer ??"
      >[/color]


      Comment

      • sanjana

        #4
        Re: fire event if screensaver starts

        hi there
        thanx a lot ..it worked:)


        Ignacio Machin ( .NET/ C# MVP ) wrote:[color=blue]
        > Hi,
        >
        > http://dotnet.mvps.org/dotnet/samples/operatingsystem/
        >
        > There you will find a demo, it's in german or something like that, but the
        > code is easy to understand :)
        >
        > I never used it though.
        >
        >
        > cheers,
        >
        > --
        > Ignacio Machin,
        > ignacio.machin AT dot.state.fl.us
        > Florida Department Of Transportation
        >
        >
        >
        > "sanjana" <sudnya@gmail.c om> wrote in message
        > news:1123061947 .230973.80570@g 14g2000cwa.goog legroups.com...[color=green]
        > > hi i want to fire an event if the screen saver starts up
        > > i have done it using a timer tick event where i have used the api
        > > function to detect if screensaver has started..but this means
        > > continuous polling at each timer click..
        > >
        > > private void tick(object sender, System.EventArg s e)
        > > {
        > > const int SPI_GETSCREENSA VERRUNNING = 114;
        > > int screenSaverRunn ing = -1;
        > > // is the screen saver running?
        > >
        > > int ok = SystemParameter sInfo(SPI_GETSC REENSAVERRUNNIN G, 0, ref
        > > screenSaverRunn ing, 0);
        > >
        > > if (ok == 0)
        > > {
        > > Console.WriteLi ne("Call to SystemParameter sInfo failed.");
        > >
        > > }
        > > if (screenSaverRun ning != 0)
        > > {
        > > // screen saver is running
        > > MessageBox.Show ("screensave r runs");
        > >
        > > }
        > > else
        > > {
        > > }
        > > }
        > >
        > >
        > >
        > >
        > >
        > > is there a better way of doing something like no use of timer..
        > > i want someting like-- if screensaver starts then a event gets fired
        > > and if screen saver stops another event gets fired..this wud avoid
        > > getting in the loop of timer tick event..
        > > So my question is "is it possible to just fire events if screen saver
        > > starts or stops without using timer ??"
        > >[/color][/color]

        Comment

        Working...