发表回复 
关于改变桌面分辨率的脚本, WIN7 x64 有问题
2013-01-05, 03 : 03
关于改变桌面分辨率的脚本, WIN7 x64 有问题
[i=s] 本帖最后由 cgx5871 于 2013-1-10 16:17 编辑 [/i]

; Change Display Settings Demo... by Skan 08-Feb-2009
; Credit: shimanov www.autohotkey.com/forum/viewtopic.php?t=8355
; Caution: This Short script is meant for Demonstration purpose only..
; Applying incompatible settings ( refresh rate in particular ) may damage your hardware.
ChangeDisplaySettings( cD, sW, sH, rR )
Gui, +AlwaysOnTop +Owner
Gui, Font, S10, Tahoma
Gui, Add, ComboBox, w200 Simple R10 vEDS gUpdateButton, % EnumDisplaySettingsA()
Gui, Add, Button, xp+10 y+10] w180 h41 vSetting gChangeSetting
GuiControlGet, EDS
Gui, Show,, %EDS%

UpdateButton:
GuiControlGet, EDS
GuiControl,, Setting, Change Display`n%EDS%
Return

ChangeSetting:
GuiControlGet, EDS
StringReplace, EDS, EDS, x, % " / "
Loop, Parse, EDS, /, %A_Space%
F%A_Index% := RegExReplace( A_LoopField, "[^0-9]" )
ChangeDisplaySettings( F3, F1, F2, F4 )
GuiControl,, EDS, % EnumDisplaySettingsA()
GuiControlGet, EDS
Gui, Show,, %EDS%
Return

ChangeDisplaySettings( cD, sW, sH, rR ) {
VarSetCapacity(dM,156,0), NumPut(156,dM,36)
DllCall( "EnumDisplaySettingsA", UInt,0, UInt,-1, UInt,&dM ), NumPut(0x5c0000,dM,40)
NumPut(cD,dM,104), NumPut(sW,dM,108), NumPut(sH,dM,112), NumPut(rR,dM,120)
Return DllCall( "ChangeDisplaySettings", UInt,&dM, UInt,0 )
}

EnumDisplaySettingsA() {
VarSetCapacity(DM,156,0), NumPut(156,&DM,36, "UShort")
,DllCall( "EnumDisplaySettingsA", UInt,0, UInt,-1, UInt,&DM )
,CS:=NumGet(DM,108) "x" NumGet(DM,112) " / " NumGet(DM,104) "bit / " NumGet(DM,120) "Hz"
Loop
If DllCall( "EnumDisplaySettingsA", UInt,0, UInt,A_Index-1, UInt,&DM )
EDS:=NumGet(DM,108) "x" NumGet(DM,112) " / " NumGet(DM,104) "bit / " NumGet(DM,120) "Hz"
,DS.=(!InStr(DS,EDS) ? "|" EDS : "")
Else Break
StringReplace, DS, DS, %CS%|, %CS%||, All
Return SubStr(DS,2)
}

GuiClose:
GuiEscape:
ExitApp

;--------------------注:
AHK_L Unicode 将EnumDisplaySettingsA全部替换成EnumDisplaySettings (去掉A)

我的问题是: 在win7 64位上 数据不正确, 求64位系统的测试下,
会不会是 VarSetCapacity的问题?
查找这个用户的全部帖子
表示感谢 引用并回复 移动视图置页面顶端
2013-01-06, 00 : 07
 
很有可能是略寫數值型態的問題,因為32bit下預設的整數長度只有64bit預設整數長度的一半
我試了一下並修改EnumDisplaySettingsA()如下:

EnumDisplaySettingsA() {
VarSetCapacity(DM,156,0), NumPut(156,&DM,36, "UShort")
,DllCall( "EnumDisplaySettingsA", UInt,0, UInt,-1, UInt,&DM )
,CS:=NumGet(DM,108, "Ushort") "x" NumGet(DM,112, "Ushort") " / " NumGet(DM,104, "Ushort") "bit / " NumGet(DM,120, "Ushort") . "Hz"
Loop
If DllCall( "EnumDisplaySettingsA", UInt,0, UInt,A_Index-1, UInt,&DM )
EDS:=NumGet(DM,108, "Ushort") "x" NumGet(DM,112, "Ushort") " / " NumGet(DM,104, "Ushort") "bit / " NumGet(DM,120, "Ushort") "Hz"
,DS.=(!InStr(DS,EDS) ? "|" EDS : "")
Else Break
StringReplace, DS, DS, %CS%|, %CS%||, All
Return SubStr(DS,2)
}
修改後 數值顯示正確了 但是改動解析度的動作並沒有作用!
查找这个用户的全部帖子
表示感谢 引用并回复 移动视图置页面顶端
2013-01-07, 15 : 37
 
你的代码Win8 x64正常
查找这个用户的全部帖子
表示感谢 引用并回复 移动视图置页面顶端
2013-01-10, 16 : 16
 
ChangeDisplaySettings( cD, sW, sH, rR ) { ;------------bit, w, h ,hz
VarSetCapacity(dM,156,0), NumPut(156,dM,36, "UInt")
DllCall( "EnumDisplaySettingsA", UInt,0, UInt,-1, UInt,&dM ), NumPut(0x5c0000,dM,40, "UInt")
NumPut(cD,dM,104, "UInt"), NumPut(sW,dM,108, "UInt"), NumPut(sH,dM,112, "UInt"), NumPut(rR,dM,120, "UInt")
Return DllCall( "ChangeDisplaySettingsA", UInt,&dM, UInt,0 )
;~ Return DllCall( "ChangeDisplaySettingsA", UIntP,&dM, UInt,0 )
}

EnumDisplaySettingsA() {
global
VarSetCapacity(DM,156,0), NumPut(156,&DM,36, "UShort")
;~ MsgBox,%CS%
While DllCall( "EnumDisplaySettingsA", UInt,0, UInt,A_Index-1, UInt,&DM ) ;----取得所有分辨率
{
WH:=NumGet(DM,108, "UInt") "x" NumGet(DM,112, "UInt")
Bit:=NumGet(DM,104, "UInt") "位"
Hz:=NumGet(DM,120, "UInt") "Hz"

IfNotInString,%WH%Hz,%Hz%
%WH%Hz.=Hz "|"
IfNotInString,%WH%bit,%bit%
%WH%bit.=bit "|"

IfNotInString,%Bit%WH,%WH%
%Bit%WH.=WH "|"
IfNotInString,%Bit%Hz,%Hz%
%Bit%Hz.=Hz "|"

IfNotInString,%Hz%WH,%WH%
%Hz%WH.=WH "|"
IfNotInString,%Hz%bit,%Bit%
%Hz%Bit.=Bit "|"

IfNotInString,Display_WH,%WH%
Display_WH.=WH "|"
Bit:=NumGet(DM,104, "UInt") "位"
IfNotInString,Display_Bit,%Bit%
Display_Bit.=Bit "|"
Hz:=NumGet(DM,120, "UInt") "Hz"
IfNotInString,Display_Hz,%Hz%
Display_Hz.=Hz "|"
/*
if (NumGet(DM,108, "UInt")>1000 && NumGet(DM,104,"UInt")>=16 && NumGet(DM,120, "UInt")>=60) ;----wight>100 bit>=16 Hz>=60 108=wight 112=height 120=Hz 104=bit
{
Display_HzALL.=NumGet(DM,108, "UInt") "x" NumGet(DM,112, "UInt") "/" NumGet(DM,104,"UInt") "位|"
Display_bitALL.=NumGet(DM,108, "UInt") "x" NumGet(DM,112, "UInt") "/" NumGet(DM,120, "UInt") "Hz|"
Display_strALL.=NumGet(DM,108, "UInt") "x" NumGet(DM,112, "UInt") "/" NumGet(DM,104,"UInt") "位/" NumGet(DM,120, "UInt") "Hz|"
;~ EDS:=NumGet(DM,108, "UInt") "x" NumGet(DM,112, "UInt") " / " NumGet(DM,104,"UInt") "bit / " NumGet(DM,120, "UInt") "Hz"
;~ DS.=(!InStr(DS,EDS) ? "|" EDS : "")
}
*/
}
;~ MsgBox,% %Hz%Bit
;~ MsgBox,%Display_Bit%
DllCall( "EnumDisplaySettingsA", UInt,0, UInt,-1, UInt,&DM ) ;;----取得当前分辨率
WH:=NumGet(DM,108, "UInt") "x" NumGet(DM,112, "UInt")
Bit:=NumGet(DM,104, "UInt") "位"
Hz:=NumGet(DM,120, "UInt") "Hz"
If (Ra2Width<>"Error" && Ra2Width<>"Error")
StringReplace, Display_Ra2, Display_WH, %Ra2Width%x%Ra2Height%|, %Ra2Width%x%Ra2Height%||, All
StringReplace, Display_WH, Display_WH, %WH%|, %WH%||, All
StringReplace, Display_Bit, Display_Bit, %Bit%|, %Bit%||, All
StringReplace, Display_Hz, Display_Hz, %Hz%|, %Hz%||, All
;~ StringReplace, DS, DS, %CS%|, %CS%||, All
;~ Return SubStr(DS,2)
}

;;-----------------------已解决, 复制上来供有需要的人可以参考
查找这个用户的全部帖子
表示感谢 引用并回复 移动视图置页面顶端
发表回复 


论坛跳转:


联系我们 | Autohotkey 中文站 | 回到顶部 | 回到正文区 | 精简(归档)模式 | RSS 聚合