AutoHotkey Community

It is currently May 25th, 2012, 8:54 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: November 8th, 2007, 11:41 am 
Offline

Joined: November 6th, 2007, 6:52 pm
Posts: 7
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 :oops: I thought I was doing it in "Ask for Help". Moderator, please move it there.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2007, 9:19 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
show your code with IfWinActive and we can help.

you probably want SetTimer.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2007, 9:26 am 
Offline

Joined: November 6th, 2007, 6:52 pm
Posts: 7
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




Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2007, 6:36 pm 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
You need to use IfWinActive , not #IfWinActive. The former is for executable parts of code, the latter is for hotkey definitions.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2007, 7:44 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
and also, your SetTimer has too many parameters - remove the last two.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2007, 10:12 am 
Offline

Joined: November 6th, 2007, 6:52 pm
Posts: 7
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



Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, krajan, MilesAhead, Rathgar2, rbrtryn and 5 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group