Jump to content

Fade Window


Recommended Posts

Hello all, 

So I'm trying to write something that gives you the option to fade an open CMD window (kind of like in the windows 10 preview), using a slider; here's what I have so far:

#NoTrayIcon
#include <WinAPIProc.au3>
#include <Array.au3>
HotKeySet("!+d", "_Transpval")
HotKeySet("{Esc}", "_exit2")

$inidirexist = FileExists(@AppDataDir & "\Glass CMD")
if $inidirexist = 0 Then
    DirCreate(@AppDataDir & "\Glass CMD")
EndIf

Global $drive = ""
Global $sInipath = @AppDataDir & "\Glass CMD\config.ini"

$checkiniexist = FileExists($sInipath)
If $checkiniexist = 0 Then
    IniWrite($sInipath, "Slider", "Value", "255")
EndIf

$readval = IniRead($sInipath, "Slider", "Value", "-1")

$pid = shellexecute("cmd.exe")

$cmdTrueHandle = _WinAPI_EnumProcessWindows($pid)
_ArrayDisplay($cmdTrueHandle)
$cmdHandle = $cmdTrueHandle[1][0]

WinSetTitle($cmdHandle, "", "Command Prompt")
loopfunc()

Func loopfunc()
    While 1
        sleep(20)
    WEnd
EndFunc

Func _exit2()
    Exit
EndFunc

Func _Transpval()
    #include <GUIConstantsEx.au3>
    #include <SliderConstants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $Form2 = GUICreate("Transparency Selector", 615, 206)
    GUISetBkColor(0xA0A0A4)
    $Slider1 = GUICtrlCreateSlider(64, 96, 489, 49)
    GUICtrlSetBkColor(-1, 0xA0A0A4)
    GUICtrlSetLimit(-1, 255, 0)
    $Label1 = GUICtrlCreateLabel("Adjust Window Transparency", 0, 0, 613, 57, BitOR($SS_CENTER,$SS_CENTERIMAGE))
    GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman")
    $Label2 = GUICtrlCreateLabel("Invisible", 56, 128, 50, 19)
    GUICtrlSetFont(-1, 10, 400, 0, "Times New Roman")
    $Label3 = GUICtrlCreateLabel("Solid", 528, 128, 55, 19)
    GUICtrlSetFont(-1, 10, 400, 0, "Times New Roman")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    $OldSliderPos = IniRead($sInipath, "Slider", "Value", "-1")
    GUICtrlSetData($Slider1, $OldSliderPos)
    WinSetOnTop($Form2, "", 1)
    While 1
        $Sliderpos = GUICtrlRead($Slider1)
        If $Sliderpos <> $OldSliderPos Then
            WinSetTrans($cmdhandle, "", $Sliderpos)
        EndIf
        Sleep(10)
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                IniWrite($sInipath, "Slider", "Value", $Sliderpos)
                GUIDelete($Form2)
                loopfunc()
        EndSwitch
    WEnd
Endfunc

So it keeps giving the following error on execution and I can't for the life of me figure out why:

Subscript used on non-accessible variable.:
$cmdHandle = $cmdTrueHandle[1][0]
$cmdHandle = $cmdTrueHandle^ ERROR
 
Any help would be greatly appreciated.
Thanks in advance
Link to comment
Share on other sites

Move ALL of the #include lines out of your function and put them at the top of your script. That's the first thing I'd do.

I found out that _WinAPI_EnumProcessWindows wasn't returning any handles so your array didn't exist. Try this, I used a function from the autoit wiki to get the handle from the PID.

#NoTrayIcon
#include <WinAPIProc.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("WinTitleMatchMode", 2)
HotKeySet("!+d", "_Transpval")
HotKeySet("{Esc}", "_exit2")

$inidirexist = FileExists(@AppDataDir & "\Glass CMD")
If $inidirexist = 0 Then
    DirCreate(@AppDataDir & "\Glass CMD")
EndIf

Global $drive = ""
Global $sInipath = @AppDataDir & "\Glass CMD\config.ini"

$checkiniexist = FileExists($sInipath)
If $checkiniexist = 0 Then
    IniWrite($sInipath, "Slider", "Value", "255")
EndIf

$readval = IniRead($sInipath, "Slider", "Value", "-1")

$PID = ShellExecute("cmd.exe")

Sleep(1000) ; <<<<<<<<< Need time for the window to appear
;~ $cmdTrueHandle = _WinAPI_EnumProcessWindows($pid)
$cmdHandle = _GetHwndFromPID($PID) ; <<<<<<<<<<< get the handle of the window
;~ _ArrayDisplay($cmdTrueHandle)
;~ $cmdHandle = $cmdTrueHandle[1][0]

WinSetTitle($cmdHandle, "", "Command Prompt")
loopfunc()

Func loopfunc()
    While 1
        Sleep(20)
    WEnd
EndFunc   ;==>loopfunc

Func _GetHwndFromPID($PID)
    $hWnd = 0
    $winlist = WinList()
    Do
        For $i = 1 To $winlist[0][0]
            If $winlist[$i][0] <> "" Then
                $iPID2 = WinGetProcess($winlist[$i][1])
                If $iPID2 = $PID Then
                    $hWnd = $winlist[$i][1]
                    ExitLoop
                EndIf
            EndIf
        Next
    Until $hWnd <> 0
    Return $hWnd
EndFunc   ;==>_GetHwndFromPID

Func _exit2()
    Exit
EndFunc   ;==>_exit2

Func _Transpval()
    #Region ### START Koda GUI section ### Form=
    $Form2 = GUICreate("Transparency Selector", 615, 206)
    GUISetBkColor(0xA0A0A4)
    $Slider1 = GUICtrlCreateSlider(64, 96, 489, 49)
    GUICtrlSetBkColor(-1, 0xA0A0A4)
    GUICtrlSetLimit(-1, 255, 0)
    $Label1 = GUICtrlCreateLabel("Adjust Window Transparency", 0, 0, 613, 57, BitOR($SS_CENTER, $SS_CENTERIMAGE))
    GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman")
    $Label2 = GUICtrlCreateLabel("Invisible", 56, 128, 50, 19)
    GUICtrlSetFont(-1, 10, 400, 0, "Times New Roman")
    $Label3 = GUICtrlCreateLabel("Solid", 528, 128, 55, 19)
    GUICtrlSetFont(-1, 10, 400, 0, "Times New Roman")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    $OldSliderPos = IniRead($sInipath, "Slider", "Value", "-1")
    GUICtrlSetData($Slider1, $OldSliderPos)
    WinSetOnTop($Form2, "", 1)
    While 1
        $Sliderpos = GUICtrlRead($Slider1)
        If $Sliderpos <> $OldSliderPos Then
            WinSetTrans($cmdHandle, "", $Sliderpos)
        EndIf
        Sleep(10)
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                IniWrite($sInipath, "Slider", "Value", $Sliderpos)
                GUIDelete($Form2)
                loopfunc()
        EndSwitch
    WEnd
EndFunc   ;==>_Transpval

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...