PhilHibbs Posted March 15, 2010 Share Posted March 15, 2010 (edited) Just a bit of fun really - this script runs in the background and hooks the ` key to a function that switches the transparency of the window that is under the mouse. [Esc] aborts the script, or you can use the notification area icon to exit. expandcollapse popup#include <WinAPI.au3> Global $Struct = DllStructCreate($tagPoint) Opt('MustDeclareVars', 1) HotKeySet("`","ToggleTrans") HotKeySet("{Esc}","Escape") While True Sleep(10) WEnd Func Pos() DllStructSetData($Struct, "x", MouseGetPos(0)) DllStructSetData($Struct, "y", MouseGetPos(1)) EndFunc ;==>Pos Func Escape() Exit EndFunc Func ToggleTrans() Local $hWnd, $hLast, $trans Pos() $hWnd = _WinAPI_WindowFromPoint($Struct) do $hLast = $hWnd $hWnd = _WinAPI_GetParent($hLast) Until $hWnd = 0 $hWnd = $hLast $trans = WinGetTrans($hWnd) If $trans < 255 And $trans >= 0 Then WinSetTrans($hWnd, "", 255) ; Make fully opaque Else WinSetTrans($hWnd, "", 170) ; Make window semi-transparent (luminosity scale is logarithmic) EndIf EndFunc Func WinGetTrans($sTitle, $sText = "") Local $hWnd = WinGetHandle($sTitle, $sText) If Not $hWnd Then Return -1 Local $val = DllStructCreate("int") Local $aRet = DllCall("user32.dll", "int", "GetLayeredWindowAttributes", "hwnd", $hWnd, "ulong_ptr", 0, "int_ptr", DllStructGetPtr($val), "ulong_ptr", 0) If @error Or Not $aRet[0] Then Return -1 Return DllStructGetData($val, 1) EndFunc Shame it doesn't work on Command Prompt windows. Also the transparency is not inherited by child windows such as menus or dialogs. Edited March 15, 2010 by PhilHibbs Link to comment Share on other sites More sharing options...
l3ill Posted March 15, 2010 Share Posted March 15, 2010 Very Nice Phil !! This is definitely going into my box of stuff... My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
monter Posted March 15, 2010 Share Posted March 15, 2010 Just a bit of fun really - this script runs in the background and hooks the ` key to a function that switches the transparency of the window that is under the mouse. [Esc] aborts the script, or you can use the notification area icon to exit. It doesn't work for me. I can't see any GUI/window. Few years ago I tested (I think) this subject here => http://www.autoitscript.com/forum/index.php?showtopic=27605 Below updated/working script: expandcollapse popup#include <GUIConstants.au3> #include <EditConstants.au3> Const $guiW = 400 Const $guiH = 200 $solid = 1 $guiTitle = "Transparency & cursor hovering" $myGUI = GUICreate($guiTitle, $guiW, $guiH) $label = GUICtrlCreateLabel("How to avoid flickering when mouse is over the GUI?", 80, 20, 300, 17) If @OSTYPE = "WIN32_WINDOWS" Then $xponly = GUICtrlCreateLabel("This works only in Win XP/2000.", 120, 40, 200, 17) $combo = GUICtrlCreateCombo("This is resolved", 125, 60, 150, 100) $comboItem = GUICtrlSetData(-1, "by GaryFrost.") $edit = GUICtrlCreateEdit("Thank you, Gary ;-)", 100, 100, 200, 50, $ES_READONLY) $button = GUICtrlCreateButton("E&xit", 175, 160, 50, 25) GUISetState(@SW_SHOW) WinSetOnTop($guiTitle, "", 1) AdlibRegister("HoverTrans") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $button Exit EndSwitch WEnd Func HoverTrans() $hover = GUIGetCursorInfo($myGUI) ;MsgBox("", $guiTitle, "hover[0] = " & $hover[0] & @CRLF & "hover[0] = " & $hover[0], 4) Select Case $hover[0] < 0 Or $hover[1] < -30 Or $hover[0] > $guiW Or $hover[1] > $guiH If $solid Then $solid = 0 WinSetTrans($guiTitle, "", 160) EndIf Case $solid = 0 $solid = 1 WinSetTrans($guiTitle, "", 255) EndSelect EndFunc ;==>HoverTrans monter.FM [font="Tahoma;"]Full programs:[/font][font="'Microsoft Sans Serif';"] LogOnOff - keeps alive user session, after set time it performs logoff (instead of locking [acronym="Personal Computer"]PC[/acronym], useful in some corporations working with [acronym="Active Directory"]AD[/acronym]).[/font] ČharCönvěr - character set converter. [font="'Microsoft Sans Serif';"]CDTray - automated opening/closing the [acronym="Compact Disc"]CD[/acronym] tray.[/font] [font="'Microsoft Sans Serif';"]Example scripts: [/font][font="'Microsoft Sans Serif';"]RecentFolders - managing recently used folder list with combobox.[/font] [font="'Microsoft Sans Serif';"]AutoUpdater - periodic auto-checking, auto-updating and auto-relaunching newest script version.[/font] Changed host from monter.homeip.net to monter.homenet.org - replace address in my scripts to get back them to work. Link to comment Share on other sites More sharing options...
martin Posted March 15, 2010 Share Posted March 15, 2010 It doesn't work for me. I can't see any GUI/window.I think you haven't quite got it monter. There is no gui. Read the code and notice that there is a hotkey! Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
monter Posted March 16, 2010 Share Posted March 16, 2010 I think you haven't quite got it monter. There is no gui. Read the code and notice that there is a hotkey!You're right Now, I can't to turn it off 'Esc' nor '`' doesn't change the semi-transparency state monter.FM [font="Tahoma;"]Full programs:[/font][font="'Microsoft Sans Serif';"] LogOnOff - keeps alive user session, after set time it performs logoff (instead of locking [acronym="Personal Computer"]PC[/acronym], useful in some corporations working with [acronym="Active Directory"]AD[/acronym]).[/font] ČharCönvěr - character set converter. [font="'Microsoft Sans Serif';"]CDTray - automated opening/closing the [acronym="Compact Disc"]CD[/acronym] tray.[/font] [font="'Microsoft Sans Serif';"]Example scripts: [/font][font="'Microsoft Sans Serif';"]RecentFolders - managing recently used folder list with combobox.[/font] [font="'Microsoft Sans Serif';"]AutoUpdater - periodic auto-checking, auto-updating and auto-relaunching newest script version.[/font] Changed host from monter.homeip.net to monter.homenet.org - replace address in my scripts to get back them to work. Link to comment Share on other sites More sharing options...
somdcomputerguy Posted March 16, 2010 Share Posted March 16, 2010 (edited) @monter, You can exit by clicking the tray icon. Edit: @PhilHibbs, this could prove to be a handy little script for me, thanks. Edited March 16, 2010 by snowmaker - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
PhilHibbs Posted March 16, 2010 Author Share Posted March 16, 2010 You're right Now, I can't to turn it off 'Esc' nor '`' doesn't change the semi-transparency state Is the AutoIt icon still there in the notification area? If not, then you have probably closed the script which is why ` no longer does anything. If you have a semi-transparent window and you have closed the script, you need to run it again in order to toggle the transparency back off again. I have noticed that sometimes key bindings can stop working in AutoIt scripts, I think this usually happens if I have two scripts running that both try to bind the same key so that shouldn't be it - unless you ran it twice of course, I should stick that singleton pattern in. Link to comment Share on other sites More sharing options...
monter Posted March 16, 2010 Share Posted March 16, 2010 Is the AutoIt icon still there in the notification area? If not, then you have probably closed the script which is why ` no longer does anything.Probably I entered ` and then Esc, so the script closed, but semi-transparent state remained active. monter.FM [font="Tahoma;"]Full programs:[/font][font="'Microsoft Sans Serif';"] LogOnOff - keeps alive user session, after set time it performs logoff (instead of locking [acronym="Personal Computer"]PC[/acronym], useful in some corporations working with [acronym="Active Directory"]AD[/acronym]).[/font] ČharCönvěr - character set converter. [font="'Microsoft Sans Serif';"]CDTray - automated opening/closing the [acronym="Compact Disc"]CD[/acronym] tray.[/font] [font="'Microsoft Sans Serif';"]Example scripts: [/font][font="'Microsoft Sans Serif';"]RecentFolders - managing recently used folder list with combobox.[/font] [font="'Microsoft Sans Serif';"]AutoUpdater - periodic auto-checking, auto-updating and auto-relaunching newest script version.[/font] Changed host from monter.homeip.net to monter.homenet.org - replace address in my scripts to get back them to work. Link to comment Share on other sites More sharing options...
PhilHibbs Posted March 17, 2010 Author Share Posted March 17, 2010 Did you think it would remember which windows were transparant and undo it on exit? Link to comment Share on other sites More sharing options...
monter Posted March 17, 2010 Share Posted March 17, 2010 Did you think it would remember which windows were transparant and undo it on exit?I think it would be better monter.FM [font="Tahoma;"]Full programs:[/font][font="'Microsoft Sans Serif';"] LogOnOff - keeps alive user session, after set time it performs logoff (instead of locking [acronym="Personal Computer"]PC[/acronym], useful in some corporations working with [acronym="Active Directory"]AD[/acronym]).[/font] ČharCönvěr - character set converter. [font="'Microsoft Sans Serif';"]CDTray - automated opening/closing the [acronym="Compact Disc"]CD[/acronym] tray.[/font] [font="'Microsoft Sans Serif';"]Example scripts: [/font][font="'Microsoft Sans Serif';"]RecentFolders - managing recently used folder list with combobox.[/font] [font="'Microsoft Sans Serif';"]AutoUpdater - periodic auto-checking, auto-updating and auto-relaunching newest script version.[/font] Changed host from monter.homeip.net to monter.homenet.org - replace address in my scripts to get back them to work. Link to comment Share on other sites More sharing options...
PhilHibbs Posted March 17, 2010 Author Share Posted March 17, 2010 I think it would be better Here you go then. This version does not set the transparency to a fixed amount, it picks a random number on a pseudo-normal distribution (0-255 3 times averaged, roughly a bell curve). It's easy to change back to a fixed value though. expandcollapse popup#include <WinAPI.au3> #include <Misc.au3> #include <Array.au3> Global $Struct = DllStructCreate($tagPoint) Global $aWindows = "" Opt('MustDeclareVars', 1) Opt("WinTitleMatchMode", 2) ; Match substring HotKeySet("`","ToggleTrans") Local $i While Not(_IsPressed("1B")) Sleep(10) WEnd For $i = 0 To UBound( $aWindows ) - 1 WinSetTrans($aWindows[$i], "", 255) ; Make fully opaque Next Func Pos() DllStructSetData($Struct, "x", MouseGetPos(0)) DllStructSetData($Struct, "y", MouseGetPos(1)) EndFunc ;==>Pos Func ToggleTrans() Local $hWnd, $hLast, $trans, $pos Pos() $hWnd = _WinAPI_WindowFromPoint($Struct) do $hLast = $hWnd $hWnd = _WinAPI_GetParent($hLast) Until $hWnd = 0 $hWnd = $hLast $trans = WinGetTrans($hWnd) If $trans < 255 And $trans >= 0 Then WinSetTrans($hWnd, "", 255) ; Make fully opaque $pos = _ArraySearch( $aWindows, $hWnd ) If $pos >= 0 Then _ArrayDelete( $aWindows, $pos ) EndIf Else WinSetTrans($hWnd, "", (Random(0,255,1)+Random(0,255,1)+Random(0,255,1))/3) ; Make window semi-transparent _ArrayAdd1( $aWindows, $hWnd ) EndIf EndFunc Func WinGetTrans($sTitle, $sText = "") Local $hWnd = WinGetHandle($sTitle, $sText) If Not $hWnd Then Return -1 Local $val = DllStructCreate("int") Local $aRet = DllCall("user32.dll", "int", "GetLayeredWindowAttributes", "hwnd", $hWnd, "ulong_ptr", 0, "int_ptr", DllStructGetPtr($val), "ulong_ptr", 0) If @error Or Not $aRet[0] Then Return -1 Return DllStructGetData($val, 1) EndFunc Func _ArrayAdd1( ByRef $avArray, $vValue ) Local $iUBound = UBound($avArray) If Not(IsArray($avArray)) Or UBound($avArray, 0) <> 1 Then Dim $TempArray[1] $avArray = $TempArray $iUBound = 0 Else ReDim $avArray[$iUBound + 1] EndIf $avArray[$iUBound] = $vValue Return $iUBound EndFunc Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now