Recent

Author Topic: [CLOSED] Can't get GetMonitorBrightness to work  (Read 442 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 530
[CLOSED] Can't get GetMonitorBrightness to work
« on: April 14, 2021, 01:49:12 pm »
Hi All,

I need help. I can't get this to work

Code: Pascal  [Select][+][-]
  1.   function GetMonitorBrightness(hMonitor: HMONITOR;
  2.      pdwMinimumBrightness: PDWORD;
  3.      pdwCurrentBrightness: PDWORD;
  4.      pdwMaximumBrightness: PDWORD): boolean;
  5.      stdcall; external 'Dxva2.dll' Name 'GetMonitorBrightness';
  6.  
  7.   type
  8.      LPPHYSICAL_MONITOR = record
  9.         hPhysicalMonitor: THandle;
  10.         szPhysicalMonitorDescription: array [0..127] of widechar;
  11.      end;
  12.      PLPPHYSICAL_MONITOR = ^LPPHYSICAL_MONITOR;
  13.  
  14.      function GetPhysicalMonitorsFromHMONITOR(HMONITOR: HMONITOR;
  15.         dwPhysicalMonitorArraySize: DWORD;
  16.         pPhysicalMonitorArray: PLPPHYSICAL_MONITOR): boolean;
  17.         stdcall; external 'Dxva2.dll' Name 'GetPhysicalMonitorsFromHMONITOR';
  18.  
  19.      function GetNumberOfPhysicalMonitorsFromHMONITOR(HMONITOR: HMONITOR;
  20.         pwNumberOfPhysicalMonitors : PDWORD): boolean;
  21.         stdcall; external 'Dxva2.dll' Name 'GetNumberOfPhysicalMonitorsFromHMONITOR';
  22.  
  23.   h := Screen.Monitors[0].Handle;
  24.   DebugLn(['Monitor handle ', h]);
  25.   DebugLn('');
  26.   GetNumberOfPhysicalMonitorsFromHMONITOR(h, @NoOfPhyicalMonitors);
  27.   Debugln(['GetNumberOfPhysicalMonitorsFromHMONITOR ', SysErrorMessage(GetLastError)]);
  28.   DebugLn([NoOfPhyicalMonitors, ' monitors']);
  29.   DebugLn('');
  30.   GetPhysicalMonitorsFromHMONITOR(h, NoOfPhyicalMonitors, @pm);
  31.   Debugln(['GetPhysicalMonitorsFromHMONITOR ', SysErrorMessage(GetLastError)]);
  32.   DebugLn([pm.hPhysicalMonitor, ' ', pwidechar(@pm.szPhysicalMonitorDescription[0])]);
  33.   DebugLn('');
  34.   GetMonitorBrightness(pm.hPhysicalMonitor, @a, @b, @c);
  35.   Debugln('GetMonitorBrightness ', [SysErrorMessage(GetLastError)]);
  36.   Debugln(['Min ', a, ' Current ', b, ' Max ', c]);
  37.  
  38.  

BTW The monitor is a typical laptop LCD screen, so it has brightness capabilities.
« Last Edit: April 15, 2021, 01:12:29 pm by pcurtis »
Windows 10
Laz 2.0.10
FPC 3.2.0

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1424
  • Former Delphi 1-7, 10.2 user
Re: GetMonitorBrightness
« Reply #1 on: April 14, 2021, 02:18:28 pm »
I guess this is for Windows, but what does "I can't get this to work" mean? Error messages? What doesn't work?
Lazarus 2.1 r65061 FPC 3.3.1 r49223 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.1 r65070 FPC 3.3.1 r49223 macOS 11.2.3 aarch64 Xcode 12.4
Lazarus 2.1 r61574 FPC 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 FPC 3.2.0 Win10 Parallels VM

pcurtis

  • Hero Member
  • *****
  • Posts: 530
Re: GetMonitorBrightness
« Reply #2 on: April 14, 2021, 02:31:56 pm »
I can't get GetMonitorrightness to work
Windows 10
Laz 2.0.10
FPC 3.2.0

GetMem

  • Hero Member
  • *****
  • Posts: 4016
Re: Can't get GetMonitorBrightness to work
« Reply #3 on: April 14, 2021, 03:03:20 pm »
Did you forget your old thread https://forum.lazarus.freepascal.org/index.php/topic,48417.0.html ?
@Martin_fr example works fine(just tested).

engkin

  • Hero Member
  • *****
  • Posts: 2692
Re: Can't get GetMonitorBrightness to work
« Reply #4 on: April 14, 2021, 03:11:24 pm »
P.curtis and pcurtis are the same person?

GetMem

  • Hero Member
  • *****
  • Posts: 4016
Re: Can't get GetMonitorBrightness to work
« Reply #5 on: April 14, 2021, 03:18:02 pm »
@engkin
Quote
P.curtis and pcurtis are the same person?
Good point! I don't know. P.curtis did not log in since July 17, 2020.  The two name looks similar.

@pcurtis
If you are not P.curtis then apologies.

pcurtis

  • Hero Member
  • *****
  • Posts: 530
Re: Can't get GetMonitorBrightness to work
« Reply #6 on: April 14, 2021, 04:07:32 pm »
Yes, I'm the same person.

I know I asked previously and said that WMI works. I couldn't get fr_martins code work then or now, but now the need has arisen again + I can't get the WMI code to compile + I want to get to grips with WINAPI.

I wonder if its a driver problem (AMD Radeon R4, version 27.20.12029.1000 )
« Last Edit: April 14, 2021, 04:51:47 pm by pcurtis »
Windows 10
Laz 2.0.10
FPC 3.2.0

pcurtis

  • Hero Member
  • *****
  • Posts: 530
Re: Can't get GetMonitorBrightness to work
« Reply #7 on: April 15, 2021, 01:11:16 pm »
I believe the API is for external monitors.
So back to WMI.
Windows 10
Laz 2.0.10
FPC 3.2.0

 

TinyPortal © 2005-2018