Finally did it! This script now changes the resolution to 800x600 when the program is active, and switches back to 1280x1024 when it is not!
Thank you all for your suggestions.
Code:
Menu, TRAY, Icon, shell32.dll, 23
Menu, TRAY, Tip, Changes to 800x600`nwhen PROGRAM active.
#Persistent
GroupAdd, Program, ahk_class ui60MDIroot_W32
GroupAdd, Program, ahk_class ui60Modal_W32
EncodeInteger( p_value, p_size, p_address, p_offset )
{
loop, %p_size%
DllCall( "RtlFillMemory"
, "uint", p_address+p_offset+A_Index-1
, "uint", 1
, "uchar", ( p_value >> ( 8*( A_Index-1 ) ) ) & 0xFF )
}
SetTimer, cambia, 100
return
cambia:
IfWinActive ahk_group Program
gosub, res800
IfWinNotActive ahk_group Program
gosub, res1280
return
res1280:
If (A_ScreenWidth = 800)
{
colorDepth = 32 ; bits (quality)
screenWidth = 1280 ; pixels
screenHeight = 1024 ; pixels
refreshRate = 70 ; Hz (frequency)
; Don't change anything below!
struct_devicemode_size = 156
VarSetCapacity(device_mode, struct_devicemode_size, 0)
EncodeInteger(struct_devicemode_size, 2, &device_mode, 36)
success := DllCall("EnumDisplaySettings", "uint", 0, "uint", -1, "uint", &device_mode)
; DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT|DM_DISPLAYFREQUENCY
EncodeInteger(0x00040000|0x00080000|0x00100000|0x00400000, 4, &device_mode, 40)
EncodeInteger(colorDepth, 4, &device_mode, 104)
EncodeInteger(screenWidth, 4, &device_mode, 108)
EncodeInteger(screenHeight, 4, &device_mode, 112)
EncodeInteger(refreshRate, 4, &device_mode, 120)
DllCall("ChangeDisplaySettings", "uint", &device_mode, "uint", 0)
return
}
return
res800:
If (A_ScreenWidth <> 800)
{
colorDepth = 32 ; bits (quality)
screenWidth = 800 ; pixels
screenHeight = 600 ; pixels
refreshRate = 60 ; Hz (frequency)
; Don't change anything below!
struct_devicemode_size = 156
VarSetCapacity(device_mode, struct_devicemode_size, 0)
EncodeInteger(struct_devicemode_size, 2, &device_mode, 36)
success := DllCall("EnumDisplaySettings", "uint", 0, "uint", -1, "uint", &device_mode)
; DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT|DM_DISPLAYFREQUENCY
EncodeInteger(0x00040000|0x00080000|0x00100000|0x00400000, 4, &device_mode, 40)
EncodeInteger(colorDepth, 4, &device_mode, 104)
EncodeInteger(screenWidth, 4, &device_mode, 108)
EncodeInteger(screenHeight, 4, &device_mode, 112)
EncodeInteger(refreshRate, 4, &device_mode, 120)
DllCall("ChangeDisplaySettings", "uint", &device_mode, "uint", 0)
return
}
return