JustMeAgain Posted March 30, 2006 Share Posted March 30, 2006 This has probably been submitted about 3,497,103 times so what's 3,497,104 times? I think the comments pretty much tell it all. This might work for W2k3 and Vista, but I haven't tried it out. I have only tested this on my XP SP2 PC and not w2k. I only put put w2k as a valid OS b/c the help file said it would work. If someone could tell me a better way to... 1. figure out which program the user had "runtransparent" launch (WinSetTrans requires a window title) and 2. how to wait for the GUI to show up before searching for the all the window titles or setting the window transparency, I'd appreciate it. I'm currently sleeping for 1 second which isn't a great way to do this. Also, is there a way to use the Win* commands using the process ID instead of the window title? That would help for # 2 above. I'll see what replies I get here before posting to the support forum. Thanks! expandcollapse popup; runtranparent ; ; AutoIt Version: 3.1.1.0 ; ; Language: English ; ; Description: ; Launch applications and make them transparent after launching. ; This works on Windows 2000 amd XP. Change $validOS for future OS support. ; ; Parameters (Six are required): ; -r <application> | /r <application> for the application to run ; -t <transparency value> | /t <transparency value> for how transparent to make the window ; If there are not four parameters, then the help is displayed. An application with spaces ; in the path or with command line parameters should be enclosed in quotes. Transparency ; values are 0-255 with the higher the number the less transparent the window. ; CAUTION: a very low transparency number can make your window virtually invisable. ; ; Usage: ; runtransparent -r notepad.exe -t 130 ; ; Background: ; Windows 2000 and higher supports transparency although you can't access this feature through ; Windows itself that I know of. You can buy 3rd party desktop replacements for Windows that ; support transparency. ; OSX and Linux also support transparency. For example, if you run KDE or Gnome in Linux, you ; set the shell prompt to be transparent. ; In order to give a Windows user some of this functionality I wrote this simple program using ; the ever powerful AutoIt language, which can be found at http://www.autoitscript.com/autoit3. ; ; Version 1.0.0 - 03/30/2006 - JAH AutoItSetOption("TrayIconHide", 1) Dim $version = "1.0.0" ;Program version. Call("main") Func main() ; This function is called first by AutoIt when the programs runs. ; - Turn off AutoIt fatal errors. ; - Hide the AutoIt tray icon. ; - Set the valid Windows versions that support transparency. ; - Verify the running OS supports transparency. ; - Get the command line parameters the user passed and verify they are correct. ; - Run the user's program with transparency. ; - Exit. Local $options[2] ;Parameters used to launch the user's program. Local $validOS[2] ;Array to hold the valid OSes. $validOS[0] = "WIN_2000" $validOS[1] = "WIN_XP" verifyOS($validOS) $options = Call("getParms") launch($options) Call("end") EndFunc Func verifyOS($OS) ; Verify the running OS supports transparency. ; If not, notify the user and exit. ; $OS = the array of valid OSes. For $i = 0 to UBound($OS) -1 Step 1 If @OSVersion = $OS[$i] Then Return Next ; If you didn't return, then your running an unsupported version of Windows. MsgBox(16+4096, @ScriptName & " " & $version & " ERROR", _ "ERROR: Invalid OS - " & @OSVersion & "." & @CRLF & _ "You are running an version of Windows that does not support transparency." & @CRLF & _ "Upgrade Windows to and try again. Exiting now.") Call("end") EndFunc Func getParms() ; Get the command line parameters and return them in an array. ; If the user requests help, then show the help and exit. Local $clp[2] ;Command line parameters to return. Local $validR = 0 ;Verify the user passed the -r|/r parameters. Local $validT = 0 ;Verify the user passed the -t|/t parameters. If $CmdLine[0] <> 4 Then ;There can only be 6 parameters. Any more or less is an error. Call("showHelp") Else For $i = 1 to $CmdLine[0] Step 1 If $CmdLine[$i] = "-r" Or $CmdLine[$i] = "/r" Then $clp[0] = $CmdLine[$i+1] $validR = 1 ElseIf $CmdLine[$i] = "-t" Or $CmdLine[$i] = "/t" Then $clp[1] = $CmdLine[$i+1] $validT = 1 EndIf Next EndIf If Not $validR Or Not $validT Then Call("showHelp") Else Return($clp) EndIf EndFunc Func showHelp() ; Display the help if requested by the user or there were not any command line parameters MsgBox(64, @ScriptName & " " & $version & " Help", _ "This program will run a program with transparency set. NOTE: Some programs" & @CRLF & _ "may not support transparency or " & @ScriptName & " may not be able to set" & @CRLF & _ "the transparency of the program that was run." & @CRLF & @CRLF & _ "The following are command line parameters that must be used." & @CRLF & @CRLF & _ " -r <application> | /r <application> = The application to run with transparency." & @CRLF & _ " -title <window title> | /title <window title> = The exact title of the window that is run." & @CRLF & _ " -t <transparency value> | /t <transparency value> = Transparency value ." & @CRLF & _ " Transparency values range from 0-255, where a larger number is more transparent." & @CRLF & @CRLF & _ "Examples:" & @CRLF & @CRLF & _ " " & @ScriptName & " -r cmd.exe -title ""C:\WINDOWS\system32\cmd.exe"" -t 200 = Run cmd.exe with a transparency value of 200." & @CRLF & _ " " & @ScriptName & " /r ""C:\Program Files\AutoIt3\AU3Info.exe"" /title ""AutoIt v3 Active Window Info"" /t 150 = Run" & @CRLF & _ " ""C:\Program Files\AutoIt3\AU3Info.exe"" with a transparency value of 150." & @CRLF & @CRLF & _ "NOTE: You can create a shortcut to " & @ScriptName & " with the parameters already set" & @CRLF & _ "so you run a program with the same transparency value every time." & @CRLF & @CRLF & _ "CAUTION: a very low transparency number can make your window virtually invisable.") Call("end") EndFunc Func launch($opts) ; Verify the specified program exists. If not, exit. ; If so, run the program with the transparency the user specified. ; $opts[0] = the program to run. ; $opts[1] = the transparency value. $pid = Run($opts[0]) If Not $pid Then If Not FileExists($opts[0]) Then MsgBox(16+4096, @ScriptName & " " & $version & " ERROR", _ "ERROR: Unable to find " & $opts[0] & "." & @CRLF & _ "Verify the following:" & @CRLF & _ " 1. The path and program name are correct." & @CRLF & _ " 2. The program is in the path if a path was not given." & @CRLF & _ " 3. You have permissions/access to the program." & @CRLF & _ "Exiting now.") Call("end") Else MsgBox(16+4096, @ScriptName & " " & $version & " ERROR", _ "ERROR: Unable to launch " & $opts[0] & "." & @CRLF & _ "Verify the following:" & @CRLF & _ " 1. The program runs properly without using " & @ScriptName & "." & @CRLF & _ " 2. The program is installed properly." & @CRLF & _ " 3. The program does not require parameters that are missing." & @CRLF & _ "Exiting now.") Call("end") EndIf Else Sleep(1000) ;Give the window a second to open. $titles = WinList("") ;Get the titles of all the open windows. For $i = 0 To UBound($titles) -1 Step 1 If WinGetProcess($titles[$i][0]) = $pid Then WinSetTrans($titles[$i][0], "", $opts[1]) ;Make the $opts[0] window transparent. Return EndIf Next EndIf MsgBox(48+4096, @ScriptName & " " & $version & "ERROR", _ "ERROR: Unable to find the window with process ID " & $pid & " to make transparent." & @CRLF & _ "Possible causes:" & @CRLF & _ " 1. " & $opts[0] & " may not have a window/GUI." & @CRLF & _ " 2. The window took too long to open." & @CRLF & _ " 3. " & $opts[0] & " may launch another process that runs the GUI.") Return EndFunc Func end() ; Future cleanup steps needed before exiting can be put here. Exit 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