AutoHotkey Community

It is currently May 26th, 2012, 2:35 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: January 24th, 2009, 10:41 am 
Offline

Joined: January 20th, 2009, 9:35 pm
Posts: 16
the purpose of this script is to grey out any window whose pixel at location (6,140) is not white, and then fade it back in when it is. The script works great except for the fact that it seems to use up 4K of additional memory with every passthru. I suppose this has something to do with getDc/getPixel but I am too new at this to know for sure. I would appreciate any comments. Thank you!


Code:
switch := true
opacity := 100

loop
{
   WinGet, tableIDList, list, ahk_class WindowClass
   if   numWindows <> windowIDList
      refreshwindows(), numwindows := windowIDList

   loop, %windowIDList%
   {
      windowID := windowIDList%A_Index%
      hDC := windowDCList%A_Index%
      pixel := DllCall("GetPixel", "Uint", hDC, "Uint", 6, "Uint", 140)   

      if   (pixel <> 16777215) && (switch)
         winset, transparent, %opacity%, ahk_id %windowID%
      else
      {
         ;winactivate, ahk_id %windowID%
         winset, transparent, off, ahk_id %windowID%
      }
   }

   sleep 500
}   

refreshwindows()
{
   global

   loop, %windowIDList%
   {
      windowID := windowIDlist%A_INDEX%                  
      windowDCList%A_Index% := DllCall("GetDC", "Uint", windowID)
   }
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2009, 2:28 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Each call to GetDC must have a corresponding call to ReleaseDC, otherwise each device context will remain in memory until the process terminates. Eventually you may run out of GDI resources, and GetDC will fail.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2009, 3:39 am 
Offline

Joined: January 20th, 2009, 9:35 pm
Posts: 16
this is true but getDC wouldnt get run very often since the numbr of windows doesnt change very frequently. the DC was meant to be kept open.

I figured out the leak it actually had to do with this line:
if numWindows <> windowIDList

this kept being evaluated as true, i think because of the tab? not sure

i changed it to
if (numWindows <> windowIDList)

and things are now kosher. thanks for the help though!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2009, 3:47 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Ah. FAQ: When exactly are variable names enclosed in percent signs?


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: G. Sperotto, poserpro and 21 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