 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Jaime
Joined: 06 Nov 2007 Posts: 7
|
Posted: Thu Nov 08, 2007 10:41 am Post subject: Execute action inside IfWinActive |
|
|
Hi. I already have a script to alternate between two screen resolutions. What I need is a way to change that resolution when certain window is active, and then change back to the other one when that window is not active (foremost). I tried to define it with IfWinActive, and then inserting a GoSub to call the resolution change code, but to no avail. Any help?
Thanks for your time
EDIT: Sorry, posted in wrong forum I thought I was doing it in "Ask for Help". Moderator, please move it there. |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 8255 Location: Maywood, IL
|
Posted: Thu Nov 08, 2007 8:19 pm Post subject: |
|
|
show your code with IfWinActive and we can help.
you probably want SetTimer. _________________
(Common Answers) |
|
| Back to top |
|
 |
Jaime
Joined: 06 Nov 2007 Posts: 7
|
Posted: Fri Nov 09, 2007 8:26 am Post subject: |
|
|
I tried, but it's not quite working. The resolution changes to 800x600 even if the program is not active (foremost). Here is the part of the code I'm using:
| Code: | #Persistent
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, reschange, 100, Period, 1000
return
reschange:
#IfWinActive, ahk_class ui60
{
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
#IfWinActive
|
|
|
| Back to top |
|
 |
ManaUser
Joined: 24 May 2007 Posts: 1121
|
Posted: Fri Nov 09, 2007 5:36 pm Post subject: |
|
|
| You need to use IfWinActive , not #IfWinActive. The former is for executable parts of code, the latter is for hotkey definitions. |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 8255 Location: Maywood, IL
|
Posted: Fri Nov 09, 2007 6:44 pm Post subject: |
|
|
and also, your SetTimer has too many parameters - remove the last two. _________________
(Common Answers) |
|
| Back to top |
|
 |
Jaime
Joined: 06 Nov 2007 Posts: 7
|
Posted: Sat Nov 10, 2007 9:12 am Post subject: |
|
|
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
|
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|