Advertisement
Guest User

Untitled

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