GetMonitorBrightness http://msdn.microsoft.com/en-us/library/ms775205.aspx是如何工作的? 有人可以给我一个实际的工作实现在C#中调用此代码?
我正在尝试检索笔记本电脑支持的亮度级别。
我有以下工作代码,将亮度从1设置为〜150。 但是我正在寻找允许的input值(最小值最大值)。
static void SetBrightness(byte targetBrightness) { ManagementScope scope = new ManagementScope("root\\WMI"); SelectQuery query = new SelectQuery("WmiMonitorBrightnessMethods"); using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query)) { using (ManagementObjectCollection objectCollection = searcher.Get()) { foreach (ManagementObject mObj in objectCollection) { mObj.InvokeMethod("WmiSetBrightness", new Object[] { UInt32.MaxValue, targetBrightness }); break; } } } }
尽管使用Interop应该是可能的,但通过WMI也可以使用这个功能。 改变我原来的代码有点导致下面的代码应该工作:
ManagementScope scope; SelectQuery query; scope = new ManagementScope("root\\WMI"); query = new SelectQuery("SELECT * FROM WmiMonitorBrightness"); using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query)) { using (ManagementObjectCollection objectCollection = searcher.Get()) { foreach (ManagementObject mObj in objectCollection) { Console.WriteLine(mObj.ClassPath); foreach (var item in mObj.Properties) { Console.WriteLine(item.Name + " " +item.Value.ToString()); if(item.Name =="CurrentBrightness") //Do something with CurrentBrightness } } } }
现在我真的很好奇如何处理像“非笔记本电脑屏幕”的“特殊”情况,如果他们实施任何方式来影响亮度。
该函数具有最小值和最大值的输出:
LPDWORD pdwMinimumBrightness=NULL; LPDWORD pdwMaximumBrightness=NULL; HANDLE pmh = pPhysicalMonitors[0].hPhysicalMonitor; GetMonitorBrightness(pmh, pdwMinimumBrightness, pdwMaximumBrightness);
这是假设你想要的第一台显示器的值。