Jump to content

How to change the refresh rate?


VicTT
 Share

Recommended Posts

this is an updated version from Larry to work with latest beta, might need some more work

Opt("MustDeclareVars", 1)

_Main()

Func _Main()
    Local $width, $height, $bpp, $freq
    
;~ $a = DisplayEnumRes(0, $width, $height, $bpp, $freq)
;~ MsgBox(4096,$a,$width & @LF & $height & @LF & $bpp & @LF & $freq)
    
;~ $a = DisplayEnumRes(1, $width, $height, $bpp, $freq)
;~ MsgBox(4096,$a,$width & @LF & $height & @LF & $bpp & @LF & $freq)
    
    MsgBox(4096, "", DisplayChangeRes(1024, 768, 32, 60))
    
    MsgBox(4096, "", DisplayChangeRes(1024, 768, 32, 75))
EndFunc  ;==>_Main

Func DisplayEnumRes($index, ByRef $width, ByRef $height, ByRef $bpp, ByRef $freq)
    Local $DEVMODE = DllStructCreate("byte[32];int[10];byte[32];int[6]")
    
    Local $b = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "long", $index, "ptr", DllStructGetPtr($DEVMODE))
    
    If @error Then
        $b = 0
    Else
        $b = $b[0]
    EndIf
    
    If $b <> 0 Then
        $width = DllStructGetData($DEVMODE, 4, 2)
        $height = DllStructGetData($DEVMODE, 4, 3)
        $bpp = DllStructGetData($DEVMODE, 4, 1)
        $freq = DllStructGetData($DEVMODE, 4, 5)
    EndIf
    
    $DEVMODE = 0
    
    Return $b
EndFunc  ;==>DisplayEnumRes

Func DisplayChangeRes($width, $height, $bpp, $freq)
    Local Const $DM_PELSWIDTH = 0x00080000
    Local Const $DM_PELSHEIGHT = 0x00100000
    Local Const $DM_BITSPERPEL = 0x00040000
    Local Const $DM_DISPLAYFREQUENCY = 0x00400000
    Local Const $CDS_TEST = 0x00000002
    Local Const $CDS_UPDATEREGISTRY = 0x00000001
    Local Const $DISP_CHANGE_RESTART = 1
    Local Const $DISP_CHANGE_SUCCESSFUL = 0
    Local Const $HWND_BROADCAST = 0xffff
    Local Const $WM_DISPLAYCHANGE = 0x007E
    
    Local $DEVMODE = DllStructCreate("byte[32];int[10];byte[32];int[6]")
    
    Local $b = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "long", 0, "ptr", DllStructGetPtr($DEVMODE))
    If @error Then
        $b = 0
    Else
        $b = $b[0]
    EndIf
    If $b <> 0 Then
        DllStructSetData($DEVMODE, 2, BitOR($DM_PELSWIDTH, $DM_PELSHEIGHT, $DM_BITSPERPEL, $DM_DISPLAYFREQUENCY), 5)
        DllStructSetData($DEVMODE, 4, $width, 2)
        DllStructSetData($DEVMODE, 4, $height, 3)
        DllStructSetData($DEVMODE, 4, $bpp, 1)
        DllStructSetData($DEVMODE, 4, $freq, 5)
        
        $b = DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "int", $CDS_TEST)
        
        If @error Then
            $b = -1
        Else
            $b = $b[0]
        EndIf
        
        Select
            Case $b = $DISP_CHANGE_RESTART
                $DEVMODE = 0
                Return 2
            Case $b = $DISP_CHANGE_SUCCESSFUL
                DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "int", $CDS_UPDATEREGISTRY)
                DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_DISPLAYCHANGE, _
                        "int", $bpp, "int", $height * 2 ^ 16 + $width)
                $DEVMODE = 0
                Return 1
            Case Else
                $DEVMODE = 0
                Return $b
        EndSelect
    EndIf
EndFunc  ;==>DisplayChangeRes

