Okay, just when you thought this thread was safe. lol
So I brought in the structure in to my example, so that it would work on Vista/7. Great it works! both examples do.
I did however notice a difference in the look between the two dimmings.
Here is an updated example, that toggle dims, without a slider.
It looks more like a laptop on battery power(the whites are dimmer!), but without the ability to adjust.
Code:
Private usrRamp As New RAMP
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 Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
apiGetDeviceGammaRamp(apiGetWindowDC(apiGetDesktopWindow), usrRamp)
End Sub
Private Sub Form1_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
apiSetDeviceGammaRamp(apiGetWindowDC(apiGetDesktopWindow), usrRamp)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
HalfBright()
End Sub
Private Function HalfBright() As Int32
Dim rmp As New RAMP
apiGetDeviceGammaRamp(apiGetWindowDC(apiGetDesktopWindow), rmp)
For iCtr As UShort = 0 To 255
rmp.Red(iCtr) = CUShort(rmp.Red(iCtr) / 2)
rmp.Green(iCtr) = CUShort(rmp.Green(iCtr) / 2)
rmp.Blue(iCtr) = CUShort(rmp.Blue(iCtr) / 2)
Next
Return apiSetDeviceGammaRamp(apiGetWindowDC(apiGetDesktopWindow), rmp)
End Function