1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help needed to power down monitor in a C++ service.

Discussion in 'C++' started by predatorsown, Jun 25, 2009.

  1. predatorsown

    predatorsown New Member

    Joined:
    Mar 25, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    I recently finished a project but was then asked to make it into a service. I hit a problem in that I need to put the monitor into standby mode as part of this and odviously can't use the usual as there is no window to send a message to.

    SendMessage( hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM)2 );

    Is there a more direct way of getting the same functionallity that would work in a service and if so how? Thanks for any help given.

    Joe.
     
  2. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    If you don't have a window to SendMessage to, you can send the message to all top-level windows :
    Code:
    SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM)2 );
    or, you can also use GetDesktopWindow to send message to the desktop window.

    Hope that would be helpful :)
     
  3. predatorsown

    predatorsown New Member

    Joined:
    Mar 25, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    I've already tried the first and it doesn't compile because not only does a service have to run without its own window but also has to run without a windows messaging loop.

    I'll give the later a try tomorrow and will let you know if it works.

    Joe.
     
  4. predatorsown

    predatorsown New Member

    Joined:
    Mar 25, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Many thanks SaswatPadhi. Tried the GetDesktopWindow function and that did the job.

    Thanks again

    Joe.
     
  5. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:

Share This Page