Sign in to follow this  
Followers 0
Stormgrade

Change Display Setting and Maintain display Scaling

1 post in this topic

#1 ·  Posted

Hello,

I want to use the "_ChangeScreenResEx()" UDF for changing my display settings from 1680*1050 to 1280*800.

When I use it the display change to 1280*800 but with Intel Drivers, Scaling option change : Maintain display Scaling become Center Image.

firefox_2017-06-20_10-58-01.png

Here my Main program

#include <.\_ChangeResolutionEx.au3>

Global $Config = @ScriptDir & "\ChangeResolution.ini"

Global $aSection = IniReadSectionNames($Config)

Global $Moniteur,$Largeur,$Hauteur,$Profondeur,$Refresh

for $i = 1 to $aSection[0] Step 1
    $Moniteur = Number($i)
    $Largeur = Number(IniRead($Config,$i,"Width","1680"))
    $Hauteur = Number(IniRead($Config,$i,"Height","1050"))
    $Profondeur = Number(IniRead($Config,$i,"Bits","32"))
    $Refresh = Number(IniRead($Config,$i,"Refresh","60"))
    _ChangeScreenResEx($Moniteur,$Largeur,$Hauteur,$Profondeur,$Refresh)
    Sleep(1000)
Next

 _ChangeScreenResEx()

#include-once
;===============================================================================
; Function Name:    _ChangeScreenResEx()
; Description:    Changes the current screen geometry, colour and refresh rate.
; Version:        1.0.0.0
; Parameter(s):  $i_DisplayNum - Display to change, starting at 1
;                  $i_Width - Width of the desktop screen in pixels. (horizontal resolution)
;                  $i_Height - Height of the desktop screen in pixels. (vertical resolution)
;                   $i_BitsPP - Depth of the desktop screen in bits per pixel.
;                   $i_RefreshRate - Refresh rate of the desktop screen in hertz.
; Requirement(s):   AutoIt Beta > 3.1
; Return Value(s):  On Success - Screen is adjusted, @ERROR = 0
;                  On Failure - sets @ERROR = 1
; Forum(s):
; Author(s):        Original code - psandu.ro, PartyPooper
;                  Modifications - bobchernow
;===============================================================================
Func _ChangeScreenResEx($i_DisplayNum = 1, $i_Width = @DesktopWidth, $i_Height = @DesktopHeight, $i_BitsPP = @DesktopDepth, $i_RefreshRate = @DesktopRefresh)
    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
    If $i_Width = "" Or $i_Width = -1 Then $i_Width = @DesktopWidth; default to current setting
    If $i_Height = "" Or $i_Height = -1 Then $i_Height = @DesktopHeight; default to current setting
    If $i_BitsPP = "" Or $i_BitsPP = -1 Then $i_BitsPP = @DesktopDepth; default to current setting
    If $i_RefreshRate = "" Or $i_RefreshRate = -1 Then $i_RefreshRate = @DesktopRefresh; default to current setting
    Local $DEVMODE = DllStructCreate("byte[32];int[10];byte[32];int[6]")
    Local $s_Display

    $s_Display = "\\.\Display" & $i_DisplayNum

    Local $B = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "int", 0, "ptr", DllStructGetPtr($DEVMODE))

    If @error Then
        $B = 0
        SetError(1)
        Return $B
    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, $i_Width, 2)
        DllStructSetData($DEVMODE, 4, $i_Height, 3)
        DllStructSetData($DEVMODE, 4, $i_BitsPP, 1)
        DllStructSetData($DEVMODE, 4, $i_RefreshRate, 5)

        $B = DllCall("user32.dll", "int", "ChangeDisplaySettingsEx","str", $s_Display, "ptr", DllStructGetPtr($DEVMODE), "hwnd", 0, "dword", $CDS_TEST, "lparam", 0)
        If @error Then
            $B = -1
        Else
            $B = $B[0]
        EndIf
        Select
            Case $B = $DISP_CHANGE_RESTART
                $DEVMODE = ""
                Return 2
            Case $B = $DISP_CHANGE_SUCCESSFUL
                DllCall("user32.dll", "int", "ChangeDisplaySettingsEx","str", $s_Display, "ptr", DllStructGetPtr($DEVMODE), "hwnd", 0, "dword", $CDS_UPDATEREGISTRY, "lparam", 0)
                DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_DISPLAYCHANGE, _
                        "int", $i_BitsPP, "int", $i_Height * 2 ^ 16 + $i_Width)
                $DEVMODE = ""
                Return 1
            Case Else
                $DEVMODE = ""
                SetError(1)
                Return $B
        EndSelect
    EndIf
EndFunc;==>_ChangeScreenResEx

Any idea how to get around this problem ?

