winapi改变亮度 [英] winapi change brightness

查看:1371
本文介绍了winapi改变亮度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么winapi可以改变屏幕的亮度?

What winapi's are there to change the screen's brightness?

我一直在尝试寻找一个可用于Delphi的示例或API,但没有找到任何内容。

I've been attempting to look for an example or API I can use for Delphi but have not found anything.

推荐答案

从Windows Vista开始,您可以使用 GetMonitorBrightness SetMonitorBrightness 功能。

Starting with Windows Vista you can use the GetMonitorBrightness and SetMonitorBrightness functions.

function GetMonitorBrightness(
  hMonitor : THandle;
  var   pdwMinimumBrightness : DWORD;
  var   pdwCurrentBrightness : DWORD;
  var   pdwMaximumBrightness : DWORD
) : BOOL; stdcall ; external 'Dxva2.dll' name 'GetMonitorBrightness';


function SetMonitorBrightness(
  hMonitor : THandle;
  dwNewBrightness : DWORD
): BOOL; stdcall ; external 'Dxva2.dll' name 'SetMonitorBrightness';

另一个选项是使用 WmiSetBrightness 方法 WmiMonitorBrightnessMethods WMI

Another option is use the WmiSetBrightness method of the WmiMonitorBrightnessMethods WMI Class.

{$APPTYPE CONSOLE}

uses
  SysUtils,
  ActiveX,
  Variants,
  ComObj;

procedure  SetBrightness(Timeout : Integer; Brightness : Byte);
var
  FSWbemLocator : OLEVariant;
  FWMIService   : OLEVariant;
  FWbemObjectSet: OLEVariant;
  FWbemObject   : OLEVariant;
  oEnum         : IEnumvariant;
  iValue        : LongWord;
begin;
  FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  FWMIService   := FSWbemLocator.ConnectServer('localhost', 'root\WMI', '', '');
  FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM WmiMonitorBrightnessMethods Where Active=True','WQL',$00000020);
  oEnum         := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
  while oEnum.Next(1, FWbemObject, iValue) = 0 do
  begin
    FWbemObject.WmiSetBrightness(Timeout, Brightness);
    FWbemObject:=Unassigned;
  end;
end;


begin
 try
    CoInitialize(nil);
    try
      SetBrightness(5, 100);
    finally
      CoUninitialize;
    end;
 except
    on E:EOleException do
        Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
    on E:Exception do
        Writeln(E.Classname, ':', E.Message);
 end;
 Writeln('Press Enter to exit');
 Readln;
end.

注意:如果 GetMonitorCapabilities 函数返回MC_CAPS_BRIGHTNESS标志。

Note: These functions are supported if the GetMonitorCapabilities function returns the MC_CAPS_BRIGHTNESS flag.

这篇关于winapi改变亮度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