AutoHotkey Community

It is currently May 27th, 2012, 3:19 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 29 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Transparent windows
PostPosted: August 26th, 2004, 3:36 pm 
For those looking for an easy way to make windows transparent and control the transparency from the mouse.

Usage :
Hold down the Ctrl and Shift keys while turning the mouse wheel to change the transparency of the window the cursor is on. (The window doesn't have to be active.)
A tooltip shows the current opacity while you change it.
The script remembers the transparency level for each window as long as it is loaded.
To see the opacity level of a window, click the wheel while holding the two keys down.

Please note that the script doesn't let you set the opacity to 0% to avoid loosing windows ;o)

Code:
#SingleInstance Force
#MaxThreadsPerHotkey 10

SetBatchLines, -1
AutoTrim, Off

AlphaIncrement = 8.5

Ctrl & MButton::
   GetKeyState, ShiftState, Shift
   If ShiftState = U
   {
      Return
   }
   Gosub, WinGetTransparency
   Gosub, WinSetTransparency
   Gosub, ShowTransparencyToolTip
Return

Ctrl & WheelDown::
   GetKeyState, ShiftState, Shift
   If ShiftState = U
   {
      Return
   }
   Gosub, WinGetTransparency
   Trans0 -= 10
   Gosub, WinSetTransparency
   Gosub, ShowTransparencyToolTip
Return

Ctrl & WheelUp::
   GetKeyState, ShiftState, Shift
   If ShiftState = U
   {
      Return
   }
   Gosub, WinGetTransparency
   Trans0 += 10
   Gosub, WinSetTransparency
   Gosub, ShowTransparencyToolTip
Return

WinGetTransparency:
   MouseGetPos, , , WindowID
   If Trans_%WindowID% =
   {
      Trans_%WindowID% = 100
   }
   StringTrimRight, Trans, Trans_%WindowID%, 0
   Trans0 = %Trans%
Return

WinSetTransparency:
   WinGetClass, WindowClass, ahk_id %WindowID%
   If WindowClass = Progman
   {
      Trans0 = 100
   }
   Else If Trans0 < 10
   {
      Trans0 = 10
   }
   Else If Trans0 > 100
   {
      Trans0 = 100
   }
   a = %Trans%
   b = %Trans0%
   Trans = %Trans0%
   Trans_%WindowID% = %Trans%
   If WindowClass = Progman
   {
      Return
   }
   a *= 2.55
   Alpha0 = %a%            ; Starting Alpha
   b *= 2.55
   Alpha = %b%
   Transform, Alpha, Round, %Alpha%   ; Ending Alpha
   c = %Alpha0%            ; Init iteration var.
   d = %Alpha%
   d -= %Alpha0%         ; Range to iterate
   Transform, e, Abs, %d%
   If e > 0
   {
      f = %d%
      f /= %e%            ; Unity increment (+/- 1)
   }
   Else
   {
      f = 0
   }
   g = %f%
   g *= %AlphaIncrement%      ; Increment
   Loop
   {
      Transform, c, Round, %c%
      WinSet, Trans, %c%, ahk_id %WindowID%
      If c = %Alpha%
      {
         Break
      }
      Else If e >= %AlphaIncrement%
      {
         c += %g%
         e -= %AlphaIncrement%
      }
      Else
      {
         c = %Alpha%
      }
   }
Return

ShowTransparencyToolTip:
   h = %Trans%
   h /= 4
   i = 25
   i -= %h%
   ToolTipText = Opacity :%A_Space%
   Loop, %h%
   {
      ToolTipText = %ToolTipText%|
   }
   If h > 0
   {
      ToolTipText = %ToolTipText%%A_Space%
   }
   ToolTipText = %ToolTipText%%Trans%`%
   If i > 0
   {
      ToolTipText = %ToolTipText%%A_Space%
   }
   Loop, %i%
   {
      ToolTipText = %ToolTipText%|
   }
   ToolTip, %TooltipText%
   MouseGetPos, MouseX0, MouseY0
   SetTimer, RemoveToolTip
Return

RemoveToolTip:
   If A_TimeIdle < 1000
   {
      MouseGetPos, MouseX, MouseY
      If MouseX = %MouseX0%
      {
         If MouseY = %MouseY0%
         {
            Return
         }
      }
   }
   SetTimer, RemoveToolTip, Off
   ToolTip
Return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2004, 4:46 pm 
Offline

Joined: August 23rd, 2004, 10:06 pm
Posts: 276
Location: East Bay, California USA
Thanks this a great tool! Keep up the good work!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2004, 7:33 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
very nice work!
i specially like the tooltip bar.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2004, 9:14 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
I tried it too; it's great. I think a tiny improvement is possible. For your mouse button hotkeys, you could define them this way instead (to avoid the need for GetKeyState):

^+MButton::
^+WheelDown::
^+WheelUp::

If you would like me to post this in the script showcase I'll make a note to do so.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2004, 9:36 pm 
Offline

Joined: August 23rd, 2004, 10:06 pm
Posts: 276
Location: East Bay, California USA
Wait!!
This script locks up Terminal Services client in Windows 2000 Pro.
It works fine untill you try to make the Terminal Session transparent!!!
Be warned! 8)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2004, 10:06 pm 
Offline

Joined: August 19th, 2004, 10:53 pm
Posts: 326
first time I ran it , it lock my system .had to do a hard boot .


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2004, 10:22 pm 
Offline

Joined: August 23rd, 2004, 10:06 pm
Posts: 276
Location: East Bay, California USA
I have tried taking out the Tool Tip pop up with it and still get it to lock up my Treminal sessions. I tried compliing it to Exe and running it on other machines in my office and all have the same issue.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2004, 1:10 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Hmm. Could you try a simple script that uses only WinSet and see if that locks it up too? If it does, I'll put a warning in the help file about transparency.

By the way, the only thing "WinSet Transparent" does is:
SetWindowLong(target_window, GWL_EXSTYLE, GetWindowLong(target_window, GWL_EXSTYLE) | WS_EX_LAYERED);
MySetLayeredWindowAttributes(target_window, 0, value, LWA_ALPHA);

Both of the above are functions built into Windows 2000/XP+.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2004, 8:48 pm 
Chris wrote:
I tried it too; it's great. I think a tiny improvement is possible. For your mouse button hotkeys, you could define them this way instead (to avoid the need for GetKeyState):

^+MButton::
^+WheelDown::
^+WheelUp::

Thanks, Chris ! I always specify modifiers this way when combined with keys, but for some reason I didn't think of it when working with mouse buttons...

Regarding application lockups, I think they occur on executing "WinSet Transparent", but I was unable to reproduce them.
I have tested the script with TS Client and Citrix in XP and it worked fine with both, but maybe things are different in Win2k ? Does anyone encounter a problem similar to Wingfat's ?

Also, I noted that cmd.exe ignores transparency ; it seems this is by design.

Here is an updated version with some simplifications in the fading code :
Code:
#SingleInstance Force
#MaxThreadsPerHotkey 10

SetBatchLines, -1
AutoTrim, Off

AlphaIncrement = 8.5

^+MButton::
   Gosub, WinGetTransparency
   Gosub, WinSetTransparency
   Gosub, ShowTransparencyToolTip
Return

^+WheelDown::
   Gosub, WinGetTransparency
   Trans0 -= 10
   Gosub, WinSetTransparency
   Gosub, ShowTransparencyToolTip
Return

^+WheelUp::
   Gosub, WinGetTransparency
   Trans0 += 10
   Gosub, WinSetTransparency
   Gosub, ShowTransparencyToolTip
Return

WinGetTransparency:
   MouseGetPos, , , WindowID
   If Trans_%WindowID% =
   {
      Trans_%WindowID% = 100
   }
   StringTrimRight, Trans, Trans_%WindowID%, 0
   Trans0 = %Trans%
Return

WinSetTransparency:
   WinGetClass, WindowClass, ahk_id %WindowID%
   If WindowClass = Progman
   {
      Trans0 = 100
   }
   Else If Trans0 < 10
   {
      Trans0 = 10
   }
   Else If Trans0 > 100
   {
      Trans0 = 100
   }
   a = %Trans%
   b = %Trans0%
   Trans = %Trans0%
   Trans_%WindowID% = %Trans%
   If WindowClass = Progman
   {
      Return
   }
   a *= 2.55
   Alpha0 = %a%                         ; Init. Alpha
   b *= 2.55
   Alpha = %b%
   Transform, Alpha, Round, %Alpha%     ; Final Alpha
   c = %Alpha%
   c -= %Alpha0%
   d = %AlphaIncrement%
   If c < 0
   {
      d *= -1
   }                                    ; Signed increment
   Transform, c, Abs, %c%               ; Abs. iteration range
   Loop
   {
      Transform, Alpha0, Round, %Alpha0%
      WinSet, Trans, %Alpha0%, ahk_id %WindowID%
      If Alpha0 = %Alpha%
      {
         Break
      }
      Else If c >= %AlphaIncrement%
      {
         Alpha0 += %d%
         c -= %AlphaIncrement%
      }
      Else
      {
         Alpha0 = %Alpha%
      }
   }
Return

ShowTransparencyToolTip:
   e = %Trans%
   e /= 4
   f = 25
   f -= %e%
   ToolTipText = Opacity :%A_Space%
   Loop, %e%
   {
      ToolTipText = %ToolTipText%|
   }
   If e > 0
   {
      ToolTipText = %ToolTipText%%A_Space%
   }
   ToolTipText = %ToolTipText%%Trans%`%
   If f > 0
   {
      ToolTipText = %ToolTipText%%A_Space%
   }
   Loop, %f%
   {
      ToolTipText = %ToolTipText%|
   }
   ToolTip, %ToolTipText%
   MouseGetPos, MouseX0, MouseY0
   SetTimer, RemoveToolTip
Return

RemoveToolTip:
   If A_TimeIdle < 1000
   {
      MouseGetPos, MouseX, MouseY
      If MouseX = %MouseX0%
      {
         If MouseY = %MouseY0%
         {
            Return
         }
      }
   }
   SetTimer, RemoveToolTip, Off
   ToolTip
Return


Chris wrote:
If you would like me to post this in the script showcase I'll make a note to do so.

Sure, I'd be honored :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2004, 9:29 pm 
Offline

Joined: April 28th, 2004, 1:12 pm
Posts: 349
Yes, nice scipt, well done


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2004, 9:37 pm 
Offline

Joined: August 23rd, 2004, 10:06 pm
Posts: 276
Location: East Bay, California USA
Apon further testing with the new script and the old.
It doesn't really lock the treminal session up. More like suspends all key strokes to the TS Client, untill the next time you kit the Ctrl-Shif-MouseWheel. Then it sends what ever key string you have typed.
ex: I opened up Note Pad in TS, ran the transpara script then made the TS go down to 10% and then back to 100% I then typed: This is a test
-Nothing happned, then i once more used the Ctrl-Shit-MouseWheel, and it sent the: This is a test to the note pad.
So TS is NOT really locked. but it just doesn't like to be transparent.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2004, 5:08 pm 
Offline

Joined: July 2nd, 2004, 11:53 pm
Posts: 207
Quote:
Also, I noted that cmd.exe ignores transparency ; it seems this is by design.


Yeah, console windows are special in windows. Kinda sucks. If you want to have fancy console windows check out Console.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 20th, 2005, 8:33 pm 
very nice thx :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2005, 7:59 pm 
Thanks for wonderful script. :)


Report this post
Top
  
Reply with quote  
 Post subject: tried
PostPosted: April 18th, 2006, 3:20 am 
not working, neither. 1.0.42.03


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 29 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Stigg, tidbit and 11 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