有人会在Windows系统中使用 vc ++ 指导我如何获得亮度变化事件吗? 或者我需要在它改变时获得亮度滑块值。 任何帮助将非常感激。
提前致谢。
答案 0 :(得分:0)
迟到的答案,但因为我一直在寻找同样的事情。虽然控制亮度确实不是Windows任务,但有时也是驱动程序的任务,也可能直接与ACPI调用相关,但我们仍然可以通过实现WMI事件从Windows获取有关其更改的一些信息。特别是,您需要实现WmiMonitorBrightnessEvent,它将在Windows收到亮度变化事件时为您提供所需的信息。下面的示例代码是在@RRUZ answer here中直接转换为C#代码的C ++ / CLI,在那里他使用了WmiMonitorBrightnessEvent。
<强> EventWatcherAsync.h 强>
#pragma once
using namespace System;
using namespace System::Management;
ref class EventWatcherAsync
{
public:
void WmiEventHandler(Object^ sender, EventArrivedEventArgs^ e);
EventWatcherAsync();
};
<强> EventWatcherAsync.cpp 强>
#include "stdafx.h"
#include "EventWatcherAsync.h"
void EventWatcherAsync::WmiEventHandler(Object^ sender, EventArrivedEventArgs^ e)
{
Console::WriteLine("Active : " + e->NewEvent->Properties["Active"]->Value->ToString());
Console::WriteLine("Brightness : " + e->NewEvent->Properties["Brightness"]->Value->ToString());
Console::WriteLine("InstanceName : " + e->NewEvent->Properties["InstanceName"]->Value->ToString());
}
EventWatcherAsync::EventWatcherAsync()
{
try
{
System::String^ ComputerName = "localhost";
System::String^ WmiQuery;
ManagementEventWatcher^ Watcher;
ManagementScope^ Scope;
if (ComputerName != "localhost")
{
ConnectionOptions^ Conn = gcnew ConnectionOptions();
Conn->Username = "";
Conn->Password = "";
Conn->Authority = "ntlmdomain:DOMAIN";
Scope = gcnew ManagementScope(String::Format("\\\\{0}\\root\\WMI", ComputerName), Conn);
}
else
Scope = gcnew ManagementScope(String::Format("\\\\{0}\\root\\WMI", ComputerName));
Scope->Connect();
WmiQuery = "Select * From WmiMonitorBrightnessEvent";
Watcher = gcnew ManagementEventWatcher(Scope, gcnew EventQuery(WmiQuery));
Watcher->EventArrived += gcnew EventArrivedEventHandler(this, &EventWatcherAsync::WmiEventHandler);
Watcher->Start();
Console::Read();
Watcher->Stop();
}
catch (Exception^ e)
{
Console::WriteLine("Exception {0} Trace {1}", e->Message, e->StackTrace);
}
}
<强> Main.cpp的强>
#include "stdafx.h"
#include "EventWatcherAsync.h"
using namespace System;
int main(array<System::String ^> ^args)
{
Console::WriteLine("Listening {0}", "WmiMonitorBrightnessEvent");
Console::WriteLine("Press Enter to exit");
EventWatcherAsync^ eventWatcher = gcnew EventWatcherAsync();
Console::Read();
return 0;
}