webu
Full Member
Posts: 149
|
Post by webu on Mar 30, 2022 13:23:55 GMT 1
Hi all over the world,
Which operating system routine can we use with GFA to monitor the display brightness of laptops and also adjust it if necessary? Is there anything general or does it depend on the manufacturer?
|
|
|
Post by (X) on Apr 1, 2022 13:03:16 GMT 1
|
|
|
Post by (X) on Apr 1, 2022 13:04:57 GMT 1
This code may work with a few tweaks to convert to GFA...
Public Class Form1 Private Structure RAMP <System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=256)> _ Public Red As UShort() <System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=256)> _ Public Green As UShort() <System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=256)> _ Public Blue As UShort() End Structure Private Declare Function apiGetDeviceGammaRamp Lib "gdi32" Alias "GetDeviceGammaRamp" (ByVal hdc As Int32, ByRef lpv As RAMP) As Int32 Private Declare Function apiSetDeviceGammaRamp Lib "gdi32" Alias "SetDeviceGammaRamp" (ByVal hdc As Int32, ByRef lpv As RAMP) As Int32 Private Declare Function apiGetWindowDC Lib "user32" Alias "GetWindowDC" (ByVal hwnd As Int32) As Int32 Private Declare Function apiGetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Int32 Private newRamp As New RAMP() Private usrRamp As New RAMP() Private IsLoaded As Boolean
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load TrackBar1.Minimum = 1000 : TrackBar1.Maximum = 2000 'Set trackbar to valid range, since if will be half, the lower range is invalid TrackBar2.Minimum = 25 : TrackBar2.Maximum = 44 apiGetDeviceGammaRamp(apiGetWindowDC(apiGetDesktopWindow), usrRamp) IsLoaded = True End Sub
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed apiSetDeviceGammaRamp(apiGetWindowDC(apiGetDesktopWindow), usrRamp) End Sub
Private Sub TrackBar1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar1.ValueChanged If IsLoaded = False Then Exit Sub DesktopBrightnessContrast(TrackBar1.Value, 44 - TrackBar2.Value + 3) Label2.Text = "Dim 1/" & (TrackBar1.Value / 1000).ToString End Sub
Private Sub TrackBar2_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar2.ValueChanged If IsLoaded = False Then Exit Sub DesktopBrightnessContrast(TrackBar1.Value, 44 - TrackBar2.Value + 3) Label3.Text = "Contrast " & TrackBar2.Value.ToString End Sub
Private Function DesktopBrightnessContrast(ByVal bLevel As Int32, ByVal gamma As Int32) As Int32 newRamp.Red = New UShort(255) {} : newRamp.Green = New UShort(255) {} : newRamp.Blue = New UShort(255) {} For i As Int32 = 1 To 255 ' gamma is a value between 3 and 44 newRamp.Red(i) = InlineAssignHelper(newRamp.Green(i), InlineAssignHelper(newRamp.Blue(i), CUShort((Math.Min(65535, Math.Max(0, Math.Pow((i + 1) / 256.0R, gamma * 0.1) * 65535 + 0.5)))))) Next For iCtr As UShort = 0 To 255 newRamp.Red(iCtr) = CUShort(newRamp.Red(iCtr) / CDbl(bLevel / 1000)) newRamp.Green(iCtr) = CUShort(newRamp.Green(iCtr) / CDbl(bLevel / 1000)) newRamp.Blue(iCtr) = CUShort(newRamp.Blue(iCtr) / CDbl(bLevel / 1000)) Next Return apiSetDeviceGammaRamp(apiGetWindowDC(apiGetDesktopWindow), newRamp) ' Now set the value. End Function
Private Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T target = value : InlineAssignHelper = value End Function
End Class
|
|