下載:
MFC Static Library 版本 BrightControl.zip
3231542282B33385960CB6B95F6A0056
Share Library 版本 BrightControl0.32.zip
E9A45AC37C028403D23748F0D63DAAE6
如果你要自己寫一個的話,以下是參考資料及程式片段,我是用VS2008兜出來的。
SetMonitorBrightness
Dxva2.lib
// Minimum supported client Windows Vista
它應該是用 DDC 來控制螢幕的,不過這些 API 只有在 Vista 以上提供,我自己是在Windows7上使用。
#include<HighLevelMonitorConfigurationAPI.h>
int CMonConfDlg::SetMonitorBright(HWND hWnd , DWORD cBrightness)
{
HMONITOR hMonitor = NULL;
DWORD cPhysicalMonitors;
DWORD minb=0;
DWORD curb=0;
DWORD maxb=0;
LPPHYSICAL_MONITOR pPhysicalMonitors = NULL;
// Get the monitor handle.
hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY);
// Get the number of physical monitors.
BOOL bSuccess = GetNumberOfPhysicalMonitorsFromHMONITOR(
hMonitor, &cPhysicalMonitors);
if (bSuccess)
{
// Allocate the array of PHYSICAL_MONITOR structures.
pPhysicalMonitors = (LPPHYSICAL_MONITOR)malloc(
cPhysicalMonitors* sizeof(PHYSICAL_MONITOR));
if (pPhysicalMonitors != NULL)
{
// Get the array.
bSuccess = GetPhysicalMonitorsFromHMONITOR(hMonitor, cPhysicalMonitors, pPhysicalMonitors);
int n = 0;
do {
bSuccess = GetMonitorBrightness(pPhysicalMonitors->hPhysicalMonitor , &minb, &curb, &maxb);
if( !bSuccess ) {
dbg_printf("GetMonitorBrightness, n = %d, bSuccess = %d\r\r\n", n, bSuccess);
GetErrorMessage(TEXT("GetMonitorBrightness"));
Sleep(RETRY_SLEEP);
}
n++;
} while( !bSuccess && n < MAX_RETRY);
if( bSuccess ) {
if( curb != cBrightness && minb <= cBrightness && cBrightness <= maxb ) {
int n = 0;
do {
bSuccess = SetMonitorBrightness(pPhysicalMonitors->hPhysicalMonitor , cBrightness);
if( !bSuccess ) {
dbg_printf("SetMonitorBrightness, n = %d, bSuccess = %d\r\r\n", n, bSuccess);
GetErrorMessage(TEXT("SetMonitorBrightness"));
Sleep(RETRY_SLEEP);
}
n++;
} while( !bSuccess && n < MAX_RETRY);
dbg_printf("SetMonitorBrightness(%d), bSuccess = %d\r\r\n",cBrightness, bSuccess);
}
}
// Close the monitor handles.
bSuccess = DestroyPhysicalMonitors( cPhysicalMonitors, pPhysicalMonitors);
// Free the array.
free(pPhysicalMonitors);
}
}
return curb;
}
No comments:
Post a Comment