Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 3.75 KB | None | 0 0
  1. #include-once
  2. ;===============================================================================
  3. ; Function Name:    _ChangeScreenResEx()
  4. ; Description:    Changes the current screen geometry, colour and refresh rate.
  5. ; Version:        1.0.0.0
  6. ; Parameter(s):  $i_DisplayNum - Display to change, starting at 1
  7. ;                  $i_Width - Width of the desktop screen in pixels. (horizontal resolution)
  8. ;                  $i_Height - Height of the desktop screen in pixels. (vertical resolution)
  9. ;                   $i_BitsPP - Depth of the desktop screen in bits per pixel.
  10. ;                   $i_RefreshRate - Refresh rate of the desktop screen in hertz.
  11. ; Requirement(s):   AutoIt Beta > 3.1
  12. ; Return Value(s):  On Success - Screen is adjusted, @ERROR = 0
  13. ;                  On Failure - sets @ERROR = 1
  14. ; Forum(s):      
  15. ; Author(s):        Original code - psandu.ro, PartyPooper
  16. ;                  Modifications - bobchernow
  17. ;===============================================================================
  18. Func _ChangeScreenResEx($i_DisplayNum = 1, $i_Width = @DesktopWidth, $i_Height = @DesktopHeight, $i_BitsPP = @DesktopDepth, $i_RefreshRate = @DesktopRefresh)
  19.     Local Const $DM_PELSWIDTH = 0x00080000
  20.     Local Const $DM_PELSHEIGHT = 0x00100000
  21.     Local Const $DM_BITSPERPEL = 0x00040000
  22.     Local Const $DM_DISPLAYFREQUENCY = 0x00400000
  23.     Local Const $CDS_TEST = 0x00000002
  24.     Local Const $CDS_UPDATEREGISTRY = 0x00000001
  25.     Local Const $DISP_CHANGE_RESTART = 1
  26.     Local Const $DISP_CHANGE_SUCCESSFUL = 0
  27.     Local Const $HWND_BROADCAST = 0xffff
  28.     Local Const $WM_DISPLAYCHANGE = 0x007E
  29.     If $i_Width = "" Or $i_Width = -1 Then $i_Width = @DesktopWidth; default to current setting
  30.     If $i_Height = "" Or $i_Height = -1 Then $i_Height = @DesktopHeight; default to current setting
  31.     If $i_BitsPP = "" Or $i_BitsPP = -1 Then $i_BitsPP = @DesktopDepth; default to current setting
  32.     If $i_RefreshRate = "" Or $i_RefreshRate = -1 Then $i_RefreshRate = @DesktopRefresh; default to current setting
  33.     Local $DEVMODE = DllStructCreate("byte[32];int[10];byte[32];int[6]")
  34.     Local $s_Display
  35.    
  36.     $s_Display = "\\.\Display" & $i_DisplayNum
  37.    
  38.     Local $B = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "int", 0, "ptr", DllStructGetPtr($DEVMODE))
  39.    
  40.     If @error Then
  41.         $B = 0
  42.         SetError(1)
  43.         Return $B
  44.     Else
  45.         $B = $B[0]
  46.     EndIf
  47.     If $B <> 0 Then
  48.         DllStructSetData($DEVMODE, 2, BitOR($DM_PELSWIDTH, $DM_PELSHEIGHT, $DM_BITSPERPEL, $DM_DISPLAYFREQUENCY), 5)
  49.         DllStructSetData($DEVMODE, 4, $i_Width, 2)
  50.         DllStructSetData($DEVMODE, 4, $i_Height, 3)
  51.         DllStructSetData($DEVMODE, 4, $i_BitsPP, 1)
  52.         DllStructSetData($DEVMODE, 4, $i_RefreshRate, 5)
  53.    
  54.         $B = DllCall("user32.dll", "int", "ChangeDisplaySettingsEx","str", $s_Display, "ptr", DllStructGetPtr($DEVMODE), "hwnd", 0, "dword", $CDS_TEST, "lparam", 0)
  55.         If @error Then
  56.             $B = -1
  57.         Else
  58.             $B = $B[0]
  59.         EndIf
  60.         Select
  61.             Case $B = $DISP_CHANGE_RESTART
  62.                 $DEVMODE = ""
  63.                 Return 2
  64.             Case $B = $DISP_CHANGE_SUCCESSFUL
  65.                 DllCall("user32.dll", "int", "ChangeDisplaySettingsEx","str", $s_Display, "ptr", DllStructGetPtr($DEVMODE), "hwnd", 0, "dword", $CDS_UPDATEREGISTRY, "lparam", 0)
  66.                 DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_DISPLAYCHANGE, _
  67.                         "int", $i_BitsPP, "int", $i_Height * 2 ^ 16 + $i_Width)
  68.                 $DEVMODE = ""
  69.                 Return 1
  70.             Case Else
  71.                 $DEVMODE = ""
  72.                 SetError(1)
  73.                 Return $B
  74.         EndSelect
  75.     EndIf
  76. EndFunc;==>_ChangeScreenResEx
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement