Turn off the display on remote PC
I'm fixing some bugs in the application for remote control (remote desktop-like) for Windows. And there is a feature that you can blank screen on remote machine - all the programms keep running unaffected, but the person who looks into the display on remote PC sees nothing but black screen.
It is implemented by sending IoCtl request IOCTL_VIDEO_SET_OUTPUT_DEVICE_POWER_STATE
, which is undocumented. And this request does not开发者_如何学编程 work on Vista and above.
Are there another ways to do what I want?
In fact, SendMessage(-1,WM_SOMMAND,SC_MONITORPOWER,2)
does the trick, but screen turns back on if someone toches keyboard/mouse.
You should be able to send a WM_SYSCOMMAND with the SC_MONITORPOWER set to 2. Unfortunately, I am not at a computer with testing abilities, so I haven't tried it out.
I believe that whenever you touch mouse/keyboard, windows tries to wake up again, but you should be able to trap those messages and resend the 2.
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){
switch (msg){
...
case WM_SYSCOMMAND:
switch (wParam){
case SC_MONITORPOWER:
return 2;
}
break;
...
}
}
Please note that this is not tested.
You could try a low level keyboard and mouse hook (which a remote desktop app should already have). Make sure it is low level i.e. SetWindowsHookEx(WH_KEYBOARD_LL) and SetWindowsHookEx(WH_MOUSE_LL).
Inside your hook callback functions:
- DO NOT CALL CallNextHookEx()
- return -1 in LowLevelKeyboardProc (which you must implement). Do the same thing for LowLevelMouseProc.
WARNING: This WILL disable the keyboard (even if it doesn't work properly) until your code does call CallNextHookEx() and returns 0 in your callback procedures.
精彩评论