[RESOLVED] Monitor Brightness - Page 5
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 5 of 5 FirstFirst ... 2345
Results 61 to 73 of 73

Thread: [RESOLVED] Monitor Brightness

  1. #61
    Join Date
    Jun 2004
    Location
    NH
    Posts
    674

    Re: Monitor Temperature

    Absolutely. On xp, short works, but on Vista/7 you must pass the structure, which by default tends to be ByRef, especially if you expect information back out of it.

    EDIT:
    Moreover, that's probably why vb6 works on Vista/7 without the structure, because I don't believe it existed.
    Last edited by TT(n); June 26th, 2010 at 03:31 AM.

  2. #62
    Join Date
    Jun 2004
    Location
    NH
    Posts
    674

    Re: Monitor Temperature

    Sorry to keep this thread going on forever, but...

    I've found that the slider on lowest does not dim the whites as much as the toggle HalfDim method.
    I brought both examples into my current project, and can flip between them quickly, and they are clearly different.

    I don't know how to put a slider on that yet, so that the whole picture dims a grey, blocking out the whites. Oh well, all in good time.



    EDIT:

    AH_HA, you can use both at the same time to get the desired effect of both, slider, and dimness of the whites.


    .
    Last edited by TT(n); June 26th, 2010 at 07:24 PM. Reason: Dim slider

  3. #63
    Join Date
    Jun 2004
    Location
    NH
    Posts
    674

    Slider solution

    Okay that's it, here is a final example with both methods discussed here, combined. The range is cut in half, so values 22-44 are still valid.

    Code:
         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
    Attached Files Attached Files
    Last edited by TT(n); July 3rd, 2010 at 02:50 AM.

  4. #64
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,097

    Re: Monitor Temperature

    This thread can keep going on, I do not mind

    Good work dude!

    I did notice a great deal of flickering when changing the trackbar though. Did you get the same results?

    Oh, and I decided to change this thread's title to Monitor brighness - if you don't mind stin. I'm just trying to help people with this same issue to find this excellent thread more easily

    Hannes

  5. #65
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,097

    Re: Monitor Brightness

    And, I think it is now safe to mark the thread Resolved again..

  6. #66
    Join Date
    Jun 2004
    Location
    NH
    Posts
    674

    Re: [RESOLVED] Monitor Brightness

    Nice, the thread name matches now!

    I did get some flicker, and could not resolve it in the current state with two separate functions. I've been busy, but I might spend a little more time on it today.

    You should be able to blend them directly in the SliderGamma, but I can't really understand what you've got going on, in the InlineAssignHelper nesting.
    If you know a little more about it, then perhaps you can clear up the flicker.

    Or better yet we get the half dim method to slide too if possible.
    It really does drop the whites, while the slidergamma brightens or dims the darks. Do you agree HanneS? Stin, do you?

    If this program is to be on a boat then a dimming slider for whites is exactly what is needed.
    The good thing about SliderGamma is that it can brighten the darks, which can help keep the darks visible, when it's dimmed. So they are both great together, in the proper configuration.

    EDIT:
    So what I mean, is that having two independent adjustments, would avoid the flicker alltogether.
    Last edited by TT(n); June 30th, 2010 at 02:02 AM.

  7. #67
    Join Date
    Oct 2005
    Posts
    158

    Re: [RESOLVED] Monitor Brightness

    I'm really stoked about trying this out.

  8. #68
    Join Date
    Jun 2004
    Location
    NH
    Posts
    674

    Re: [RESOLVED] Monitor Brightness

    It was pretty simple to get rid of the flicker.
    I'm gonna try and put a slider on the HalfBright function, and I'll post it if I get it.

    I updated the code in this thread above.

    EDIT: Slider working for dimmer
    Project zip file on post #63
    Last edited by TT(n); July 3rd, 2010 at 02:53 AM. Reason: desc

  9. #69
    Join Date
    Jun 2004
    Location
    NH
    Posts
    674

    Re: [RESOLVED] Monitor Brightness

    It was also simple to put a slider on the dimmer!


    Hey guys, does this look smooth or what? Both dimmer and contrast now!
    Full example Project zip file on post #63


    EDIT: SMOOTHER dimmer now, set in thousands-th, is a double valid 1-2.
    Last edited by TT(n); July 3rd, 2010 at 02:52 AM.

  10. #70
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,097

    Re: [RESOLVED] Monitor Brightness

    Perfect! That is awesome! Great work!

  11. #71
    Join Date
    Apr 2011
    Posts
    7

    Re: [RESOLVED] Monitor Brightness

    Hi all, I have never used VB .net before, but what I wanted to do was use some of this code to control monitor backlight with my C++ program. Does the code I see uploaded above in SetMonitorBrightness.zip output a .exe that allows me to set monitor brightness? If so, I could simply call that .exe in my C++ program and use it that way, correct?

  12. #72
    Join Date
    Apr 2011
    Posts
    7

    Re: [RESOLVED] Monitor Brightness

    Also, does this solution control the LCD backlight, or just image brightness on the screen?

  13. #73
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,097

    Re: [RESOLVED] Monitor Brightness

    Hmm, it's alive again...

    Have you tried the sample, and see what it does?

    This thread is 1 year old, it is actually best to start a new thread and refer to this from your new thread....

Page 5 of 5 FirstFirst ... 2345

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center