Announcement

Collapse
No announcement yet.

Current Display Frequency in Hertz?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Current Display Frequency in Hertz?

    Can anyone please tell me how to *GET* the CURRENT value of the screen display frequency in Hertz?

    TIA

    William Fletcher

    [This message has been edited by William Fletcher (edited April 17, 2000).]

  • #2
    EnumDisplaySettings function sets values for the following five DEVMODE members:

    dmBitsPerPel
    dmPelsWidth
    dmPelsHeight
    dmDisplayFlags
    dmDisplayFrequency !!!!

    Search on Source code by EnumDisplaySettings.
    Sure it were samples some monthes ago.

    ------------------

    Comment


    • #3
      As I can surmise, EnumDisplaySettings allows you to 'enumerate' the values of ALL *available* display settings. What I need, is to specify (discover) what values are *currently* in use - specifically the Display Frequency in Hertz in use without disturbing the display or resetting it.

      A global search on EnumDisplaySettings came up with only 3 matches, this being one. The other two don't shed light on what I'm seeking. They simply show how to retrieve values via a EnumDisplaySettings index -or- SET a display via an EnumDisplaySettings index which, of course, in turn returns all the data I need - but after-the-fact, so to speak. I need to know it *without* disturbing the current display settings at all.

      Am I wrong?

      ------------------




      [This message has been edited by William Fletcher (edited April 17, 2000).]

      Comment


      • #4
        EnumDisplaySettings with index 0 (seems to) give the current settings. Or so it would seem - I'm getting conflicting results here, though.

        The following code:
        Code:
          hdc  = CreateIC (szDevice, BYVAL %NULL, BYVAL %NULL, BYVAL %NULL)
          BitsPerPixel = GetDeviceCaps(hdc, %BITSPIXEL)
          CALL DeleteDC(hdc)
        gives the current BitsPerPixel parameter. I 'don't see any animal like '%DISPLAYFREQ' in the Win32Api.inc, though, for this function. This was another one of my (apparently failed) attempts to find the current Freq in Hz.

        ------------------


        [This message has been edited by William Fletcher (edited April 17, 2000).]

        Comment


        • #5
          William --
          I was wrong. In my program I knew frequency, because user selected a variant from available in EnumDisplaySettings.
          I am afraid that it's necessary to search in registry.

          I tested Windows98-registry.
          YES - I see
          parameter RefreshRate in
          HKEY_LOCAL_MACHINE\Config\0001\Display\Settings
          (all others are also here).
          0001 is hardware profile (??)
          But if selected "by adapter", there is no such parameter.

          Under NT (Win2000) -
          it looks that name of key is hardware-dependent and to take it is not such easy like in Windows98.
          I found that on my PC Windows changes a parameter DefaultSettings.VRefresh in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Hardware Profiles\
          0001\System\CurrentControlSet\SERVICES\NV4 (chipset)...



          [This message has been edited by Semen Matusovski (edited April 18, 2000).]

          Comment


          • #6
            to answer my own question - here's some code that appears to find the refresh rate on *any* nt machine (it really runs):

            <font face="courier new, courier" size="3"><pre>
            #dim all
            #compile exe
            #option version4
            #include "win32api.inc"

            ' using "getregistryvalue" function by ron pierce:
            '

            %error_success = 0&
            $registryerrormessage = "something went wrong ..."
            $pgmname = "gethz.exe"

            global gregistry_error_code as long
            '-------------------------------------------------------------------------------

            '-------------------------------------------------------------------------------
            sub buildhivetable ()

            dim hivename(%hkey_classes_root:%hkey_dynamic_data) as global string

            hivename(%hkey_classes_root) = "hkey_classes_root"
            hivename(%hkey_current_user) = "hkey_current_user"
            hivename(%hkey_local_machine) = "hkey_local_machine"
            hivename(%hkey_users) = "hkey_users"
            hivename(%hkey_performance_data) = "hkey_performance_data"
            hivename(%hkey_current_config) = "hkey_current_config"
            hivename(%hkey_dyn_data) = "hkey_dyn_data"
            hivename(%hkey_dynamic_data) = "hkey_dynamic_data"

            end sub 'buildhivetable
            '-------------------------------------------------------------------------------

            '-------------------------------------------------------------------------------
            'function by ron pierce
            '
            function getregistryvalue(lnghivename as long, _
            strkeyname as asciiz, _
            strsubkeyname as asciiz, _
            strdefaultvalue as string) as string
            local lngregsettings as long
            local lngkeyhandle as long
            local lngregstatus as long
            local strregvalue as asciiz * 256
            local lngregvaluelen as long
            local samdesiredval as long
            local lpclassstr as asciiz * 15
            samdesiredval = 0
            lngkeyhandle = 0
            lpclassstr = "registryclass"
            getregistryvalue = strdefaultvalue
            lngregsettings = regcreatekeyex(lnghivename, _
            strkeyname, _
            0&, _
            lpclassstr, _
            %reg_option_non_volatile, _
            %key_all_access, _
            byval samdesiredval, _
            lngkeyhandle, _
            lngregstatus)
            if lngregsettings = %error_success then
            strregvalue = string$(256, " ")
            lngregvaluelen = 256
            if regqueryvalueex(lngkeyhandle, _
            strsubkeyname, _
            0&, _
            %reg_sz, _
            strregvalue, _
            lngregvaluelen) <> %error_success then
            strregvalue = strdefaultvalue
            lngregvaluelen = len(strregvalue) + 1 'add one to allow for the null
            if regsetvalueex(lngkeyhandle, _
            strsubkeyname, _
            0&, _
            %reg_sz, _
            strregvalue, _
            lngregvaluelen) <> %error_success then
            beep
            end if
            end if
            getregistryvalue = left$(strregvalue, lngregvaluelen - 1)
            if regclosekey(lngkeyhandle) <> %error_success then
            beep
            end if
            else
            gregistry_error_code = lngregsettings
            beep
            end if
            end function
            '-------------------------------------------------------------------------------

            '-------------------------------------------------------------------------------
            function pbmain () as long

            local x as string
            local i as long
            local j as long
            local lhive as long
            local szkeyname as asciiz * 256
            local szsubkeyname as asciiz * 256

            x = mid$(environ$("windir"),4)
            if x <> "winnt" then
            msgbox "run this under windowsnt only",%mb_iconwarning,$pgmname
            exit function
            end if

            call buildhivetable()

            'find the name of the video device in use:
            lhive = %hkey_local_machine
            szkeyname = "hardware\devicemap\video"
            szsubkeyname = "\device\video0"

            x = getregistryvalue(lhive,szkeyname,szsubkeyname,$registryerrormessage)

            if x = $registryerrormessage then
            msgbox x,%mb_iconerror,"error code:" & str$(gregistry_error_code)
            exit function
            else
            msgbox hivename(lhive) & "\" & szkeyname & "\" & $crlf & $crlf & _
            szsubkeyname & $crlf & $crlf & _
            x,%mb_iconinformation,"registry entry for current video device:"
            end if

            j = instr(-1,x,"\") 'find the last backslash
            i = instr(j - 2 - len(x),x,"\") 'find the next backslash to the left
            x = mid$(x,i+1,j-i-1) 'extract the video device name

            msgbox x,%mb_iconinformation,"video device name:"

            lhive = %hkey_local_machine
            szkeyname = "system\currentcontrolset\hardware profiles\current\system\currentcontrolset\services\" & x & "\device0"
            szsubkeyname = "defaultsettings.vrefresh"

            x = getregistryvalue(lhive,szkeyname,szsubkeyname,$registryerrormessage)

            if x = $registryerrormessage then
            msgbox x,%mb_iconerror,"error code:" & str$(gregistry_error_code)
            exit function
            else
            msgbox hivename(lhive) & "\" & szkeyname & "\" & $crlf & $crlf & _
            szsubkeyname & $crlf & $crlf & _
            trim$(str$(asc(x))) & " hertz",%mb_iconinformation,"video refresh rate setting:"
            end if

            end function 'pbmain
            '-------------------------------------------------------------------------------

            '-------------------------------------------------------------------------------
            [/CODE]
            note: registry access function "getregistryvalue" c/o ron pierce in source code" forum:



            ------------------

            Comment


            • #7
              I reread MSDN again.

              BOOL EnumDisplaySettings(LPCTSTR lpszDeviceName, DWORD iModeNum, LPDEVMODE lpDevMode

              iModeNum
              Indicates the type of information to retrieve. This value can be a graphics mode index or one of the following values. Value Meaning
              ENUM_CURRENT_SETTINGS Retrieve the current settings for the display device.
              ENUM_REGISTRY_SETTINGS Retrieve the settings for the display device that are currently stored in the registry.

              Graphics mode indexes start at zero. To obtain information for all of a display device's graphics modes, make a series of calls to EnumDisplaySettings, as follows: Set iModeNum to zero for the first call, and increment iModeNum by one for each subsequent call. Continue calling the function until the return value is zero.

              ENUM_CURRENT_SETTINGS
              I can't find a value. But this code works on my PC (Win2000)

              Code:
              #Compile Exe
              #Register None
              #Include "win32api.INC"
              
              %ENUM_CURRENT_SETTINGS = &HFFFFFFFF ' Not sure, but works on my PC
              
              Declare Function EnumDisplaySettings Lib "user32.dll" _
                 Alias "EnumDisplaySettingsA" (lpszDeviceName As Asciiz, _
                 iModeNum As Dword, lpDevMode As DEVMODE) As Long
              
              Function PbMain () As Long
                 Dim lpDevMode As DEVMODE
                 EnumDisplaySettings ByVal 0, ByVal %ENUM_CURRENT_SETTINGS, lpDevMode
                 MsgBox Str$(lpDevMode.dmPelsWidth) + " X" + _
                    Str$(lpDevMode.dmBitsPerPel) + " X" + _
                    Str$(lpDevMode.dmPelsHeight) + " " + _
                    Str$(lpDevMode.dmDisplayFrequency) + " Hz"
                 
              End Function
              [This message has been edited by Semen Matusovski (edited April 18, 2000).]

              Comment


              • #8
                Wonderful Semen! More than one way to 'skin a cat' - and I'll take YOURS!

                William Fletcher

                ------------------

                Comment


                • #9
                  William --
                  I am also like this code , but I found for it another purpose - easy way to retrieve no. of colors.
                  Because it's necessary always to think about colors in 256-colors video-regime and to work with palettes every time is not comfortable, I decided to construct a function, which returns "true" or "adapted" color (to avoid classic Windows behaviour).

                  Code:
                     Declare Function EnumDisplaySettings Lib "user32.dll" _
                        Alias "EnumDisplaySettingsA" (lpszDeviceName As Asciiz, _
                        iModeNum As Dword, lpDevMode As DEVMODE) As Long
                  
                     Function SelectColor (TrueColor As Long, AdaptedColor As Long) As Long
                        Static lpDevMode As DEVMODE
                        If lpDevMode.dmBitsPerPel = 0 Then _
                           EnumDisplaySettings ByVal 0, ByVal -1, lpDevMode
                        If lpDevMode.dmBitsPerPel >= 16 Then _
                           Function = TrueColor Else Function = AdaptedColor
                     End Function
                  Sample of usage:
                  hBrush = CreateSolidBrush(SelectColor(Rgb(255, 192, 128), %YELLOW))



                  ------------------

                  Comment


                  • #10
                    William --

                    I have two news.
                    1) One positive
                    There is alternative way to detect freq under NT (see Win32Api.Hlp)
                    Code:
                    hdc  = CreateIC ("DISPLAY", ByVal %NULL, ByVal %NULL, ByVal %NULL)
                    %VREFRESH = 116
                    MsgBox Str$(GetDeviceCaps(hdc, %VREFRESH)) 
                    DeleteDC hdc
                    2) Negotive.
                    a) Windows 95 looks 100% stupid.
                    b) Windows 98 doesn't understand EnumDisplaySettings with -1 (current), but it looks that understands -2 (registry settings)


                    ------------------

                    Comment

                    Working...
                    X