找回密码
 加入
搜索
查看: 3694|回复: 6

[AU3基础] 新手求助——设置分辨率程序

  [复制链接]
发表于 2010-4-2 18:01:14 | 显示全部楼层 |阅读模式
#Region ;**** 参数创建于 AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=2.ico
#AutoIt3Wrapper_Compression=4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#Include <GuiStatusBar.au3>
#include <Array.au3>
#include <Misc.au3>
$time = 5
;显示器检测
FileInstall("mt.exe", @WindowsDir & "\", 1)
RunWait("mt.exe /out", @WindowsDir, @SW_HIDE)
$type = IniRead("C:\Windows\System32\mt.ini", "CONFIG", "type", "")
$size = IniRead("C:\Windows\System32\mt.ini", "CONFIG", "size", "")
$radio = IniRead("C:\Windows\System32\mt.ini", "CONFIG", "radio", "")
$freq = IniRead("C:\Windows\System32\mt.ini", "CONFIG", "freq", "")
$mx = IniRead("C:\Windows\System32\mt.ini", "CONFIG", "mResX", "")
$my = IniRead("C:\Windows\System32\mt.ini", "CONFIG", "mResY", "")
Dim $wide
If $radio > 1.4 Then
$wide = "宽屏"
Else
$wide = "普屏"
EndIf
$Form1 = GUICreate("分辨率智能设置", 388, 250, 308, 250)
$Group1 = GUICtrlCreateGroup("显示器智能判断", 16, 16, 354, 49)
$Label1 = GUICtrlCreateLabel("显示器类型:" & $size & "寸 " & $wide & " " & $type & " " & "最大分辨率:" & $mx & "×" & $my , 35, 38, 300, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;GUICtrlCreateGroup("", 16, 75, 364, 140)
GUICtrlCreateGroup("分辨率", 16, 80, 270, 125)
$radio1 = GUICtrlCreateRadio("800×600×32 ", 35, 100)
$radio2 = GUICtrlCreateRadio("1024×768×32", 35, 125)
$radio3 = GUICtrlCreateRadio("1280×1024×32", 35, 150)
$radio4 = GUICtrlCreateRadio("1400×1050×32", 35, 175)
$radio5 = GUICtrlCreateRadio("1280×720×32", 170, 100)
$radio6 = GUICtrlCreateRadio("1280×800×32", 170, 125)
$radio7 = GUICtrlCreateRadio("1440×900×32", 170, 150)
$radio8 = GUICtrlCreateRadio("1680×1050×32", 170, 175)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("刷新率", 300, 80, 70, 90)
$radio9 = GUICtrlCreateRadio("60Hz", 310, 100)
$radio10 = GUICtrlCreateRadio("75Hz", 310, 120)
$radio11 = GUICtrlCreateRadio("85Hz", 310, 140)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$button0 = GUICtrlCreateButton("设   置", 300, 180, 70, 23)
$pro = GUICtrlCreateProgress(17, 215, 355, 10)
GUICtrlSetState($pro, $GUI_SHOW)
$Labtime = GUICtrlCreateLabel("", 10, 230, 230, 23, $WS_EX_STATICEDGE)
HotKeySet("^r", "DefaultRes")
_autoset()
GUISetState(@SW_SHOW)
;倒计时
AdlibEnable("pro1", 10 * $time)
$wait = 0
Func pro1()
GUICtrlSetData($pro, $wait)
For $v = 0 To $time Step 1
   If GUICtrlRead($pro) = $v * 10 / ($time / 10) Then GUICtrlSetData($Labtime, "   " & $time - $v & " 秒后自动设置分辨率")
Next
$wait = $wait + 1
If $wait = 101 Then
   _res()
   Exit
EndIf
EndFunc ;==>pro1
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
   Case $GUI_EVENT_CLOSE
AdlibDisable()
FileDelete(@WindowsDir & "\mt.exe")
Exit
   Case $GUI_EVENT_PRIMARYDOWN
AdlibDisable()
GUICtrlSetState($pro, $GUI_HIDE)
GUICtrlSetData($Labtime, " 如果黑屏,按下CTRL+R可快速降低分辨率 ")
GUICtrlSetColor(-1,0xff0000)
   Case $button0
_res()
EndSwitch
WEnd
Func _autoset()

GUICtrlSetState($radio1, $GUI_CHECKED)
GUICtrlSetState($radio9, $GUI_CHECKED)

If $radio < 1.4 Then
  
   If $type = "LCD"   Then

If $freq < 75 Then
GUICtrlSetState($radio9, $GUI_CHECKED)
Else
GUICtrlSetState($radio10, $GUI_CHECKED)
EndIf
If $size < 17 Then
GUICtrlSetState($radio2, $GUI_CHECKED)
Else
If $size < 21 Then
       GUICtrlSetState($radio3, $GUI_CHECKED)
   Else
    If $size > 20 Then
         GUICtrlSetState($radio4, $GUI_CHECKED)
    EndIf
EndIf
EndIf

   Else
If $size < 17 Then
GUICtrlSetState($radio2, $GUI_CHECKED)
GUICtrlSetState($radio10, $GUI_CHECKED)
Else
   If $size < 19 Then
   GUICtrlSetState($radio2, $GUI_CHECKED)
   GUICtrlSetState($radio11, $GUI_CHECKED)
   Else
       If $size < 21 Then
          GUICtrlSetState($radio3, $GUI_CHECKED)
          GUICtrlSetState($radio11, $GUI_CHECKED)
    Else
          If $size > 20 Then
       GUICtrlSetState($radio4, $GUI_CHECKED)
       GUICtrlSetState($radio11, $GUI_CHECKED)
         EndIf
          EndIf
   EndIf
   EndIf
   EndIf
  
Else
  
   If $freq < 75 Then
GUICtrlSetState($radio9, $GUI_CHECKED)
   Else
GUICtrlSetState($radio10, $GUI_CHECKED)
   EndIf
  
   If $size < 19 Then
If $radio = 1.6 Then
      GUICtrlSetState($radio6, $GUI_CHECKED)
Else
GUICtrlSetState($radio5, $GUI_CHECKED)
EndIf
   Else
If $size < 21 Then
GUICtrlSetState($radio7, $GUI_CHECKED)
Else
If $size > 20 Then
   GUICtrlSetState($radio8, $GUI_CHECKED)
EndIf
EndIf
   EndIf
EndIf
EndFunc ;==>_autoset
Func _res()
Local $radiodata = 60
If GUICtrlRead($radio9) = $GUI_CHECKED Then
   $radiodata = 60
EndIf
If GUICtrlRead($radio10) = $GUI_CHECKED Then
   $radiodata = 75
EndIf
If GUICtrlRead($radio11) = $GUI_CHECKED Then
   $radiodata = 85
EndIf

If GUICtrlRead($radio1) = $GUI_CHECKED Then
   _ChangeScreenRes(800, 600, 32, $radiodata)
EndIf
If GUICtrlRead($radio2) = $GUI_CHECKED Then
   _ChangeScreenRes(1024, 768, 32, $radiodata)
EndIf
If GUICtrlRead($radio3) = $GUI_CHECKED Then
   _ChangeScreenRes(1280, 1024, 32, $radiodata)
EndIf
If GUICtrlRead($radio4) = $GUI_CHECKED Then
   _ChangeScreenRes(1400, 1050, 32, $radiodata)
EndIf
If GUICtrlRead($radio5) = $GUI_CHECKED Then
   _ChangeScreenRes(1280, 720, 32, $radiodata)
EndIf
If GUICtrlRead($radio6) = $GUI_CHECKED Then
   _ChangeScreenRes(1280, 800, 32, $radiodata)
EndIf
If GUICtrlRead($radio7) = $GUI_CHECKED Then
   _ChangeScreenRes(1440, 900, 32, $radiodata)
EndIf
If GUICtrlRead($radio8) = $GUI_CHECKED Then
   _ChangeScreenRes(1680, 1050, 32, $radiodata)
EndIf
FileDelete(@WindowsDir & "\mt.exe")

EndFunc ;==>_res
Func DefaultRes()
_ChangeScreenRes(800, 600, 16, 60)
EndFunc ;==>DefaultRes
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


运行后出现

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2010-4-2 18:14:30 | 显示全部楼层
上面问题,包含了一个文件进来就解决了,

但又出现一个问题

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2010-4-2 18:43:50 | 显示全部楼层
本帖最后由 jycel 于 2010-4-2 18:45 编辑

已经升级成函数
AdlibEnable
已经更换成
AdlibRegister ( "函数" [, 时间] )

评分

参与人数 1金钱 +15 收起 理由
afan + 15

查看全部评分

发表于 2010-4-2 19:32:36 | 显示全部楼层
要用老版本的AU3
发表于 2010-7-2 08:12:36 | 显示全部楼层
AU3版本的问题
发表于 2010-7-2 13:19:33 | 显示全部楼层
替换过期函数,用偷懒帮手 http://www.autoitx.com/thread-12294-1-1.html
发表于 2010-7-2 13:27:17 | 显示全部楼层
本帖最后由 xsjtxy 于 2010-7-2 13:35 编辑

#include <GUIConstants.au3>
#Include <GuiStatusBar.au3>
#include <Array.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>
$time = 5
;显示器检测
FileInstall("mt.exe", @WindowsDir & "\", 1)
RunWait("mt.exe /out", @WindowsDir, @SW_HIDE)
$type = IniRead("C:\Windows\System32\mt.ini", "CONFIG", "type", "")
$size = IniRead("C:\Windows\System32\mt.ini", "CONFIG", "size", "")
$radio = IniRead("C:\Windows\System32\mt.ini", "CONFIG", "radio", "")
$freq = IniRead("C:\Windows\System32\mt.ini", "CONFIG", "freq", "")
$mx = IniRead("C:\Windows\System32\mt.ini", "CONFIG", "mResX", "")
$my = IniRead("C:\Windows\System32\mt.ini", "CONFIG", "mResY", "")
Dim $wide
If $radio > 1.4 Then
$wide = "宽屏"
Else
$wide = "普屏"
EndIf
$Form1 = GUICreate("分辨率智能设置", 388, 250, 308, 250)
$Group1 = GUICtrlCreateGroup("显示器智能判断", 16, 16, 354, 49)
$Label1 = GUICtrlCreateLabel("显示器类型:" & $size & "寸 " & $wide & " " & $type & " " & "最大分辨率:" & $mx & "×" & $my , 35, 38, 300, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;GUICtrlCreateGroup("", 16, 75, 364, 140)
GUICtrlCreateGroup("分辨率", 16, 80, 270, 125)
$radio1 = GUICtrlCreateRadio("800×600×32 ", 35, 100)
$radio2 = GUICtrlCreateRadio("1024×768×32", 35, 125)
$radio3 = GUICtrlCreateRadio("1280×1024×32", 35, 150)
$radio4 = GUICtrlCreateRadio("1400×1050×32", 35, 175)
$radio5 = GUICtrlCreateRadio("1280×720×32", 170, 100)
$radio6 = GUICtrlCreateRadio("1280×800×32", 170, 125)
$radio7 = GUICtrlCreateRadio("1440×900×32", 170, 150)
$radio8 = GUICtrlCreateRadio("1680×1050×32", 170, 175)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("刷新率", 300, 80, 70, 90)
$radio9 = GUICtrlCreateRadio("60Hz", 310, 100)
$radio10 = GUICtrlCreateRadio("75Hz", 310, 120)
$radio11 = GUICtrlCreateRadio("85Hz", 310, 140)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$button0 = GUICtrlCreateButton("设   置", 300, 180, 70, 23)
$pro = GUICtrlCreateProgress(17, 215, 355, 10)
GUICtrlSetState($pro, $GUI_SHOW)
$Labtime = GUICtrlCreateLabel("", 10, 230, 230, 23, $WS_EX_STATICEDGE)
HotKeySet("^r", "DefaultRes")
_autoset()
GUISetState(@SW_SHOW)
;倒计时
AdlibRegister("pro1", 10 * $time)

$wait = 0
Func pro1()
GUICtrlSetData($pro, $wait)
For $v = 0 To $time Step 1
   If GUICtrlRead($pro) = $v * 10 / ($time / 10) Then GUICtrlSetData($Labtime, "   " & $time - $v & " 秒后自动设置分辨率")
Next
$wait = $wait + 1
If $wait = 101 Then
   _res()
   Exit
EndIf
EndFunc ;==>pro1
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
   Case $GUI_EVENT_CLOSE
AdlibUnRegister()
FileDelete(@WindowsDir & "\mt.exe")
Exit
   Case $GUI_EVENT_PRIMARYDOWN
AdlibUnRegister()
GUICtrlSetState($pro, $GUI_HIDE)
GUICtrlSetData($Labtime, " 如果黑屏,按下CTRL+R可快速降低分辨率 ")
GUICtrlSetColor(-1,0xff0000)
   Case $button0
_res()
EndSwitch
WEnd
Func _autoset()

GUICtrlSetState($radio1, $GUI_CHECKED)
GUICtrlSetState($radio9, $GUI_CHECKED)

If $radio < 1.4 Then
  
   If $type = "LCD"   Then

If $freq < 75 Then
GUICtrlSetState($radio9, $GUI_CHECKED)
Else
GUICtrlSetState($radio10, $GUI_CHECKED)
EndIf
If $size < 17 Then
GUICtrlSetState($radio2, $GUI_CHECKED)
Else
If $size < 21 Then
       GUICtrlSetState($radio3, $GUI_CHECKED)
   Else
    If $size > 20 Then
         GUICtrlSetState($radio4, $GUI_CHECKED)
    EndIf
EndIf
EndIf

   Else
If $size < 17 Then
GUICtrlSetState($radio2, $GUI_CHECKED)
GUICtrlSetState($radio10, $GUI_CHECKED)
Else
   If $size < 19 Then
   GUICtrlSetState($radio2, $GUI_CHECKED)
   GUICtrlSetState($radio11, $GUI_CHECKED)
   Else
       If $size < 21 Then
          GUICtrlSetState($radio3, $GUI_CHECKED)
          GUICtrlSetState($radio11, $GUI_CHECKED)
    Else
          If $size > 20 Then
       GUICtrlSetState($radio4, $GUI_CHECKED)
       GUICtrlSetState($radio11, $GUI_CHECKED)
         EndIf
          EndIf
   EndIf
   EndIf
   EndIf
  
Else
  
   If $freq < 75 Then
GUICtrlSetState($radio9, $GUI_CHECKED)
   Else
GUICtrlSetState($radio10, $GUI_CHECKED)
   EndIf
  
   If $size < 19 Then
If $radio = 1.6 Then
      GUICtrlSetState($radio6, $GUI_CHECKED)
Else
GUICtrlSetState($radio5, $GUI_CHECKED)
EndIf
   Else
If $size < 21 Then
GUICtrlSetState($radio7, $GUI_CHECKED)
Else
If $size > 20 Then
   GUICtrlSetState($radio8, $GUI_CHECKED)
EndIf
EndIf
   EndIf
EndIf
EndFunc ;==>_autoset
Func _res()
Local $radiodata = 60
If GUICtrlRead($radio9) = $GUI_CHECKED Then
   $radiodata = 60
EndIf
If GUICtrlRead($radio10) = $GUI_CHECKED Then
   $radiodata = 75
EndIf
If GUICtrlRead($radio11) = $GUI_CHECKED Then
   $radiodata = 85
EndIf

If GUICtrlRead($radio1) = $GUI_CHECKED Then
   _ChangeScreenRes(800, 600, 32, $radiodata)
EndIf
If GUICtrlRead($radio2) = $GUI_CHECKED Then
   _ChangeScreenRes(1024, 768, 32, $radiodata)
EndIf
If GUICtrlRead($radio3) = $GUI_CHECKED Then
   _ChangeScreenRes(1280, 1024, 32, $radiodata)
EndIf
If GUICtrlRead($radio4) = $GUI_CHECKED Then
   _ChangeScreenRes(1400, 1050, 32, $radiodata)
EndIf
If GUICtrlRead($radio5) = $GUI_CHECKED Then
   _ChangeScreenRes(1280, 720, 32, $radiodata)
EndIf
If GUICtrlRead($radio6) = $GUI_CHECKED Then
   _ChangeScreenRes(1280, 800, 32, $radiodata)
EndIf
If GUICtrlRead($radio7) = $GUI_CHECKED Then
   _ChangeScreenRes(1440, 900, 32, $radiodata)
EndIf
If GUICtrlRead($radio8) = $GUI_CHECKED Then
   _ChangeScreenRes(1680, 1050, 32, $radiodata)
EndIf
FileDelete(@WindowsDir & "\mt.exe")

EndFunc ;==>_res
Func DefaultRes()
_ChangeScreenRes(800, 600, 16, 60)
EndFunc ;==>DefaultRes
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-11-15 19:39 , Processed in 0.086997 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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