From: Deepika on

Hi,
I have to achieve a samll functionality.
I want to turn off the monitor and irrespective of the inputs from keyboard
and mouse, it should not turn on.
I am trying this code on Windows 7.
Following is the code.

HMODULE hUser32=LoadLibrary("USER32");
if(hUser32 == NULL)
return 0;
pbi = (pBlockInput)GetProcAddress( hUser32, "BlockInput");
Sleep(500); // Eliminate user's interaction for 500 ms
BOOL blocked = (*pbi)(TRUE);
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 2);
Sleep(10000);
// Turn on monitor
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) -1);
(*pbi)(FALSE);

using the above code, the monitor is turning off but if we press anykey on
the keyboard, the monitor is turning on but keyboard and mouse will continue
to be disabled till the sleep time.
I do not understand that if keyboard is disabled, then why the monitor is
turning on on a key event.
i am running the exe as administrator.
Any help will be too much useful
From: Leo Davidson on
On Feb 19, 11:17 am, Deepika <Deep...(a)discussions.microsoft.com>
wrote:
> SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 2);


This probably won't solve your keyboard problem but you shouldn't be
sending those messages to HWND_BROADCAST as it can cause problems. (A
lot of sample code on the net does this, and it usually works okay,
but it can go wrong.) Raymond Chen wrote about it here:

https://blogs.msdn.com/oldnewthing/archive/2006/06/13/629451.aspx

Instead, the correct thing to do is create your own window and send
the message to it directly. The OS will take care of the rest.

Source to a small C++ program which does that is here, in case it
helps:

http://www.pretentiousname.com/miscsoft/index.html#ScreenSave
From: Deepika on
thanks for the reply.
i checked the samples but my requirement is a bit different.
I want to turn off the monitor and then irrespective of the inputs from
keyboard and mouse, it should not turn ON. only after a prescribed delay, it
should turned on.

In the sample, the monitor turns on with the keyborad and mouse events

I have checked all the forums and googled for over two weeks but i am not
getting any solution to my requirement.

But this is possible since i have seen this implemented in a software.
but i do not know how to implement it in C++/Win32.
Any suggestions will be helpful



"Leo Davidson" wrote:

> On Feb 19, 11:17 am, Deepika <Deep...(a)discussions.microsoft.com>
> wrote:
> > SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 2);
>
>
> This probably won't solve your keyboard problem but you shouldn't be
> sending those messages to HWND_BROADCAST as it can cause problems. (A
> lot of sample code on the net does this, and it usually works okay,
> but it can go wrong.) Raymond Chen wrote about it here:
>
> https://blogs.msdn.com/oldnewthing/archive/2006/06/13/629451.aspx
>
> Instead, the correct thing to do is create your own window and send
> the message to it directly. The OS will take care of the rest.
>
> Source to a small C++ program which does that is here, in case it
> helps:
>
> http://www.pretentiousname.com/miscsoft/index.html#ScreenSave
> .
>