thanks for your answer.

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      Hi dear
      I have a question
      about the display language of the system
      How can I get the current display language and how can I change it by autoit
      Of course, if this is possible
      Greetings to all and hope you help me
    • FrancescoDiMuro
      By FrancescoDiMuro
      Hi guys! How are you? Hope you're fine
      I'm trying to use SQLite for managing some data, and, I would like to display my "retrieved" data, but I'm trying to do a select from 2 table, and seems to not work properly...
      What I'd like to do is retrieve data from 2 tables and display in a listview...
      I tried with:
      Local $aRisultato, $iRighe, $iColonne, $iRVal $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Rockwell, Magazzino_Siemens;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then ;_SQLite_Display2DResult($aRisultato) _ArrayDisplay($aRisultato) EndIf ... but it displays a single record 41 times, and it does this thing for every record in the database...
      What do you need to help me?
      Thanks  

      EDIT:
      Managed with a double If and double query like this:
       
      $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Rockwell;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then Local $aRisultatoRockwell = $aRisultato $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Siemens;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then _ArrayConcatenate($aRisultato, $aRisultatoRockwell) Local $i, $sRiga, $s_LV_Item For $i = 1 To Ubound($aRisultato) - 1 $sRiga = $aRisultato[$i][0] & "|" & _ $aRisultato[$i][1] & "|" & _ $aRisultato[$i][2] & "|" & _ $aRisultato[$i][3] & "|" & _ $aRisultato[$i][4] & "|" & _ $aRisultato[$i][5] & "|" & _ $aRisultato[$i][6] & "|" & _ $aRisultato[$i][7] & "|" & _ $aRisultato[$i][8] & "|" & _ $aRisultato[$i][9] & "|" & _ $aRisultato[$i][10] & "|" & _ $aRisultato[$i][11] $s_LV_Item = GUICtrlCreateListViewItem($sRiga, $lv_Lista) Next And so, the listview is created
      If anyone has another more efficient way, I'm here Thanks guys  
       
    • AmarokStudios
      By AmarokStudios
      Hello all! I'm trying to figure out how to display the contents of my Microsoft Outlooks inbox inside of an AutoIt GUI.
       
      So far, I've managed to embed it perfectly and the website looks fantastic, but whenever I click on a message in my inbox, I can't view it. I also can't create new messages or search my inbox. I figured this was probably an ActiveX or JavaScript incompatibility. Any ideas?
       
      Local $oIE = _IECreateEmbedded() $browserObj = GUICtrlCreateObj($oIE, 20, 60, 780, 580) _IENavigate($oIE, "https://outlook.office.com/owa/#path=/mail")  
    • thatguypursue
      By thatguypursue
      In my code, I'm using GUICtrlCreateLabel to create a label and GUICtrlSetFont to set the font. Example...
      $SELlbl = GUICtrlCreateLabel("Hello World", 8, 8, 286, 24) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") This works in my GUI unless display settings are changed in Windows 7 from 100% to 125-150%. Then the text is blown up and is misaligned with my GUI. 
      Is there a simple way to ignore the display setting and force the font size?
    • Mungo
      By Mungo
      I have encountered that the font weight does not seem to scale the way I would have expected. The degree of "bold" does not always increase with the weight value but even reverses e.g. 700 being less bold than 600 ?
      Does anyone have an idea?
      Code and screenshot below.
      Cheers
      #include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Example() Func Example() Local $f_size = 9 Local $h_win = GUICreate ( "TEST GUI ... FONT weight", 400, 350) GUISetBkColor(0xffffff, $h_win) GUISetFont(10, 400, 0, "Arial", $h_win, 2) GUICtrlCreateLabel("Test FONT weight ...", 10, 10) GUICtrlCreateLabel("The quick brown fox jumps over ... (weight = 200)", 10, 60, 380, 20) GUICtrlSetFont(-1, $f_size, 200) GUICtrlSetColor(-1, 0x000099) GUICtrlCreateLabel("The quick brown fox jumps over ... (weight = 400)", 10, 90, 380, 20) GUICtrlSetFont(-1, $f_size, 400) GUICtrlSetColor(-1, 0x000099) GUICtrlCreateLabel("The quick brown fox jumps over ... (weight = 500)", 10, 120, 380, 20) GUICtrlSetFont(-1, $f_size, 500) GUICtrlSetColor(-1, 0x000099) GUICtrlCreateLabel("The quick brown fox jumps over ... (weight = 600)", 10, 150, 380, 20) GUICtrlSetFont(-1, $f_size, 600) GUICtrlSetColor(-1, 0x000099) GUICtrlCreateLabel("The quick brown fox jumps over ... (weight = 700)", 10, 180, 380, 20) GUICtrlSetFont(-1, $f_size, 700) GUICtrlSetColor(-1, 0x000099) GUICtrlCreateLabel("The quick brown fox jumps over ... (weight = 800)", 10, 210, 380, 20) GUICtrlSetFont(-1, $f_size, 800) GUICtrlSetColor(-1, 0x000099) GUICtrlCreateLabel("The quick brown fox jumps over ... (weight = 900)", 10, 240, 380, 20) GUICtrlSetFont(-1, $f_size, 900) GUICtrlSetColor(-1, 0x000099) Local $button = GUICtrlCreateButton("Close", 160, 310, 80, 20) GUISetState(@SW_SHOW) While 1 Local $msg_pop = GUIGetMsg() Select Case $msg_pop = $GUI_EVENT_CLOSE ExitLoop Case $msg_pop = $button ExitLoop EndSelect WEnd GUIDelete() EndFunc