找回密码
 加入
搜索
查看: 5181|回复: 0

[系统综合] _ChangeScreenRes()如何修改系统支持的最大屏幕分辨率?

[复制链接]
发表于 2013-2-19 10:18:47 | 显示全部楼层 |阅读模式
本帖最后由 yifang3878 于 2013-2-19 11:29 编辑

_ChangeScreenRes()修改系统支持的最大分辨率的时候会失败,比如系统最大支持1366*768,_ChangeScreenRes(1366,768)会执行失败。
代码如下,请问如何修改函数?


#include-once
;===============================================================================
;
; 函数名称:    _ChangeScreenRes()
; 详细信息:    修改 屏幕分辨率,刷新率.
; 版本:          1.0.0.1
; 参数:     $i_Width - 屏幕宽度(如1024X768 中的 1024)
;             $i_Height - 屏幕高度(如1024X768 中的 768)
;             $i_BitsPP -桌面颜色深度(如 32BIT,32位)
;             $i_RefreshRate - 屏幕刷新率(如 75 MHZ).
; 需求      AutoIt 测试版 > 3.1 以上
; 返回值  :      成功,屏幕更新,@ERROR = 0
;                   失败,屏幕不更新, @ERROR = 1
; 论坛:         http://www.autoitscript.com/forum/index.php?showtopic=20121
; 作者:        Original code - psandu.ro
;                Modifications - PartyPooper
; 翻译:        thesnow
;
;===============================================================================
Func _ChangeScreenRes($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 $B = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "long", 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", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "int", $CDS_TEST)
  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", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "int", $CDS_UPDATEREGISTRY)
    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 ;==>_ChangeScreenRes
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-26 00:32 , Processed in 0.076910 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表