#cs
    Func DisplayChangeDPI($dpi)
    {
    DEVMODE DevM;
    long ret;
    
    EnumDisplaySettings(NULL,0,&DevM);
    
    DevM.dmFields = DM_LOGPIXELS;
    DevM.dmLogPixels = dpi;
    
    ret = ChangeDisplaySettings(&DevM, CDS_TEST);
    
    switch(ret)
    {
    case DISP_CHANGE_RESTART:
    return 2;
    case DISP_CHANGE_SUCCESSFUL:
    ChangeDisplaySettings(&DevM, CDS_UPDATEREGISTRY);
    SendMessage(HWND_BROADCAST, WM_DISPLAYCHANGE, (WPARAM)DevM.dmBitsPerPel, (LPARAM)(DevM.dmPelsHeight * 2 ^ 16 + DevM.dmPelsWidth));
    return 1;
    default:
    return 0;
    }
    }
#ce
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • 7 months later...

You could use a script to start the game. Have it first change the refresh rate, then start the game. When you close the game, have it change it back, then exit the script. Maybe something like this:

Opt("MustDeclareVars", 1)
dim $width, $height, $bpp, $freq
DisplayChangeRes($width, $height, $bpp, $freq) ;changes to refresh for game
runwait("The name of game", "Path")
DisplayChangeRes($width, $height, $bpp, $freq) ;changes to refresh for normal use
exit

Func DisplayEnumRes($index, ByRef $width, ByRef $height, ByRef $bpp, ByRef $freq)
    Local $DEVMODE = DllStructCreate("byte[32];int[10];byte[32];int[6]")
    
    Local $b = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "long", $index, "ptr", DllStructGetPtr($DEVMODE))
    
    If @error Then
        $b = 0
    Else
        $b = $b[0]
    EndIf
    
    If $b <> 0 Then
        $width = DllStructGetData($DEVMODE, 4, 2)
        $height = DllStructGetData($DEVMODE, 4, 3)
        $bpp = DllStructGetData($DEVMODE, 4, 1)
        $freq = DllStructGetData($DEVMODE, 4, 5)
    EndIf
    
    $DEVMODE = 0
    
    Return $b
EndFunc  ;==>DisplayEnumRes

Func DisplayChangeRes($width, $height, $bpp, $freq)
    Local Const $DM_PELSWIDTH = 0x00080000
    Local Const $DM_PELSHEIGHT = 0x00100000
    Local Const $DM_BITSPERPEL = 0x00040000
    Local Const $DM_DISPLAYFREQUENCY = 0x00400000
    Local Const $CDS_TEST = 0x00000002
    Local Const $CDS_UPDATEREGISTRY = 0x00000001
    Local Const $DISP_CHANGE_RESTART = 1
    Local Const $DISP_CHANGE_SUCCESSFUL = 0
    Local Const $HWND_BROADCAST = 0xffff
    Local Const $WM_DISPLAYCHANGE = 0x007E
    
    Local $DEVMODE = DllStructCreate("byte[32];int[10];byte[32];int[6]")
    
    Local $b = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "long", 0, "ptr", DllStructGetPtr($DEVMODE))
    If @error Then
        $b = 0
    Else
        $b = $b[0]
    EndIf
    If $b <> 0 Then
        DllStructSetData($DEVMODE, 2, BitOR($DM_PELSWIDTH, $DM_PELSHEIGHT, $DM_BITSPERPEL, $DM_DISPLAYFREQUENCY), 5)
        DllStructSetData($DEVMODE, 4, $width, 2)
        DllStructSetData($DEVMODE, 4, $height, 3)
        DllStructSetData($DEVMODE, 4, $bpp, 1)
        DllStructSetData($DEVMODE, 4, $freq, 5)
        
        $b = DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "int", $CDS_TEST)
        
        If @error Then
            $b = -1
        Else
            $b = $b[0]
        EndIf
        
        Select
            Case $b = $DISP_CHANGE_RESTART
                $DEVMODE = 0
                Return 2
            Case $b = $DISP_CHANGE_SUCCESSFUL
                DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "int", $CDS_UPDATEREGISTRY)
                DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_DISPLAYCHANGE, _
                        "int", $bpp, "int", $height * 2 ^ 16 + $width)
                $DEVMODE = 0
                Return 1
            Case Else
                $DEVMODE = 0
                Return $b
        EndSelect
    EndIf
EndFunc  ;==>DisplayChangeRes

I didn't test this. You may need to tweak it.

Edited by vollyman
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...