Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Transparent windows


  • Please log in to reply
28 replies to this topic
numEric
  • Guests
  • Last active:
  • Joined: --
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)

#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


Wingfat
  • Members
  • 937 posts
  • Last active: Oct 14 2015 04:20 PM
  • Joined: 23 Aug 2004
Thanks this a great tool! Keep up the good work!

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
very nice work!
i specially like the tooltip bar.

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
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.

Wingfat
  • Members
  • 937 posts
  • Last active: Oct 14 2015 04:20 PM
  • Joined: 23 Aug 2004
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)

Candle
  • Members
  • 326 posts
  • Last active: May 17 2010 03:04 PM
  • Joined: 19 Aug 2004
first time I ran it , it lock my system .had to do a hard boot .

Wingfat
  • Members
  • 937 posts
  • Last active: Oct 14 2015 04:20 PM
  • Joined: 23 Aug 2004
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.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
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+.

numEric
  • Guests
  • Last active:
  • Joined: --

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 :
#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

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 :)

Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
Yes, nice scipt, well done

Wingfat
  • Members
  • 937 posts
  • Last active: Oct 14 2015 04:20 PM
  • Joined: 23 Aug 2004
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.

savage
  • Members
  • 207 posts
  • Last active: Jul 03 2008 03:12 AM
  • Joined: 02 Jul 2004

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.

  • Guests
  • Last active:
  • Joined: --
very nice thx :)

Transparent Windows
  • Guests
  • Last active:
  • Joined: --
Thanks for wonderful script. :)

st
  • Guests
  • Last active:
  • Joined: --
not working, neither. 1.0.42.03