win32-改变显示器的亮度
标签:mini names change size div err collect object etl
调用SetMonitorBrightness
代码示例:
#pragma comment(lib, "dxva2.lib")
#include
#include
#include
#include
#include
#include
#include string>
#include using namespace std;
int main()
{
HWND hWnd = GetDesktopWindow();
HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY);
cout "Monitor: " endl;
DWORD cPhysicalMonitors;
BOOL bSuccess = GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, &cPhysicalMonitors);
cout "GetNumber: " ", number of physical monitors: " endl;
LPPHYSICAL_MONITOR pPhysicalMonitors = (LPPHYSICAL_MONITOR)malloc(cPhysicalMonitors * sizeof(PHYSICAL_MONITOR));
bSuccess = GetPhysicalMonitorsFromHMONITOR(hMonitor, cPhysicalMonitors, pPhysicalMonitors);
cout "GetPhysicalMonitor: " endl
"Handle: " hPhysicalMonitor endl
"Description: ";
wcout szPhysicalMonitorDescription);
DWORD MinimumBrightness;
DWORD CurrentBrightness;
DWORD MaximumBrightness;
BOOL err = GetMonitorBrightness(pPhysicalMonitors->hPhysicalMonitor, &MinimumBrightness, &CurrentBrightness, &MaximumBrightness);
err = SetMonitorBrightness(pPhysicalMonitors->hPhysicalMonitor, 50);
int err1 = GetLastError();
DWORD MonitorCapabilities;
DWORD SupportedColorTemperatures;
err = GetMonitorCapabilities(pPhysicalMonitors->hPhysicalMonitor, &MonitorCapabilities, &SupportedColorTemperatures);
DestroyPhysicalMonitors(cPhysicalMonitors, pPhysicalMonitors);
free(pPhysicalMonitors);
}
上面代码只对台式机的显示器起作用,如果要改变笔记本电脑的显示器亮度,请改用 WmiSetBrightness
样例:
ManagementClass mclass = new ManagementClass("WmiMonitorBrightnessMethods");
mclass.Scope = new ManagementScope(@"\\.\root\wmi");
ManagementObjectCollection instances = mclass.GetInstances();
// I assume you get one instance per monitor
foreach(ManagementObject instance in instances)
{
ulong timeout = 1; // in seconds
ushort brightness = 50; // in percent
object[] args = new object[] { timeout, brightness };
instance.InvokeMethod("WmiSetBrightness", args);
}
链接: What API call would I use to change brightness of laptop (.NET)?
win32-改变显示器的亮度
标签:mini names change size div err collect object etl
原文地址:https://www.cnblogs.com/strive-sun/p/13214738.html
评论