CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 5 FirstFirst 12345 LastLast
Results 16 to 30 of 73
  1. #16
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: [RESOLVED] Monitor Temperature

    It's no problem at all

    I'll have a look at it over the weekend

    Hannes

  2. #17
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: [RESOLVED] Monitor Temperature

    Hi Stin

    I am looking for external help on this issue. I know what to use and what should be done, but, for the love of me, I can't manage to get it working. perhaps I'm too stupid

    Hang in there...

    Hannes

  3. #18
    Join Date
    Oct 2005
    Posts
    158

    Re: [RESOLVED] Monitor Temperature

    I really appreciate your help. It's not urgent, and I could get by with a hard coded number.

  4. #19
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: [RESOLVED] Monitor Temperature

    This might steer someone in the right direction. Seems that it's been solved before. Looks like C++ though.

    http://www.autohotkey.com/forum/topic32034.html
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #20
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: [RESOLVED] Monitor Temperature

    That is not C code.. As far as I can tell it is a script for AutoHotKey
    Always use [code][/code] tags when posting code.

  6. #21
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: [RESOLVED] Monitor Temperature

    OK, I haven't received any response yt on any of the forums I have posted this question to

    I did try this :

    Code:
    Imports System
    
    Imports System.Runtime.InteropServices
    
    Imports System.Windows.Forms
    
    
    Public Class SetBrightness
        Inherits Form
    
    
        <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
        Private Structure RAMP
    
            <MarshalAs(UnmanagedType.ByValArray, SizeConst:=256)> _
            Public Red As UInt16()
    
    
            <MarshalAs(UnmanagedType.ByValArray, SizeConst:=256)> _
            Public Green As UInt16()
    
    
            <MarshalAs(UnmanagedType.ByValArray, SizeConst:=256)> _
            Public Blue As UInt16()
    
        End Structure
    
        <DllImport("gdi32.dll")> _
        Private Shared Function SetDeviceGammaRamp(ByVal hDC As IntPtr, ByRef lpRamp As RAMP) As Boolean
        End Function
    
        <DllImport("user32.dll")> _
        Private Shared Function GetDC(ByVal hWnd As IntPtr) As IntPtr
        End Function
    
        <DllImport("gdi32.dll")> _
        Private Shared Function GetDeviceGammaRamp(ByVal hdc As Int32, ByVal lpv As Int32) As Int32
        End Function
    
        Private WithEvents TrackBar1 As System.Windows.Forms.TrackBar
    
        Private Shared Ramp1(0 To 255, 0 To 2) As Integer
    
        Private Shared s_ramp As New RAMP()
    
        Private Shared MyRamp As New RAMP()
    
        Private Shared Sub SetGamma(ByVal gamma As Integer)
    
    
            s_ramp.Red = New UShort(255) {}
    
            s_ramp.Green = New UShort(255) {}
    
            s_ramp.Blue = New UShort(255) {}
    
    
            For i As Integer = 1 To 255
    
    
                ' gamma is a value between 3 and 44 
    
    
                s_ramp.Red(i) = InlineAssignHelper(s_ramp.Green(i), InlineAssignHelper(s_ramp.Blue(i), CUShort((Math.Min(65535, Math.Max(0, Math.Pow((i + 1) / 256.0R, gamma * 0.1) * 65535 + 0.5))))))
            Next
    
            ' Now set the value. 
    
    
            SetDeviceGammaRamp(GetDC(IntPtr.Zero), s_ramp)
        End Sub
    
        Private Shared Sub RestoreGamma(ByVal gamma As Integer)
    
            MyRamp.Red = New UShort(255) {}
    
            MyRamp.Green = New UShort(255) {}
    
            MyRamp.Blue = New UShort(255) {}
    
            For x = 0 To 255
                MyRamp.Red(x) = Ramp1(x, 0)
                MyRamp.Green(x) = Ramp1(x, 1)
                MyRamp.Blue(x) = Ramp1(x, 2)
            Next
    
            SetDeviceGammaRamp(GetDC(IntPtr.Zero), MyRamp)
        End Sub
    
        Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
            target = value
            Return value
        End Function
    
    
        Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
            SetGamma(TrackBar1.Value)
        End Sub
    
        Private Sub SetBrightness_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    
            RestoreGamma(Ramp1(0, 0))
    
        End Sub
    
        Private Sub SetBrightness_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            GetDeviceGammaRamp(GetDC(IntPtr.Zero), Ramp1(0, 0))
        End Sub
    
    
    End Class
    But it doesn't restore the screen back. either the settings doesn't get stored into my array ( which I think is the most likely explanation ), or the SetDeviceGammaRamp doesn't want to get the right values to apply. I'm feeling out of my league here....

  7. #22
    Join Date
    Oct 2005
    Posts
    158

    Re: [RESOLVED] Monitor Temperature

    Yikes. If you're out of your league...

  8. #23
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: [RESOLVED] Monitor Temperature

    I didn't originally realize how popular this question was.
    I mean the question of brightness, instead of temp.

    Since this is pretty interesting, and possibly useful to me as well, I'll take a look into it.
    I've seen alot online about it, and several programs that apparently do it.

  9. #24
    Join Date
    Oct 2005
    Posts
    158

    Re: [RESOLVED] Monitor Temperature

    Another set of eyes is always welcome.

  10. #25
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: [RESOLVED] Monitor Temperature

    got it!

    I found the vb6 version kickin around in the API-Guide.
    Made it work for the desktop with the right Device context.

    It will take a few moments to convert this to .NET, so I'll post back.
    For giggles, here is the vb6 example.
    Code:
    Option Explicit
    Private Ramp1(0 To 255, 0 To 2) As Integer
    Private Ramp2(0 To 255, 0 To 2) As Integer
    Private Declare Function apiGetDeviceGammaRamp Lib "gdi32" Alias "GetDeviceGammaRamp" (ByVal hdc As Long, ByRef lpv As Any) As Long
    Private Declare Function apiSetDeviceGammaRamp Lib "gdi32" Alias "SetDeviceGammaRamp" (ByVal hdc As Long, ByRef lpv As Any) As Long
    Private Declare Function apiCopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long) As Long
    Private Declare Function apiGetWindowDC Lib "user32" Alias "GetWindowDC" (ByVal hwnd As Long) As Long
    Private Declare Function apiGetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Long
    Private Sub Form_Load()
       Dim iCtr As Integer
       Dim lVal As Long
       Call apiGetDeviceGammaRamp(apiGetWindowDC(apiGetDesktopWindow), Ramp1(0, 0))
          For iCtr = 0 To 255
             lVal = Int2Lng(Ramp1(iCtr, 0))
             Ramp2(iCtr, 0) = Lng2Int(Int2Lng(Ramp1(iCtr, 0)) / 2)
             Ramp2(iCtr, 1) = Lng2Int(Int2Lng(Ramp1(iCtr, 1)) / 2)
             Ramp2(iCtr, 2) = Lng2Int(Int2Lng(Ramp1(iCtr, 2)) / 2)
          Next iCtr
       Call apiSetDeviceGammaRamp(apiGetWindowDC(apiGetDesktopWindow), Ramp2(0, 0))
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
       Call apiSetDeviceGammaRamp(apiGetWindowDC(apiGetDesktopWindow), Ramp1(0, 0))
    End Sub
    
    Public Function Int2Lng(IntVal As Integer) As Long
       Call apiCopyMemory(Int2Lng, IntVal, 2)
    End Function
    Public Function Lng2Int(Value As Long) As Integer
       Call apiCopyMemory(Lng2Int, Value, 2)
    End Function

  11. #26
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: [RESOLVED] Monitor Temperature

    Just when I was starting too lose all hope, the Honourable mr TT(n) pops in!

    Let us hope for the best

    Hannes

  12. #27
    Join Date
    Oct 2005
    Posts
    158

    Re: [RESOLVED] Monitor Temperature

    I just found a vb6 project too at CodeProject.com that I was starting to look at!

  13. #28
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Thumbs up Re: [RESOLVED] Monitor Temperature

    Sad to say, but VB 6 wins .NET hands down here!! Amzingly surprisingly easy in VB 6 - unbelievable!!

    Look at this. Add 2 buttons on a VB 6 form, and a checkbox. If the Checkbox is checked and command1 is clicked it dims. And when the second commandbutton is clicked, it restores everything!

    I am flabbergasted! This is one more reason why I'll probably never leave VB 6!

    Hannes
    Attached Files Attached Files

  14. #29
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: [RESOLVED] Monitor Temperature

    Here is a basic .NET example, which works to start from. {XP only, Vista/7 solution shown later in this thread}

    Code:
    Option Strict On
    Option Explicit On
    Public Class Form1
        Private Ramp1(255, 2) As Short
        Private Ramp2(255, 2) As Short
        Private Declare Function apiGetDeviceGammaRamp Lib "gdi32" Alias "GetDeviceGammaRamp" (ByVal hdc As Int32, ByRef lpv As Short) As Int32
        Private Declare Function apiSetDeviceGammaRamp Lib "gdi32" Alias "SetDeviceGammaRamp" (ByVal hdc As Int32, ByRef lpv As Short) As Int32
        Private Declare Function apiCopyMemoryIntShrt Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Int32, ByRef Source As Short, ByVal Length As Int32) As Int32
        Private Declare Function apiCopyMemoryShrtInt Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Short, ByRef Source As Int32, ByVal Length As Int32) 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 eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
            Dim iCtr As Short
            Dim lVal As Int32
            apiGetDeviceGammaRamp(apiGetWindowDC(apiGetDesktopWindow), Ramp1(0, 0))
            For iCtr = 0 To 255
                lVal = Shr2Int(Ramp1(iCtr, 0))
                Ramp2(iCtr, 0) = Int2Shr(CInt(Shr2Int(Ramp1(iCtr, 0)) / 2))
                Ramp2(iCtr, 1) = Int2Shr(CInt(Shr2Int(Ramp1(iCtr, 1)) / 2))
                Ramp2(iCtr, 2) = Int2Shr(CInt(Shr2Int(Ramp1(iCtr, 2)) / 2))
            Next
            apiSetDeviceGammaRamp(apiGetWindowDC(apiGetDesktopWindow), Ramp2(0, 0))
        End Sub
        Private Sub Form1_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
            apiSetDeviceGammaRamp(apiGetWindowDC(apiGetDesktopWindow), Ramp1(0, 0))
        End Sub
    
        Public Function Shr2Int(ByRef shrVal As Short) As Int32
            apiCopyMemoryIntShrt(Shr2Int, shrVal, 2)
        End Function
        Public Function Int2Shr(ByRef Value As Int32) As Short
            apiCopyMemoryShrtInt(Int2Shr, Value, 2)
        End Function
    End Class
    Last edited by TT(n); June 26th, 2010 at 02:35 AM. Reason: Option strict/explicit now

  15. #30
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: [RESOLVED] Monitor Temperature

    Great work TT(n)!

    I do get a red squiggly at this line though :

    Code:
    apiSetDeviceGammaRamp(apiGetWindowDC(apiGetDesktopWindow), Ramp1(0, 0))
    And it tells me that it cannot convert Short to Type RAMP

    Coincidentally, That is the error I have been battling with the whole time, before I got to the code I had in post # 21

Page 2 of 5 FirstFirst 12345 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured