Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Help needed to power down monitor in a C++ service. (http://www.go4expert.com/forums/help-power-monitor-cpp-service-t18187/)

predatorsown 25Jun2009 16:12

Help needed to power down monitor in a C++ service.
 
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.

SaswatPadhi 25Jun2009 20:22

Re: Help needed to power down monitor in a C++ service.
 
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 :)

predatorsown 30Jun2009 03:14

Re: Help needed to power down monitor in a C++ service.
 
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.

predatorsown 30Jun2009 16:35

Re: Help needed to power down monitor in a C++ service.
 
Many thanks SaswatPadhi. Tried the GetDesktopWindow function and that did the job.

Thanks again

Joe.

SaswatPadhi 30Jun2009 17:59

Re: Help needed to power down monitor in a C++ service.
 
My pleasure :)


All times are GMT +5.5. The time now is 21:28.