Returns current screen resolution as WxHaF (Width x Height @ Frequency), for example: 1280x720@60
Parameter:
- Disp should be a MonitorName, eg: \\.\DISPLAY1. If Disp is omitted or is zero, primary monitor will be presumed.
ScreenResolution_List(Disp)
Returns a valid MatchList of all supported screen resolution for a monitor.
Parameter:
- Disp should be a MonitorName, eg: \\.\DISPLAY1. If Disp is omitted or is zero, primary monitor will be presumed.
Note 1: By default the function filters out entries whose frequency is less than 60Hz. Find and change this condition NumGet(DM,184,"UInt")>59 accordingly.
Note 2: If monitor is connected via a VGA port, this function will return MatchList even if the monitor is not connected to mains.
For HDMI, the monitor needs to be at least be in SOFT-OFF state.
ScreenResolution_Set(WxHaF, [Disp])
Changes screen resolution and returns 0 (DISP_CHANGE_SUCCESSFUL) when successful.
Return values
Parameters:
- WxHaF : Pass screen resolution as WxHaF (Width x Height @ Frequency), for example: 1280x720@60
- Disp should be a MonitorName, eg: \\.\DISPLAY1. If Disp is omitted or is zero, primary monitor will be presumed.
Note: If your device is has dual-display, the function will return DISP_CHANGE_SUCCESSFUL even when Disp is not part of the desktop.
It is better to test, for eg. ScreenResolution_Get("\\.\DISPLAY2") before attempting to set a resolution.
The functions:
Code: Select all
ScreenResolution_Get(Disp:=0) { ; v0.90 By SKAN on D36I/D36M @ tiny.cc/screenresolution
Local DM, N:=VarSetCapacity(DM,220,0)
Return DllCall("EnumDisplaySettingsW", (Disp=0 ? "Ptr" : "WStr"),Disp, "Int",-1, "Ptr",&DM)=0 ? ""
: Format("{:}x{:}@{:}", NumGet(DM,172,"UInt"),NumGet(DM,176,"UInt"),NumGet(DM,184,"UInt"))
}
ScreenResolution_List(Disp:=0) { ; v0.90 By SKAN on D36I/D36M @ tiny.cc/screenresolution
Local DM, N:=VarSetCapacity(DM,220,0), L:="", DL:=","
While DllCall("EnumDisplaySettingsW", (Disp=0 ? "Ptr" : "WStr"),Disp, "Int",A_Index-1, "Ptr",&DM)
If ( NumGet(DM,168,"UInt")=32 && NumGet(DM,184,"UInt")>59)
L.=Format("{:}x{:}@{:}" . DL, NumGet(DM,172,"UInt"),NumGet(DM,176,"UInt"),NumGet(DM,184,"UInt"))
Return RTrim(L,DL)
}
ScreenResolution_Set(WxHaF, Disp:=0) { ; v0.90 By SKAN on D36I/D36M @ tiny.cc/screenresolution
Local DM, N:=VarSetCapacity(DM,220,0), F:=StrSplit(WxHaF,["x","@"],A_Space)
Return DllCall("ChangeDisplaySettingsExW",(Disp=0 ? "Ptr" : "WStr"),Disp, "Ptr",NumPut(F[3]
, NumPut(F[2], NumPut(F[1], NumPut(32, NumPut(0x5C0000, NumPut(220,DM,68,"UShort")+2,"UInt")+92
, "UInt"),"UInt"),"UInt")+4,"UInt")-188, "Ptr",0, "Int",0, "Int",0)
}
Credit: Thanks to @just me. Picked required unicode structure offsets from his ChangeDisplaySettings()