0

I'm looking for a way to programmatically power off multiple monitors.

Note: This doesn't mean power off ALL monitors.

The languages I'm currently able to compile in with my current enviorment is python/C/C++. I am aware of the easy C++ way of.

SendMessage(GetConsoleWindow(), WM_SYSCOMMAND, SC_MONITORPOWER, 2);

However this powers off all the monitors the system has on, which isn't the result I'm after.

Let's say I have a Window with the name "Application Window", now I want to power off all of the monitors that does not have this app window open.

Note: Ideally it'd be implemented with python, however not needed.

Edit: Found this, however I'm unable to recreate it and have the desired functionality.

Cpp how to turn off specific monitor?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • It wouldn't surprise me if you're not able to turn off individual monitors except by disabling the monitor. The power management software in Windows wouldn't need to do that. Either all monitors are in power saving mode (turned off) or they're all not. – Ross Ridge Jun 04 '17 at 19:01
  • @RossRidge If i were to disable the monitor, would it the applications opened on that monitor be moved over to another monitor or would they persist on that monitor/pixel location? –  Jun 04 '17 at 19:05
  • If you a disable a monitor Windows will move any windows on that monitor to another enabled monitor. – Ross Ridge Jun 04 '17 at 19:09
  • @RossRidge Mhm you think something like making the display(s) display a pure black screen saver might do the trick? –  Jun 04 '17 at 19:17
  • It looks like the answer you linked suggesting using `SetVCPFeature` should do the trick, but I can't get it to work either. GetPhysicalMonitorsFromHMONITOR just returns NULL handles for me. – Ross Ridge Jun 04 '17 at 20:01

1 Answers1

-2

Using ctypes you can access the winapi functions you mentioned:

import ctypes

WM_SYSCOMMAND = 0x0112
SC_MONITORPOWER = 0xF170

window = ctypes.windll.kernel32.GetConsoleWindow()

ctypes.windll.user32.SendMessageA(window, WM_SYSCOMMAND, SC_MONITORPOWER, 2);

The msdn documentation:

You should use GetDesktopWindow:

window = ctypes.windll.kernel32.GetDesktopWindow()
Szabolcs Dombi
  • 5,493
  • 3
  • 39
  • 71