-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add option to alter all monitors at once
- Loading branch information
Showing
11 changed files
with
207 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
x64\Release\Monitor.exe /set 1 55 | ||
x64\Release\Monitor.exe /set 55 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
x64\Release\Monitor.exe /set 1 80 | ||
x64\Release\Monitor.exe /set 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
x64\Release\Monitor.exe /brighter 1 | ||
x64\Release\Monitor.exe /brighter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
x64\Release\Monitor.exe /set 1 20 | ||
x64\Release\Monitor.exe /set 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
x64\Release\Monitor.exe /darker 1 | ||
x64\Release\Monitor.exe /darker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
#include "MonitorManager.h" | ||
#include <iostream> | ||
|
||
MonitorManager::MonitorManager() | ||
{ | ||
monitors = EnumerateMonitors(); | ||
} | ||
|
||
std::vector<Monitor> MonitorManager::EnumerateMonitors() | ||
{ | ||
std::vector<Monitor> monitors; | ||
EnumDisplayMonitors(NULL, NULL, MonitorEnumCallback, reinterpret_cast<LPARAM>(&monitors)); | ||
return monitors; | ||
} | ||
|
||
BOOL CALLBACK MonitorManager::MonitorEnumCallback(_In_ HMONITOR hMonitor, _In_ HDC hdcMonitor, _In_ LPRECT lprcMonitor, _In_ LPARAM dwData) | ||
{ | ||
std::vector<Monitor>* monitors = reinterpret_cast<std::vector<Monitor>*>(dwData); | ||
|
||
// Get the number of physical monitors. | ||
DWORD cPhysicalMonitors; | ||
BOOL bSuccess = GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, &cPhysicalMonitors); | ||
|
||
LPPHYSICAL_MONITOR pPhysicalMonitors = NULL; | ||
if (bSuccess) | ||
{ | ||
// Allocate the array of PHYSICAL_MONITOR structures. | ||
LPPHYSICAL_MONITOR pPhysicalMonitors = new PHYSICAL_MONITOR[cPhysicalMonitors]; | ||
|
||
if (pPhysicalMonitors != NULL) | ||
{ | ||
// Get the array. | ||
bSuccess = GetPhysicalMonitorsFromHMONITOR(hMonitor, cPhysicalMonitors, pPhysicalMonitors); | ||
|
||
// Use the monitor handles. | ||
for (unsigned int i = 0; i < cPhysicalMonitors; ++i) | ||
{ | ||
monitors->push_back(Monitor(pPhysicalMonitors[i])); | ||
} | ||
} | ||
} | ||
// Return true to continue enumeration. | ||
return TRUE; | ||
} | ||
|
||
void MonitorManager::Show() { | ||
if (monitors.empty()) { | ||
std::cout << "No monitors found." << std::endl; | ||
return; | ||
} | ||
for (int i = 0; i < monitors.size(); i++) { | ||
if (i != 0) std::cout << std::endl; | ||
std::cout << "Monitor " << i << ": " << std::endl; | ||
std::cout << "Current brightness: " << monitors[i].currentBrightness() << std::endl; | ||
std::cout << "Current contrast: " << monitors[i].currentContrast() << std::endl; | ||
} | ||
} | ||
|
||
bool MonitorManager::Set(int monitorId, int intensity) { | ||
if (monitorId >= monitors.size() || monitorId < 0) { | ||
std::cerr << "Monitor with id " << monitorId << " not found" << std::endl; | ||
return false; | ||
} | ||
bool result = true; | ||
if (!monitors[monitorId].setCurrentBrightness(intensity)) { | ||
std::cerr << "Error setting brightness for monitor " << monitorId << std::endl; | ||
result = false; | ||
} | ||
if (!monitors[monitorId].setCurrentContrast(intensity)) { | ||
std::cerr << "Error setting contrast for monitor " << monitorId << std::endl; | ||
result = false; | ||
} | ||
return result; | ||
} | ||
|
||
bool MonitorManager::BrighterOrDarker(int monitorId, bool brighter) { | ||
if (monitors.empty()) { | ||
std::cout << "No monitors found." << std::endl; | ||
return false; | ||
} | ||
if (monitorId >= monitors.size() || monitorId < 0) { | ||
std::cerr << "Monitor with id " << monitorId << " not found" << std::endl; | ||
return false; | ||
} | ||
const int currentIntensity = monitors[monitorId].currentBrightness(); | ||
const int newIntensity = brighter ? min(currentIntensity + 10, 100) : max(currentIntensity - 10, 0); | ||
|
||
bool result = true; | ||
if (!monitors[monitorId].setCurrentBrightness(newIntensity)) { | ||
std::cerr << "Error setting brightness for monitor " << monitorId << std::endl; | ||
result = false; | ||
} | ||
|
||
if (!monitors[monitorId].setCurrentContrast(newIntensity)) { | ||
std::cerr << "Error setting contrast for monitor " << monitorId << std::endl; | ||
result = false; | ||
} | ||
return result; | ||
} | ||
|
||
bool MonitorManager::SetAll(int intensity) | ||
{ | ||
if (monitors.empty()) { | ||
std::cout << "No monitors found." << std::endl; | ||
return true; | ||
} | ||
bool result = true; | ||
for (int i = 0; i < monitors.size(); i++) { | ||
result &= Set(i, intensity); | ||
} | ||
return result; | ||
} | ||
|
||
bool MonitorManager::Brighter(int monitorId) { | ||
return BrighterOrDarker(monitorId, true); | ||
} | ||
|
||
bool MonitorManager::Darker(int monitorId) { | ||
return BrighterOrDarker(monitorId, false); | ||
} | ||
|
||
bool MonitorManager::BrighterAll() { | ||
return BrighterOrDarkerAll(true); | ||
} | ||
|
||
bool MonitorManager::DarkerAll() { | ||
return BrighterOrDarkerAll(false); | ||
} | ||
|
||
bool MonitorManager::BrighterOrDarkerAll(bool brighter) { | ||
if (monitors.empty()) { | ||
std::cout << "No monitors found." << std::endl; | ||
return true; | ||
} | ||
bool result = true; | ||
for (int i = 0; i < monitors.size(); i++) { | ||
result &= BrighterOrDarker(i, brighter); | ||
} | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
|
||
#include "Monitor.h" | ||
|
||
class MonitorManager { | ||
public: | ||
MonitorManager(); | ||
void Show(); | ||
|
||
bool Set(int monitorId, int intensity); | ||
bool Brighter(int monitorId); | ||
bool Darker(int monitorId); | ||
|
||
bool SetAll(int intensity); | ||
bool BrighterAll(); | ||
bool DarkerAll(); | ||
private: | ||
std::vector<Monitor> EnumerateMonitors(); | ||
BOOL static MonitorEnumCallback(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData); | ||
bool BrighterOrDarker(int monitorId, bool brighter); | ||
bool BrighterOrDarkerAll(bool brighter); | ||
|
||
std::vector<Monitor> monitors; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.