AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Transparent windows
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
numEric
Guest





PostPosted: Thu Aug 26, 2004 3:36 pm    Post subject: Transparent windows Reply with quote

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
Back to top
Wingfat



Joined: 23 Aug 2004
Posts: 193
Location: East Bay, California USA

PostPosted: Thu Aug 26, 2004 4:46 pm    Post subject: Reply with quote

Thanks this a great tool! Keep up the good work!
Back to top
View user's profile Send private message
Rajat



Joined: 28 Mar 2004
Posts: 1718

PostPosted: Thu Aug 26, 2004 7:33 pm    Post subject: Reply with quote

very nice work!
i specially like the tooltip bar.
_________________
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Thu Aug 26, 2004 9:14 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail
Wingfat



Joined: 23 Aug 2004
Posts: 193
Location: East Bay, California USA

PostPosted: Thu Aug 26, 2004 9:36 pm    Post subject: Reply with quote

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! Cool
Back to top
View user's profile Send private message
Candle



Joined: 19 Aug 2004
Posts: 334

PostPosted: Thu Aug 26, 2004 10:06 pm    Post subject: Reply with quote

first time I ran it , it lock my system .had to do a hard boot .
Back to top
View user's profile Send private message
Wingfat



Joined: 23 Aug 2004
Posts: 193
Location: East Bay, California USA

PostPosted: Thu Aug 26, 2004 10:22 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Fri Aug 27, 2004 1:10 am    Post subject: Reply with quote

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+.
Back to top
View user's profile Send private message Send e-mail
numEric
Guest





PostPosted: Fri Aug 27, 2004 8:48 pm    Post subject: Reply with quote

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 Smile
Back to top
Jon



Joined: 28 Apr 2004
Posts: 373

PostPosted: Fri Aug 27, 2004 9:29 pm    Post subject: Reply with quote

Yes, nice scipt, well done
Back to top
View user's profile Send private message Send e-mail
Wingfat



Joined: 23 Aug 2004
Posts: 193
Location: East Bay, California USA

PostPosted: Fri Aug 27, 2004 9:37 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
savage



Joined: 02 Jul 2004
Posts: 206

PostPosted: Thu Sep 09, 2004 5:08 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message AIM Address
Guest






PostPosted: Fri May 20, 2005 8:33 pm    Post subject: Reply with quote

very nice thx Smile
Back to top
Transparent Windows
Guest





PostPosted: Thu Aug 04, 2005 7:59 pm    Post subject: Reply with quote

Thanks for wonderful script. Smile
Back to top
st
Guest





PostPosted: Tue Apr 18, 2006 3:20 am    Post subject: tried Reply with quote

not working, neither. 1.0.42.03
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group