Jump to content

TaskPin


ioa747
 Share

Recommended Posts

GUI assistant to pin shortcuts to the taskbar

The first time you run the script TaskPin.au3 , it will create a executable shortcut in the script directory,  with the name TaskPin.Pin
Right-click on the shortcut and select 'pin to taskbar'

For each pin you need an ini file, which you call as a parameter in TaskPin.au3, with a help of a shortcut
The script automatically creates the shortcut, which we either pin to the taskbar, or assign to a button on another taskpin
 

More info:

Spoiler

The format of the .ini file
[GUI_Settings]                                   ; The first section is about the GUI Settings
AutoSort=False                                 ; if true the  commands are listed in alphabetical order
GuiIcon=imageres.dll, 288               ; the shortcut icon
GuiWidth=200                                    ; the GUI width
GuiMargin=3                                      ; the margin around the GUI
BtnHeight=28                                     ; the button height
BtnMargin=1                                       ; the space betwwen buttons
BtnIconSize=0                                     ; the size of button icon  0 = small icon,  1 = large icon
BtnTxtSpace="  "                                ; the space getwwen icon and text name in buttons
BtnFont=11, 400, 0, "Segoe UI"        ; the font of the buttons

[ name of the command ]
Executable= the executable path can accept  [, "parameters"]
Icon= can accept iconfile.ico   or  shell32.dll, -22   or  nothing if Executable= .exe
ToolTip= the ToolTip of the command

I updated the script so that it can accept native macro in the .ini file with

Opt("ExpandVarStrings", 1)   ; this option allows you to use variables and macros inside strings, e.g., "The value of var1 is $var1$" , "The value of @AutoItExe is @AutoItExe@"
Opt("ExpandEnvStrings", 1)   ; this option allows you to use %environment% variables inside strings, e.g., "The temp directory is: %temp%".

Tip Add some useful global macro as a variable so you can also use variables for macros in the .ini file like I did with $AutoItDir

and so

#include <StringConstants.au3>

; With
Opt("ExpandVarStrings", 1) ;0=don't expand, 1=do expand

; And
Local $AutoIt3Dir = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1)

; The
; "C:\Program Files (x86)\AutoIt3\autoit3.exe", /AutoIt3ExecuteScript "C:\Program Files (x86)\AutoIt3\Examples\Helpfile\StringRegExpGUI.au3"

; is expressed as
Local $Txt = '"@AutoItExe@", /AutoIt3ExecuteScript "$AutoIt3Dir$\Examples\Helpfile\StringRegExpGUI.au3"'

ConsoleWrite("$Txt=" & $Txt & @CRLF)

 

Useful links for building commands
https://ss64.com/nt/shell.html
https://ss64.com/nt/syntax-settings.html

 

 

TaskPin.au3

; https://www.autoitscript.com/forum/topic/211276-taskpin/
;----------------------------------------------------------------------------------------
; Title...........: TaskPin.au3
; Description.....: GUI assistant to pin shortcuts to the taskbar
; AutoIt Version..: 3.3.16.1   Author: ioa747
;----------------------------------------------------------------------------------------
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_ProductName=TaskPin.au3
#AutoIt3Wrapper_Res_Fileversion=0.0.0.8
#AutoIt3Wrapper_Res_Description=GUI assistant to pin shortcuts to the taskbar
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 6 -w 7
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#NoTrayIcon
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GuiListBox.au3>
#include <File.au3>
#include <Array.au3>
#include <Misc.au3>

Opt("ExpandVarStrings", 1) ;0=don't expand, 1=do expand
Opt("ExpandEnvStrings", 1) ;0=don't expand, 1=do expand


; Add some usefull global Macro as variable
Global $AutoIt3Dir = FileGetShortName(StringTrimRight(@AutoItExe, 12))
Global $AutoItExe = FileGetShortName(@AutoItExe)

Global $MyIni = $CmdLine[0]
If Not $MyIni Then
    ;assuming it's the first run and check
    $MyIni = FileGetShortName(StringTrimRight(@ScriptFullPath, 4) & ".ini")
Else
    $MyIni = $CmdLine[1]
EndIf

; Read the INI file for the value of 'Elements'
Global $aElements = Elements_ReadIni()
Global $MyLnk = StringTrimRight($MyIni, 4) & ".TaskPin.lnk"
If Not FileExists($MyLnk) Then
    MakeExecuteShortcut($MyIni)
EndIf

If _IsPressed("11") Then ;11 CTRL key
    TaskPin_Editor()
Else
    TaskPin_GUI()
EndIf

;----------------------------------------------------------------------------------------
Func GoToExit()
    Exit
EndFunc   ;==>GoToExit
;----------------------------------------------------------------------------------------
Func TaskPin_Editor()
    Local $TaskPinEditor = FileGetShortName(@ScriptDir & "\TaskPinEditor.au3")
    Run(FileGetShortName(@AutoItExe) & " /AutoIt3ExecuteScript " & $TaskPinEditor & " " & $MyIni)
EndFunc   ;==>TaskPin_Editor
;----------------------------------------------------------------------------------------
Func TaskPin_GUI()
    Opt("GUIOnEventMode", 1) ;0=disabled, 1=OnEvent mode enabled
    Opt("ExpandEnvStrings", 1) ;0=don't expand, 1=do expand


    Local $iGuiWidth = Int(IniRead($MyIni, "GUI_Settings", "GuiWidth", 200))
    Local $iGuiMargin = Int(IniRead($MyIni, "GUI_Settings", "GuiMargin", 3))
    Local $iBtnMargin = Int(IniRead($MyIni, "GUI_Settings", "BtnMargin", 2))
    Local $iBtnIconSize = Int(IniRead($MyIni, "GUI_Settings", "BtnIconSize", 0))
    Local $iBtnHeight = Int(IniRead($MyIni, "GUI_Settings", "BtnHeight", 28))
    Local $sBtnTxtSpace = IniRead($MyIni, "GUI_Settings", "BtnTxtSpace", " ")
    Local $sBtnFont = IniRead($MyIni, "GUI_Settings", "BtnFont", "")

    If $iGuiMargin < 0 Then $iGuiMargin = 0
    If $iGuiMargin > 50 Then $iGuiMargin = 50
    If $iBtnMargin < 0 Then $iBtnMargin = 0
    If $iBtnMargin > 10 Then $iBtnMargin = 10
    If $iBtnIconSize < 0 Then $iBtnIconSize = 0
    If $iBtnIconSize > 1 Then $iBtnIconSize = 1

    Local $iStep = $iBtnHeight + $iBtnMargin
    Local $iBtnWidth = $iGuiWidth - ($iGuiMargin * 2)

    Local $aPos = MouseGetPos()
    Local $TaskPin_GUI = GUICreate("TaskPin GUI", $iGuiWidth, ($aElements[0][0] * $iStep) + ($iGuiMargin * 2), _
            $aPos[0] - ($iGuiWidth / 2), @DesktopHeight - ($aElements[0][0] * $iStep) - ($iGuiMargin * 2), _
            $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) ; $aPos[1] - ($aElements[0][0] * $iStep) + $iGuiMargin

    GUISetOnEvent($GUI_EVENT_CLOSE, "GoToExit")

    Local $aSplit, $sIcon
    For $i = 1 To $aElements[0][0]
        $aElements[$i][4] = GUICtrlCreateButton($sBtnTxtSpace & $aElements[$i][0], $iGuiMargin, ($i * $iStep) + $iGuiMargin - $iStep, _
                $iBtnWidth, $iBtnHeight, BitOR($BS_LEFT, $BS_VCENTER, $BS_FLAT))

        Execute('GUICtrlSetFont(-1, $sBtnFont$)')
        GUICtrlSetTip(-1, $aElements[$i][3])
        GUICtrlSetOnEvent(-1, "Elements_Click")

        ; check for the icon
        $aSplit = StringSplit($aElements[$i][2], ", ", 1)
        $sIcon = $aSplit[1]
        If $aSplit[0] = 2 Then
            GUICtrlSetImage(-1, $sIcon, Int($aSplit[2]), $iBtnIconSize)
        Else
            If StringLen($aSplit[1]) = 0 Then
                $sIcon = $aElements[$i][1]
                GUICtrlSetImage(-1, $sIcon, 0, $iBtnIconSize)
            Else
                GUICtrlSetImage(-1, $sIcon, "", $iBtnIconSize)
            EndIf
        EndIf
    Next
    ;_ArrayDisplay($aElements, "$aElements")
    GUISetState(@SW_SHOW)

    ; Loop until mouse not over GUI
    ;******************************
    While 1
        If Not IsMouseOverWin($TaskPin_GUI, 50) Then ExitLoop
        Sleep(100)
    WEnd
    ;******************************

EndFunc   ;==>TaskPin_GUI
;----------------------------------------------------------------------------------------
Func IsMouseOverWin($hWnd, $iOffSet = 0)
    Local $aMPos = MouseGetPos()
    Local $aWPos = WinGetPos($hWnd)
    If $aMPos[0] > $aWPos[0] - $iOffSet _
            And $aMPos[1] > $aWPos[1] - $iOffSet _
            And $aMPos[0] < $aWPos[0] + $aWPos[2] + $iOffSet _
            And $aMPos[1] < $aWPos[1] + $aWPos[3] + $iOffSet Then
        Return True
    EndIf
    Return False
EndFunc   ;==>IsMouseOverWin
;----------------------------------------------------------------------------------------
Func Elements_Click()
    Local $aSplit
    For $i = 0 To $aElements[0][0]
        If $aElements[$i][4] = @GUI_CtrlId Then
            GUISetState(@SW_HIDE)
            $aSplit = StringSplit($aElements[$i][1], ", ", 1)
            ;ConsoleWrite("$aSplit[1]=" & $aSplit[1] & @CRLF)
            If $aSplit[0] = 2 Then
                ShellExecute($aSplit[1], $aSplit[2])
                ;ConsoleWrite("$aSplit[2]=" & $aSplit[2] & @CRLF)
            Else
                ShellExecute($aSplit[1])
            EndIf
            GoToExit()
        EndIf
    Next

EndFunc   ;==>Elements_Click
;----------------------------------------------------------------------------------------
Func Elements_ReadIni()
    Local $aArray[1][5]
    $aArray[0][0] = 0 ;index
    $aArray[0][1] = "Executable"
    $aArray[0][2] = "Icon"
    $aArray[0][3] = "ToolTip"
    $aArray[0][4] = "ID"


    ;Checks if TaskPin.ini not exists then make one.
    If $MyIni = FileGetShortName(StringTrimRight(@ScriptFullPath, 4) & ".ini") Then
        Local $iniFileExists = FileExists($MyIni)
        If Not $iniFileExists Then
            Opt("ExpandVarStrings", 0) ;0=don't expand, 1=do expand
            Opt("ExpandEnvStrings", 0) ;0=don't expand, 1=do expand

            ;Open the file for writing (append to the end of a file) and store the handle to a variable.
            Local $hFileOpen = FileOpen($MyIni, $FO_APPEND + $FO_UNICODE)
            If $hFileOpen = -1 Then
                MsgBox($MB_SYSTEMMODAL, "", "An error occurred while writing the " & $MyIni)
                Exit
            EndIf

            ;Write Example data to the ini file
            Local $sTxt = ""
            $sTxt &= "[GUI_Settings]" & @CRLF
            $sTxt &= "AutoSort=False" & @CRLF
            $sTxt &= "GuiIcon=imageres.dll, 288" & @CRLF
            $sTxt &= "GuiWidth=200" & @CRLF
            $sTxt &= "GuiMargin=3" & @CRLF
            $sTxt &= "BtnHeight=28" & @CRLF
            $sTxt &= "BtnMargin=1" & @CRLF
            $sTxt &= "BtnIconSize=0" & @CRLF
            $sTxt &= "BtnTxtSpace=""  """ & @CRLF
            $sTxt &= "BtnFont=11, 400, 0, ""Segoe UI""" & @CRLF
            $sTxt &= "[TaskPinEditor]" & @CRLF
            $sTxt &= "Executable=@AutoItExe@, /AutoIt3ExecuteScript ""@ScriptDir@\TaskPinEditor.au3"" ""$MyIni$""" & @CRLF
            $sTxt &= "Icon=wmploc.dll, -18" & @CRLF
            $sTxt &= "ToolTip=Editor for the TaskPin" & @CRLF
            $sTxt &= "[Edit INI]" & @CRLF
            $sTxt &= "Executable=""$MyIni$""" & @CRLF
            $sTxt &= "Icon=shell32.dll, -70" & @CRLF
            $sTxt &= "ToolTip=Edit This INI" & @CRLF
            $sTxt &= "[Sleep]" & @CRLF
            $sTxt &= "Executable=@AutoItExe@, /AutoIt3ExecuteLine ""Send('#1')""" & @CRLF
            $sTxt &= "Icon=shell32.dll, -28" & @CRLF
            $sTxt &= "ToolTip=Send Computer to Sleep" & @CRLF
            $sTxt &= "[Control Panel]" & @CRLF
            $sTxt &= "Executable=explorer.exe, shell:ControlPanelFolder" & @CRLF
            $sTxt &= "Icon=shell32.dll, -22" & @CRLF
            $sTxt &= "ToolTip=Display the Control Panel" & @CRLF
            $sTxt &= "[Calculator]" & @CRLF
            $sTxt &= "Executable=@WindowsDir@\System32\calc.exe" & @CRLF

            $sTxt &= "Icon=" & @CRLF
            $sTxt &= "ToolTip=Calculator" & @CRLF
            $sTxt &= "[StringRegExpGUI]" & @CRLF
            $sTxt &= "Executable=@AutoItExe@, /AutoIt3ExecuteScript ""$AutoIt3Dir$\Examples\Helpfile\StringRegExpGUI.au3""" & @CRLF
            $sTxt &= "Icon=imageres.dll, -247" & @CRLF
            $sTxt &= "ToolTip=GUI for testing various StringRegExp() patterns" & @CRLF
            $sTxt &= "[www.autoitscript.com]" & @CRLF
            $sTxt &= "Executable=https://www.autoitscript.com/forum" & @CRLF
            $sTxt &= "Icon=shell32.dll, -136" & @CRLF
            $sTxt &= "ToolTip=www.autoitscript.com/forum" & @CRLF
            $sTxt &= "[Desktop]" & @CRLF
            $sTxt &= "Executable=explorer.exe, shell:::{3080F90D-D7AD-11D9-BD98-0000947B0257}" & @CRLF
            $sTxt &= "Icon=imageres.dll, -175" & @CRLF
            $sTxt &= "ToolTip=Show Desktop" & @CRLF
            $sTxt &= "[Folders...]" & @CRLF
            $sTxt &= "Executable=@AutoItExe@, /AutoIt3ExecuteScript ""@ScriptDir@\TaskPin.au3"" ""@ScriptDir@\Folders.ini""" & @CRLF
            $sTxt &= "Icon=imageres.dll, -265" & @CRLF
            $sTxt &= "ToolTip=Favorite Folders" & @CRLF

            FileWrite($hFileOpen, $sTxt)

            ;Close the handle returned by FileOpen.
            FileClose($hFileOpen)

            ;Check for the MyFolders.ini also
            $iniFileExists = FileExists(@ScriptDir & "\Folders.ini")
            If Not $iniFileExists Then

                $hFileOpen = FileOpen(@ScriptDir & "\Folders.ini", $FO_APPEND + $FO_UNICODE)
                If $hFileOpen = -1 Then
                    MsgBox($MB_SYSTEMMODAL, "", "An error occurred while writing the Folders.ini")
                    Exit
                EndIf

                $sTxt = ""
                $sTxt &= "[GUI_Settings]" & @CRLF
                $sTxt &= "AutoSort=False" & @CRLF
                $sTxt &= "GuiIcon=imageres.dll, 264" & @CRLF
                $sTxt &= "GuiWidth=200" & @CRLF
                $sTxt &= "GuiMargin=3" & @CRLF
                $sTxt &= "BtnHeight=28" & @CRLF
                $sTxt &= "BtnMargin=1" & @CRLF
                $sTxt &= "BtnIconSize=0" & @CRLF
                $sTxt &= "BtnTxtSpace=""  """ & @CRLF
                $sTxt &= "BtnFont=11, 400, 0, ""Segoe UI""" & @CRLF
                $sTxt &= "[TaskPinEditor]" & @CRLF
                $sTxt &= "Executable=@AutoItExe@, /AutoIt3ExecuteScript ""@ScriptDir@\TaskPinEditor.au3"" ""$MyIni$""" & @CRLF
                $sTxt &= "Icon=wmploc.dll, -18" & @CRLF
                $sTxt &= "ToolTip=Editor for the TaskPin" & @CRLF
                $sTxt &= "[ScriptDir]" & @CRLF
                $sTxt &= "Executable=@ScriptDir@" & @CRLF
                $sTxt &= "Icon=shell32.dll, -68" & @CRLF
                $sTxt &= "ToolTip=ScriptDir" & @CRLF
                $sTxt &= "[HomePath]" & @CRLF
                $sTxt &= "Executable=@HomeDrive@@HomePath@" & @CRLF
                $sTxt &= "Icon=imageres.dll, -118" & @CRLF
                $sTxt &= "ToolTip=HomePath" & @CRLF
                $sTxt &= "[AutoIt3 Dir]" & @CRLF
                $sTxt &= "Executable=$AutoIt3Dir$" & @CRLF
                $sTxt &= "Icon=$AutoIt3Dir$\Icons\au3.ico" & @CRLF
                $sTxt &= "ToolTip=AutoIt3Dir" & @CRLF
                $sTxt &= "[SCITE_USERHOME]" & @CRLF
                $sTxt &= "Executable=%SCITE_USERHOME%" & @CRLF
                $sTxt &= "Icon=$AutoIt3Dir$\scite\SciTE.exe" & @CRLF
                $sTxt &= "ToolTip=SCITE_USERHOME" & @CRLF
                $sTxt &= "[AppDataDir]" & @CRLF
                $sTxt &= "Executable=@LocalAppDataDir@" & @CRLF
                $sTxt &= "Icon=imageres.dll, -158" & @CRLF
                $sTxt &= "ToolTip=AppDataDir" & @CRLF
                $sTxt &= "[Downloads]" & @CRLF
                $sTxt &= "Executable=explorer.exe, shell:Downloads" & @CRLF
                $sTxt &= "Icon=imageres.dll, -176" & @CRLF
                $sTxt &= "ToolTip=Downloads" & @CRLF
                $sTxt &= "[Documents]" & @CRLF
                $sTxt &= "Executable=explorer.exe, shell:Documents" & @CRLF
                $sTxt &= "Icon=shell32.dll, -127" & @CRLF
                $sTxt &= "ToolTip=Documents" & @CRLF
                $sTxt &= "[This PC]" & @CRLF
                $sTxt &= "Executable=explorer.exe, shell:MyComputerFolder" & @CRLF
                $sTxt &= "Icon=imageres.dll, -105" & @CRLF
                $sTxt &= "ToolTip=This PC" & @CRLF
                $sTxt &= "[TaskPin...]" & @CRLF
                $sTxt &= "Executable=@AutoItExe@, /AutoIt3ExecuteScript ""@ScriptDir@\TaskPin.au3"" ""@ScriptDir@\TaskPin.ini""" & @CRLF
                $sTxt &= "Icon=imageres.dll, -289" & @CRLF
                $sTxt &= "ToolTip=Favorite" & @CRLF

                FileWrite($hFileOpen, $sTxt)

                ;Close the handle returned by FileOpen.
                FileClose($hFileOpen)

            EndIf

            Opt("ExpandVarStrings", 1) ;0=don't expand, 1=do expand
            Opt("ExpandEnvStrings", 1) ;0=don't expand, 1=do expand

            Sleep(100)
        EndIf
    EndIf

    Local $iSort = Execute(IniRead($MyIni, "GUI_Settings", "AutoSort", False))

    ; Read the INI section names. This will return a 1 dimensional array.
    Local $aSection = IniReadSectionNames($MyIni)
    If Not @error Then
        _ArrayDelete($aSection, _ArraySearch($aSection, "GUI_Settings")) ; Removed section named [Main Settings] from the array
        $aSection[0] = UBound($aSection) - 1  ; Adjust the amount of row in the array
        If $iSort Then _ArraySort($aSection)
        For $i = 1 To $aSection[0]
            ReDim $aArray[UBound($aArray) + 1][5]
            $aArray[0][0] = $i
            $aArray[$i][0] = $aSection[$i]                                      ;"Name"
            $aArray[$i][1] = IniRead($MyIni, $aSection[$i], "Executable", "<>") ;"Executable"
            $aArray[$i][2] = IniRead($MyIni, $aSection[$i], "Icon", "<>")       ;"Icon"
            $aArray[$i][3] = IniRead($MyIni, $aSection[$i], "ToolTip", "<>")    ;"ToolTip"
        Next
    EndIf

    Return $aArray

EndFunc   ;==>Elements_ReadIni
;----------------------------------------------------------------------------------------
Func MakeExecuteShortcut($IniPath, $Suffix = ".Pin")  ; Make Execute Shortcut .execute.lnk
    Local $sDrive, $sDir, $sFileName, $sExtension
    _PathSplit($IniPath, $sDrive, $sDir, $sFileName, $sExtension)

    ; Create a constant variable in Local scope of the $Suffixcut filepath.
    Local Const $ShortFilePath = $sDrive & $sDir & $sFileName & $Suffix & ".lnk"
    Local $sArgs = ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '" "' & $IniPath & '"'

    ; Create a shortcut
    Local $aSplit = IniRead($IniPath, "GUI_Settings", "GuiIcon", "")
    If $aSplit = "" Then $aSplit = "@SystemDir@\imageres.dll, 288"
    $aSplit = StringSplit($aSplit, ", ", 1)
    Local $aIcon[3]
    $aIcon[0] = ($aSplit[1]) ? ($aSplit[1]) : ("")      ;icon
    $aIcon[1] = ""                                      ;hotkey
    $aIcon[2] = ($aSplit[2]) ? ($aSplit[2]) : ("")      ;icon number

    FileCreateShortcut(FileGetShortName(@AutoItExe), _  ;file
            $ShortFilePath, _                           ;lnk
            $sDrive & $sDir, _                          ;workdir
            $sArgs, _                                   ;args
            "Execute: " & $sFileName & $sExtension, _   ;desc
            $aIcon[0], $aIcon[1], $aIcon[2])            ;icon

EndFunc   ;==>MakeExecuteShortcut
;----------------------------------------------------------------------------------------


I also added an Editor optionally, for easy alignment and management of commands

To enter edit mode, hold down the control key while clicking on the shortcut we pinned to the taskbar
or hit the TaskPinEditor button

in version 0.0.0.7 I added the ability to the executable field to accept icons with drag & drop and adjust them accordingly
if it's a script to open it  with AutoIT,  if it's a shortcut to move it to @ScriptDir & "\lnkBackUp\"

TaskPinEditor.au3

; https://www.autoitscript.com/forum/topic/211276-taskpin/
;----------------------------------------------------------------------------------------
; Title...........: TaskPinEditor.au3
; Description.....: Editor for the TaskPin
; AutoIt Version..: 3.3.16.1   Author: ioa747
;----------------------------------------------------------------------------------------
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_ProductName=TaskPinEditor.au3
#AutoIt3Wrapper_Res_Fileversion=0.0.0.8
#AutoIt3Wrapper_Res_Description=Editor for the TaskPin
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <AutoItConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <MsgBoxConstants.au3>
#include <GuiListBox.au3>
#include <StaticConstants.au3>
#include <WinAPIDlg.au3>
#include <Misc.au3>
#include <Array.au3>
#include <File.au3>

; Add some usefull global Macro as variable
Global $AutoIt3Dir = FileGetShortName(StringTrimRight(@AutoItExe, 12))
Global $AutoItExe = FileGetShortName(@AutoItExe)

Global $hGuiEdit, $Input_Name, $Input_Exec, $Input_icon, $Input_ToolTip

Global $MyIni = $CmdLine[0]
If Not $MyIni Then
    MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, @ScriptName, "I did not find command line parameters", 10)
    GoToExit()
Else
    $MyIni = $CmdLine[1]
EndIf

; Read the INI file for the value of 'Elements'
Global $aElements = Elements_ReadIni()

Editor_GUI()

;----------------------------------------------------------------------------------------
Func GoToExit()
    Exit
EndFunc   ;==>GoToExit
;----------------------------------------------------------------------------------------
Func Editor_GUI()
    #Region ; === TaskPin Editor GUI ===
    $hGuiEdit = GUICreate($MyIni, 498, 605, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
    Local $idListBox = GUICtrlCreateList("", 5, 0, 484, 310)
    GUICtrlSetFont(-1, 11)
    GUICtrlCreateLabel("Name:", 5, 328, 45, 18)
    $Input_Name = GUICtrlCreateInput("Name", 5, 345, 405, 23)
    GUICtrlSetFont(-1, 11, 300, 0, "Consolas")
    GUICtrlCreateLabel("Executable:", 5, 377, 69, 18)
    $Input_Exec = GUICtrlCreateInput("Executable", 5, 395, 460, 60, $ES_MULTILINE)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    GUICtrlSetFont(-1, 11, 300, 0, "Consolas")
    GUICtrlSetTip(-1, "Drag and drop Executable file here" & @CRLF & "or select with ... button")
    Local $Label_Exec = GUICtrlCreateLabel("", 5, 455, 485, 54)
    GUICtrlSetFont(-1, 9, 300, 0, "Consolas")
    Local $Button_GetExec = GUICtrlCreateButton("...", 470, 395, 20, 20)
    GUICtrlSetTip(-1, "FileOpenDialog to get Executable")
    Local $Button_TestRun = GUICtrlCreateButton("▶", 470, 415, 20, 20)
    GUICtrlSetTip(-1, "Test Run")
    Local $Button_ExecInsert = GUICtrlCreateButton("|+", 470, 435, 20, 20)
    GUICtrlSetTip(-1, "First place the cursor in Executable" & @CRLF & "where the text will be inserted")
    GUICtrlCreateLabel("Icon:", 45, 514, 200, 18)
    $Input_icon = GUICtrlCreateInput("icon", 45, 532, 400, 21)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    GUICtrlSetTip(-1, "Drag and drop Icon file here" & @CRLF & "or select with ... button")
    Local $Button_GetIcon = GUICtrlCreateButton("...", 448, 532, 20, 20)
    GUICtrlSetTip(-1, "Icon Open Dialog to get Icon")
    Local $Button_IconInsert = GUICtrlCreateButton("|+", 470, 532, 20, 20)
    GUICtrlSetTip(-1, "Insert Window .dll to get Icon")
    GUICtrlCreateLabel("ToolTip:", 5, 560, 46, 18)
    $Input_ToolTip = GUICtrlCreateInput("ToolTip", 5, 578, 484, 21)
    Local $Button_Add = GUICtrlCreateButton("Add", 422, 323, 32, 32, $BS_ICON)
    GUICtrlSetTip(-1, "Add Item")
    GUICtrlSetImage(-1, "mmcndmgr.dll", -7)
    Local $Button_Remove = GUICtrlCreateButton("Remove", 422, 356, 32, 32, $BS_ICON)
    GUICtrlSetTip(-1, "Remove Item")
    GUICtrlSetImage(-1, "mmcndmgr.dll", -40)
    Local $Button_Up = GUICtrlCreateButton("Up", 457, 323, 32, 32, $BS_ICON)
    GUICtrlSetTip(-1, "Move UP")
    GUICtrlSetImage(-1, "mmcndmgr.dll", -58)
    Local $Button_Down = GUICtrlCreateButton("Down", 457, 356, 32, 32, $BS_ICON)
    GUICtrlSetTip(-1, "Move DOWN")
    GUICtrlSetImage(-1, "mmcndmgr.dll", -49)
    Local $Icon1 = GUICtrlCreateIcon("", -1, 5, 520, 32, 32)
    Local $Dummy_Exit = GUICtrlCreateDummy()

    GUISetState(@SW_SHOW)
    #EndRegion ; === TaskPin Editor GUI ===

    #Region ; === ContextMenu $idListBox ===
    Local $hBoxMenu = GUICtrlCreateContextMenu($idListBox)
    Local $Menu_Add = GUICtrlCreateMenuItem("Add Item ", $hBoxMenu)
    Local $Menu_Remove = GUICtrlCreateMenuItem("Remove Item ", $hBoxMenu)
    GUICtrlCreateMenuItem("", $hBoxMenu) ; separator    -------------------------------------
    Local $Menu_Up = GUICtrlCreateMenuItem("Move UP" & @TAB & "Shift ▲", $hBoxMenu)
    Local $Menu_Down = GUICtrlCreateMenuItem("Move DOWN" & @TAB & "Shift ▼", $hBoxMenu)
    GUICtrlCreateMenuItem("", $hBoxMenu) ; separator    -------------------------------------
    #EndRegion ; === ContextMenu $idListBox ===

    #Region === ContextMenu $Button_ExecInsert ===
    Local $hMenuExecInsert = GUICtrlCreateContextMenu($Button_ExecInsert)
    Local $aMenuExecInsert = '&&;"";@;$;(;);@TAB@;;$AutoIt3Dir$;$AutoItExe$;;@AutoItExe@, /AutoIt3ExecuteLine "Send(''#1'')";'
    $aMenuExecInsert &= '@AutoItExe@, /AutoIt3ExecuteScript "@ScriptFullPath@" "parameters";explorer.exe, "FileToExecute";'
    $aMenuExecInsert &= '@AppDataDir@;@AutoItExe@;;@ComputerName@;@DesktopDir@;@FavoritesDir@;@HomeDrive@;@HomePath@;@HomeShare@;'
    $aMenuExecInsert &= '@LocalAppDataDir@;@LogonDomain@;@MyDocumentsDir@;@ProgramFilesDir@;@ProgramsDir@;@ScriptDir@;@ScriptFullPath@;'
    $aMenuExecInsert &= '@ScriptName@;@SystemDir@;@TempDir@;@StartMenuDir@;@StartupDir@;@UserName@;@UserProfileDir@;@WindowsDir@;'
    $aMenuExecInsert &= ';@YEAR@;@MON@;@MDAY@;@WDAY@;@HOUR@;@MIN@;@SEC@;@MSEC@'

    $aMenuExecInsert = StringSplit($aMenuExecInsert, ";", 1)
    _ArrayColInsert($aMenuExecInsert, 0)
    $aMenuExecInsert[0][0] = $aMenuExecInsert[0][1]
    For $i = 1 To $aMenuExecInsert[0][0]
        $aMenuExecInsert[$i][0] = GUICtrlCreateMenuItem($aMenuExecInsert[$i][1], $hMenuExecInsert)
    Next
    #EndRegion === ContextMenu $Button_ExecInsert ===

    #Region === ContextMenu $Button_IconInsert ===
    Local $hMenuIconInsert = GUICtrlCreateContextMenu($Button_IconInsert)
    Local $aMenuIconInsert = 'imageres.dll, -1;shell32.dll, -1;wmploc.dll, -1;ddores.dll, -1;'
    $aMenuIconInsert &= 'mmcndmgr.dll, -1;ieframe.dll, -1;compstui.dll, -1;setupapi.dll, -1;netshell.dll, -1'
    $aMenuIconInsert = StringSplit($aMenuIconInsert, ";", 1)
    _ArrayColInsert($aMenuIconInsert, 0)
    $aMenuIconInsert[0][0] = $aMenuIconInsert[0][1]
    For $i = 1 To $aMenuIconInsert[0][0]
        $aMenuIconInsert[$i][0] = GUICtrlCreateMenuItem($aMenuIconInsert[$i][1], $hMenuIconInsert)
    Next
    #EndRegion === ContextMenu $Button_IconInsert ===

    Local $GUI_AccelTable[2][2] = [["+{UP}", $Menu_Up], ["+{DOWN}", $Menu_Down]]
    GUISetAccelerators($GUI_AccelTable, $hGuiEdit)

    Local $CurPos, $TmpPos, $AddNew, $mName, $NeedSave, $sFileOpenDialog
    Local $aIcon, $aTxt[6], $aCtrlRecvMsg = 0
    Local $hDLL = DllOpen("user32.dll")

    ; Add strings
    _GUICtrlListBox_BeginUpdate($idListBox)
    For $i = 1 To $aElements[0][0]
        _GUICtrlListBox_InsertString($idListBox, $aElements[$i][0])
    Next
    _GUICtrlListBox_EndUpdate($idListBox)

    _GUICtrlListBox_SetCurSel($idListBox, $aElements[0][0] - 1)
    $CurPos = _GUICtrlListBox_GetCurSel($idListBox)

    ; Get currently selected item
    GUICtrlSetData($Input_Name, $aElements[$CurPos + 1][0])
    GUICtrlSetData($Input_Exec, $aElements[$CurPos + 1][1])
    GUICtrlSetData($Label_Exec, CheckForLabel_Exec(GUICtrlRead($Input_Exec)))
    GUICtrlSetData($Input_icon, $aElements[$CurPos + 1][2])
    GUICtrlSetData($Input_ToolTip, $aElements[$CurPos + 1][3])
    CheckForTheIcon($Input_icon, $Icon1, $Input_Exec)

    Local $ID
    While 1
        If $CurPos <> $TmpPos Then
            $TmpPos = $CurPos
        EndIf

        $ID = GUIGetMsg()
        Switch $ID
            Case $GUI_EVENT_CLOSE
                GUICtrlSendToDummy($Dummy_Exit)

            Case $idListBox
                ; Get currently selected item
                $CurPos = _GUICtrlListBox_GetCurSel($idListBox)
                GUICtrlSetData($Input_Name, $aElements[$CurPos + 1][0])
                GUICtrlSetData($Input_Exec, $aElements[$CurPos + 1][1])
                GUICtrlSetData($Label_Exec, CheckForLabel_Exec($aElements[$CurPos + 1][1]))
                GUICtrlSetData($Input_icon, $aElements[$CurPos + 1][2])
                GUICtrlSetData($Input_ToolTip, $aElements[$CurPos + 1][3])
                GUICtrlSetTip($Input_Exec, "")
                GUICtrlSetTip($Input_icon, "")
                CheckForTheIcon($Input_icon, $Icon1, $Input_Exec)

                If $AddNew = True Then
                    $AddNew = False
                    GUICtrlSetTip($Input_Exec, "Drag and drop Executable file here" & @CRLF & "or select with ... button")
                    GUICtrlSetTip($Input_icon, "Drag and drop Icon file here" & @CRLF & "or select with ... button")
                    GUICtrlSetState($Input_Name, $GUI_FOCUS)
                    GUICtrlSendMsg($Input_Name, $EM_SETSEL, 0, -1)
                EndIf

            Case $Input_Name
                $aElements[$CurPos + 1][0] = GUICtrlRead($Input_Name)
                _GUICtrlListBox_ReplaceString($idListBox, $CurPos, $aElements[$CurPos + 1][0])
                _GUICtrlListBox_ClickItem($idListBox, $CurPos, "left")
                $NeedSave = True

            Case $Input_Exec
                $aElements[$CurPos + 1][1] = GUICtrlRead($Input_Exec)
                GUICtrlSetData($Label_Exec, CheckForLabel_Exec($aElements[$CurPos + 1][1]))
                If GUICtrlRead($Input_ToolTip) = "<Tip>" Then
                    GUICtrlSetData($Input_ToolTip, GUICtrlRead($Label_Exec))
                    $aElements[$CurPos + 1][3] = GUICtrlRead($Label_Exec)
                EndIf
                $NeedSave = True

            Case $Input_icon
                $aElements[$CurPos + 1][2] = GUICtrlRead($Input_icon)
                CheckForTheIcon($Input_icon, $Icon1, $Input_Exec)
                $NeedSave = True

            Case $Input_ToolTip
                $aElements[$CurPos + 1][3] = GUICtrlRead($Input_ToolTip)
                $NeedSave = True

            Case $Button_TestRun
                Elements_Run(GUICtrlRead($Input_Exec))

            Case $Button_GetExec
                GUISetState(@SW_HIDE, $hGuiEdit)
                $sFileOpenDialog = FileOpenDialog("Select to add in .ini", @ScriptDir & "\", _
                        "All (*.*)", BitOR($FD_FILEMUSTEXIST, $FD_PATHMUSTEXIST))
                If @error Then
                    MsgBox(4096, "Error", "No file was selected.", 3)
                Else
                    $aElements[$CurPos + 1][1] = Check_Executable($sFileOpenDialog)
                    GUICtrlSetData($Input_Exec, $aElements[$CurPos + 1][1])
                    $mName = StringSplit($sFileOpenDialog, "\")
                    GUICtrlSetData($Input_Name, $mName[$mName[0]])
                    $aElements[$CurPos + 1][0] = $mName[$mName[0]]
                    GUICtrlSetData($Input_ToolTip, $mName[$mName[0]])
                    $aElements[$CurPos + 1][3] = $mName[$mName[0]]
                    _GUICtrlListBox_ReplaceString($idListBox, $CurPos, $mName[$mName[0]])
                    $NeedSave = True
                EndIf
                GUISetState(@SW_SHOW, $hGuiEdit)
                _GUICtrlListBox_ClickItem($idListBox, $CurPos, "left")
                $NeedSave = True

            Case $Button_GetIcon
                $aIcon = StringSplit(GUICtrlRead($Input_icon), ", ", 1)
                If $aIcon[0] = 1 Then _ArrayAdd($aIcon, "-1", 2)
                Local $aData = _WinAPI_PickIconDlg($aIcon[1], Abs($aIcon[2]) - 1, $hGuiEdit)
                If IsArray($aData) Then
                    ;GUICtrlSetImage($idIcon, $aData[0], -(1 + $aData[1]))
                    If StringRight($aData[0], 4) = ".ico" Then
                        GUICtrlSetData($Input_icon, $aData[0])
                    Else
                        GUICtrlSetData($Input_icon, $aData[0] & ", " & - (1 + $aData[1]))
                    EndIf

                    $aElements[$CurPos + 1][2] = GUICtrlRead($Input_icon)
                    CheckForTheIcon($Input_icon, $Icon1, $Input_Exec)
                    $NeedSave = True
                    ;$aLast = $aData
                EndIf

            Case $Button_Add, $Menu_Add
                Local $sFill = "<Name>|<Path>|<icon>|<Tip>"
                If $CurPos < $aElements[0][0] - 1 Then
                    _ArrayInsert($aElements, $CurPos + 1, $sFill)
                    _GUICtrlListBox_InsertString($idListBox, "<Name>", $CurPos)
                    _GUICtrlListBox_ClickItem($idListBox, $CurPos, "left")
                Else
                    _ArrayAdd($aElements, $sFill)
                    _GUICtrlListBox_InsertString($idListBox, "<Name>")
                    _GUICtrlListBox_ClickItem($idListBox, $CurPos + 1, "left")
                EndIf
                $aElements[0][0] += 1
                $AddNew = True
                $NeedSave = True

            Case $Button_Remove, $Menu_Remove
                _GUICtrlListBox_DeleteString($idListBox, $CurPos)
                _ArrayDelete($aElements, $CurPos + 1)
                $aElements[0][0] -= 1
                If $CurPos = $aElements[0][0] - 1 Then $CurPos -= 1
                If $CurPos > 0 Then
                    _GUICtrlListBox_ClickItem($idListBox, $CurPos - 1, "left")
                Else
                    _GUICtrlListBox_ClickItem($idListBox, 0, "left")
                EndIf
                $NeedSave = True

            Case $Button_Up, $Menu_Up
                IniWrite($MyIni, "GUI_Settings", "AutoSort", False)
                If $CurPos > 0 Then
                    _ArraySwap($aElements, $CurPos + 1, $CurPos)
                    _GUICtrlListBox_SwapString($idListBox, $CurPos, $CurPos - 1)
                    $CurPos -= 1
                    _GUICtrlListBox_SetCurSel($idListBox, $CurPos)
                    $NeedSave = True
                EndIf

            Case $Button_Down, $Menu_Down
                IniWrite($MyIni, "GUI_Settings", "AutoSort", False)
                If $CurPos < $aElements[0][0] - 1 Then
                    _ArraySwap($aElements, $CurPos + 1, $CurPos + 2)
                    _GUICtrlListBox_SwapString($idListBox, $CurPos, $CurPos + 1)
                    $CurPos += 1
                    _GUICtrlListBox_SetCurSel($idListBox, $CurPos)
                    $NeedSave = True
                EndIf

            Case $GUI_EVENT_DROPPED
                If @GUI_DropId = $Input_Exec Then
                    Local $sDrive, $sDir, $sFileName, $sExtension
                    _PathSplit(@GUI_DragFile, $sDrive, $sDir, $sFileName, $sExtension)
                    Switch $sExtension
                        Case ".au3"
                            $aElements[$CurPos + 1][1] = '@AutoItExe@, /AutoIt3ExecuteScript "' & @GUI_DragFile & '"'
                            GUICtrlSetData($Input_Exec, $aElements[$CurPos + 1][1])
                            $aElements[$CurPos + 1][0] = $sFileName
                            GUICtrlSetData($Input_Name, $sFileName)
                            $aElements[$CurPos + 1][3] = $sFileName
                            GUICtrlSetData($Input_ToolTip, $sFileName)

                        Case ".lnk"
                            Local $lnkBackUp = @ScriptDir & "\lnkBackUp\"
                            $aElements[$CurPos + 1][0] = $sFileName
                            GUICtrlSetData($Input_Name, $sFileName)
                            Local $aDetails = FileGetShortcut(@GUI_DragFile)
                            $aElements[$CurPos + 1][2] = ($aDetails[4] = '' ? "" : $aDetails[4] & ", " & $aDetails[4])
                            GUICtrlSetData($Input_icon, $aElements[$CurPos + 1][2])
                            $aElements[$CurPos + 1][3] = ($aDetails[3] = '' ? $sFileName : $aDetails[3])
                            GUICtrlSetData($Input_ToolTip, $aDetails[3])
                            Local $NewFile
                            $i = 0
                            Do
                                $NewFile = $lnkBackUp & $sFileName & ($i = 0 ? "" : "_" & $i) & $sExtension
                                $i += 1
                            Until Not FileExists($NewFile)
                            FileMove(@GUI_DragFile, $NewFile, $FC_CREATEPATH)
                            $aElements[$CurPos + 1][1] = '"' & $aDetails[0] & ($aDetails[2] = '' ? '"' : '" "' & $aDetails[2] & '"')
                            GUICtrlSetData($Input_Exec, $aElements[$CurPos + 1][1])

                        Case Else
                            $aElements[$CurPos + 1][1] = '"' & @GUI_DragFile & '"'
                            GUICtrlSetData($Input_Exec, $aElements[$CurPos + 1][1])
                            $aElements[$CurPos + 1][0] = $sFileName
                            GUICtrlSetData($Input_Name, $sFileName)
                            $aElements[$CurPos + 1][3] = $sFileName
                            GUICtrlSetData($Input_ToolTip, $sFileName)

                    EndSwitch

                    _GUICtrlListBox_ReplaceString($idListBox, $CurPos, $sFileName)
                    _GUICtrlListBox_ClickItem($idListBox, $CurPos, "left")
                    $NeedSave = True

                ElseIf @GUI_DropId = $Input_icon Then
                    $aElements[$CurPos + 1][2] = @GUI_DragFile
                    GUICtrlSetData($Input_icon, @GUI_DragFile)
                    ; check for the icon
                    CheckForTheIcon($Input_icon, $Icon1, $Input_Exec)
                    $NeedSave = True
                EndIf

            Case $Button_ExecInsert
                ControlFocus($hGuiEdit, "", $Input_Exec)
                MouseClick("right")

            Case $aMenuExecInsert[1][0] To $aMenuExecInsert[$aMenuExecInsert[0][0]][0]
                ;ConsoleWrite("$ID = " & $ID & @CRLF)
                ;ControlFocus($hGuiEdit, "", $Input_Exec)
                $aCtrlRecvMsg = GUICtrlRecvMsg($Input_Exec, $EM_GETSEL)
                $aTxt[4] = (IsArray($aCtrlRecvMsg)) ? (True) : (False)

                $aTxt[0] = GUICtrlRead($Input_Exec)
                $aTxt[1] = ($aTxt[4]) ? (StringLeft($aTxt[0], $aCtrlRecvMsg[0])) : ("")
                $aTxt[2] = $aMenuExecInsert[$ID - $aMenuExecInsert[1][0] + 1][1]
                $aTxt[3] = ($aTxt[4]) ? (StringTrimLeft($aTxt[0], $aCtrlRecvMsg[1])) : ($aTxt[0])
                If $aTxt[2] = "&&" Then $aTxt[2] = "&"
                $aTxt[0] = $aTxt[1] & $aTxt[2] & $aTxt[3]
                $aTxt[1] = ($aTxt[4]) ? ($aCtrlRecvMsg[0]) : (0)
                $aTxt[2] = ($aTxt[4]) ? ($aCtrlRecvMsg[0] + StringLen($aTxt[2])) : (StringLen($aTxt[2]))

                GUICtrlSetData($Input_Exec, $aTxt[0])
                $aElements[$CurPos + 1][1] = $aTxt[0]
                GUICtrlSetData($Label_Exec, CheckForLabel_Exec($aElements[$CurPos + 1][1]))

                GUICtrlSendMsg($Input_Exec, $EM_SETSEL, $aTxt[1], $aTxt[2])
                $NeedSave = True

            Case $Button_IconInsert
                ; Set focus to the $Input_icon control.
                GUICtrlSetState($Input_icon, $GUI_FOCUS)
                ;ControlFocus($hGuiEdit, "", $Input_icon)
                MouseClick("right")

            Case $aMenuIconInsert[1][0] To $aMenuIconInsert[$aMenuIconInsert[0][0]][0]
                ;ConsoleWrite("$ID = " & $ID & @CRLF)
                GUICtrlSetData($Input_icon, $aMenuIconInsert[$ID - $aMenuIconInsert[1][0] + 1][1])
                $aElements[$CurPos + 1][2] = GUICtrlRead($Input_icon)
                CheckForTheIcon($Input_icon, $Icon1, $Input_Exec)
                $NeedSave = True

            Case $Dummy_Exit
                ExitLoop

        EndSwitch
    WEnd

    GUIDelete()
    DllClose($hDLL)

    If $NeedSave = True Then Elements_SaveIni()

EndFunc   ;==>Editor_GUI
;----------------------------------------------------------------------------------------
Func Check_Executable($sFile)
    Local $sDrive, $sDir, $sFileName, $sExtension
    _PathSplit($sFile, $sDrive, $sDir, $sFileName, $sExtension)
    Switch $sExtension
        Case ".au3"
            Return '@AutoItExe@, /AutoIt3ExecuteScript "' & $sFile & '"'

        Case ".lnk"
            Local $lnkBackUp = @ScriptDir & "\lnkBackUp\"
            GUICtrlSetData($Input_Name, $sFileName)
            Local $aDetails = FileGetShortcut($sFile)

            GUICtrlSetData($Input_icon, $aDetails[4])
            GUICtrlSetData($Input_ToolTip, $aDetails[3])
            Local $NewFile, $i = 0
            Do
                $i += 1
                $NewFile = $lnkBackUp & $sFileName & ($i = 0) ? ("") : ("_" & $i) & $sExtension
            Until Not FileExists($NewFile)
            FileMove($sFile, $NewFile, $FC_CREATEPATH)
            Return '"' & $aDetails[0] & '"' & ($aDetails[2] = "") ? ('') : (' "' & $aDetails[2] & '"')

        Case Else
            Return $sFile
    EndSwitch
EndFunc   ;==>Check_Executable
;----------------------------------------------------------------------------------------
Func Elements_Run($sFile)
    Opt("ExpandVarStrings", 1) ;0=don't expand, 1=do expand
    Opt("ExpandEnvStrings", 1) ;0=don't expand, 1=do expand

    Local $aSplit
    $aSplit = StringSplit($sFile, ", ", 1)
    If $aSplit[0] = 2 Then
        ShellExecute($aSplit[1], $aSplit[2])
    Else
        ShellExecute($aSplit[1])
    EndIf
    Opt("ExpandVarStrings", 0) ;0=don't expand, 1=do expand
    Opt("ExpandEnvStrings", 0) ;0=don't expand, 1=do expand

EndFunc   ;==>Elements_Run
;----------------------------------------------------------------------------------------
Func CheckForLabel_Exec($sFile)
    Opt("ExpandVarStrings", 1) ;0=don't expand, 1=do expand
    Opt("ExpandEnvStrings", 1) ;0=don't expand, 1=do expand

    Local $aSplit, $Result
    $aSplit = StringSplit($sFile, ", ", 1)
    If $aSplit[0] = 2 Then
        $Result = $aSplit[1] & ", " & @LF & $aSplit[2]
    Else
        $Result = $aSplit[1]
    EndIf
    Opt("ExpandVarStrings", 0) ;0=don't expand, 1=do expand
    Opt("ExpandEnvStrings", 0) ;0=don't expand, 1=do expand

    Return $Result
EndFunc   ;==>CheckForLabel_Exec
;----------------------------------------------------------------------------------------
Func CheckForTheIcon($Input_icon, $Icon1, $Input_Exec)
    Opt("ExpandVarStrings", 1) ;0=don't expand, 1=do expand
    Opt("ExpandEnvStrings", 1) ;0=don't expand, 1=do expand

    ; check for the icon
    Local $aSplit, $sIcon
    $aSplit = StringSplit(GUICtrlRead($Input_icon), ", ", 1)
    $sIcon = $aSplit[1]

    If $aSplit[0] = 2 Then
        GUICtrlSetImage($Icon1, $sIcon, Int($aSplit[2]))
    Else
        If StringLen($aSplit[1]) = 0 Then
            $sIcon = GUICtrlRead($Input_Exec)
            GUICtrlSetImage($Icon1, $sIcon, 0)
        Else
            GUICtrlSetImage($Icon1, $sIcon)
        EndIf
    EndIf
    Opt("ExpandVarStrings", 0) ;0=don't expand, 1=do expand
    Opt("ExpandEnvStrings", 0) ;0=don't expand, 1=do expand

EndFunc   ;==>CheckForTheIcon
;----------------------------------------------------------------------------------------
Func Elements_ReadIni()
    Local $iniFileExists = FileExists($MyIni)
    Local $index = 0
    Local $aArray[1][5]
    $aArray[0][0] = $index
    $aArray[0][1] = "Executable"
    $aArray[0][2] = "Icon"
    $aArray[0][3] = "ToolTip"
    ;$aArray[0][4] = "ID"

    ;Checks if .ini not GoToExit
    If Not $iniFileExists Then
        MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, @ScriptName, "I did not find command line parameters", 10)
        GoToExit()
    EndIf

    Local $iSort = Execute(IniRead($MyIni, "GUI_Settings", "AutoSort", False))

    ; Read the INI section names. This will return a 1 dimensional array.
    Local $aSection = IniReadSectionNames($MyIni)
    If Not @error Then
        _ArrayDelete($aSection, _ArraySearch($aSection, "GUI_Settings")) ; Removed section named [Main Settings] from the array
        $aSection[0] = UBound($aSection) - 1  ; Adjust the amount of row in the array
        If $iSort Then _ArraySort($aSection)
        For $i = 1 To $aSection[0]
            ReDim $aArray[UBound($aArray) + 1][5]
            $aArray[0][0] = $i
            $aArray[$i][0] = $aSection[$i]                                                ;"Name"
            $aArray[$i][1] = IniRead($MyIni, $aSection[$i], "Executable", "<Executable>") ;"Executable"
            $aArray[$i][2] = IniRead($MyIni, $aSection[$i], "Icon", "<Icon>")             ;"Icon"
            $aArray[$i][3] = IniRead($MyIni, $aSection[$i], "ToolTip", "<ToolTip>")       ;"ToolTip"
        Next
    EndIf

    Return $aArray

EndFunc   ;==>Elements_ReadIni
;----------------------------------------------------------------------------------------
Func Elements_SaveIni()
    ;Read the INI section names. This will return a 1 dimensional array.
    Local $aSection = IniReadSectionNames($MyIni)
    ;Check if an error occurred.
    If Not @error Then
        _ArrayDelete($aSection, _ArraySearch($aSection, "GUI_Settings")) ; Removed section named [Main Settings] from the array
        $aSection[0] = UBound($aSection) - 1  ; Adjust the amount of row in the array
        ;Enumerate through the array displaying the section names.
        For $i = 1 To $aSection[0]
            ;Delete the sections
            IniDelete($MyIni, $aSection[$i])
        Next
    EndIf

    Local $iSort = Execute(IniRead($MyIni, "GUI_Settings", "AutoSort", False))

    ;Write to the .ini
    If Not @error Then
        _ArrayDelete($aSection, _ArraySearch($aSection, "GUI_Settings")) ; Removed section named [Main Settings] from the array
        $aSection[0] = UBound($aSection) - 1  ; Adjust the amount of row in the array
        If $iSort Then _ArraySort($aSection)
        For $i = 1 To $aElements[0][0]
            $aSection = $aElements[$i][0] ; Name
            IniWrite($MyIni, $aSection, "Executable", $aElements[$i][1])
            IniWrite($MyIni, $aSection, "Icon", $aElements[$i][2])
            IniWrite($MyIni, $aSection, "ToolTip", $aElements[$i][3])
        Next
        ConsoleWrite("Saved the .ini file" & @CRLF)
    EndIf

EndFunc   ;==>Elements_SaveIni
;----------------------------------------------------------------------------------------

 

Please, every comment is appreciated!
leave your comments and experiences here!
Thank you very much  :)

Edited by ioa747
TaskPinEditor to 0.0.0.8 , TaskPin to 0.0.0.8

I know that I know nothing

Link to comment
Share on other sites

I beg your pardon for my very poor english


windows 11 enterprise
microsoft defender antivirus 1.403.922.0
Trojan:Script/Wacatac.B!ml

problem row
FileWrite($hFileOpen, "Executable=" & @AutoItExe & ", /AutoIt3ExecuteScript " & _
                StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & _
                "\Examples\Helpfile\StringRegExpGUI.au3" & @CRLF)

Edited by bdr529

To community goes all my regards and thanks

Link to comment
Share on other sites

4 hours ago, bdr529 said:

microsoft defender antivirus 1.403.922.0

I don't understand where this comes from.
since I haven't compiled it into an executable, and I haven't suggested it anywhere,
it means that the problem (if there is one) is on your side.

and why does this occur when he writes the line in the ini file and not when he executes it?

I understand that you mean it well, I'm just contrasting (food for thought)

I know that I know nothing

Link to comment
Share on other sites

9 hours ago, argumentum said:

I'd like it with @Macros in the INI file so that it can be portable

is there a way to read @Macro words from the .ini file?
I couldn't find a way other than StringReplace  :'(

 

#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

Example()

Func Example()

    Local $sFilePath = StringTrimRight(@ScriptFullPath, 4) & ".ini"

    IniWrite($sFilePath, "1", "Executable", '"' & @WindowsDir & '\System32\calc.exe"')
    IniWrite($sFilePath, "2", "Executable", "'" & @WindowsDir & "\System32\calc.exe'")
    IniWrite($sFilePath, "3", "Executable", @WindowsDir & "\System32\calc.exe")
    IniWrite($sFilePath, "4", "Executable", """@WindowsDir & \System32\calc.exe""")
    IniWrite($sFilePath, "5", "Executable", "@WindowsDir & '\System32\calc.exe'")
    IniWrite($sFilePath, "6", "Executable", "@WindowsDir & \System32\calc.exe")

    Local $sRead = IniRead($sFilePath, "6", "Executable", "Default Value")
    ConsoleWrite("$sRead=" & $sRead & @CRLF)

    ShellExecute($sRead)
    If @error Then
        Local $sRead2 = StringReplace($sRead, "@WindowsDir & ", @WindowsDir & "")
        ConsoleWrite("$sRead2=" & $sRead2 & @CRLF)
        ShellExecute($sRead2)

    EndIf

EndFunc   ;==>Example

 

I know that I know nothing

Link to comment
Share on other sites

2 hours ago, ioa747 said:

I couldn't find a way other than StringReplace

Neither did I. But writing to the ini with macros is better. Even invented ones like @AutoItDir are quite useful for a portable setup. :)
Maybe add another @ at the end like 
@AutoItDir@ or @WindowsDir@ . That way you would write "@WindowsDir@\System32\calc.exe" to the ini and do the StringReplace() in the script. Since we're at it add the EnvVar() too as in %temp% -thought that would be a bit more difficult to discern in code- but would make it a more flexible tool to have. :thumbsup:

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

13 hours ago, bdr529 said:

I beg your pardon for my very poor english

...hmm. Say you write an encrypted string. That would be deceptive and difficult to understand as a user, but the virus-detector would not say "hah !, found a word that say ...".
As a coder you either trust your code or abandon this thing of coding. Can't be a scary cat and seem to look like a lion at the same time. The version of windows you're using say you're a lion. Choose.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

3 hours ago, ioa747 said:
  ShellExecute($sRead)
    If @error Then

..reading the code. The string should be ready to execute with all macro translation beforehand, not after failure. More over: account for multiple possible macros in the string.

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

10 hours ago, argumentum said:

Neither did I

I expected something simple, some trick to strip the macro from the quotes,
and convert it from a string back to a macro (something like double quotes or something like that).
But I was unlucky :)

 

I finally made it more flexible like you said  B)
I updated the script so that it can accept native macro in the .ini file
 

; Add some usefull global Macro as variable
you can also use variables for macros like I did with $AutoIt3Dir, which I use in section [006]

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

Quote

; Add some usefull global Macro as variable
you can also use variables for macros like I did with $AutoIt3Dir, which I use in section [006]

Very nice tool.  Section [006] failed because is missing a double quote, fixed by using Chr(34) to add the double quotes.

FileWrite($hFileOpen, "Executable=@AutoItExe, '/AutoIt3ExecuteScript " & Chr(34) & "' & $AutoIt3Dir & '\Examples\Helpfile\StringRegExpGUI.au3" & Chr(34) & "'" & @CRLF)

 

Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

4 hours ago, Danny35d said:

Section [006] failed because is missing a double quote

strange because it works for me as it is
Don't overlook that the string first split in 2 part (if ', ' exist) and then is passed through the function Execute()

the one below works too

#include <StringConstants.au3>

Local $AutoIt3Dir = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1)

Local $Txt = "@AutoItExe, '/AutoIt3ExecuteScript ' & $AutoIt3Dir & '\Examples\Helpfile\StringRegExpGUI.au3'"

Local $aSplit, $Str1, $Str2

$aSplit = StringSplit($Txt, ", ", 1)
$Str1 = Execute($aSplit[1])
If Not $Str1 Then $Str1 = $aSplit[1]
ConsoleWrite("$Str1=" & $Str1 & @CRLF)
If $aSplit[0] = 2 Then
    $Str2 = Execute($aSplit[2])
    If Not $Str2 Then $Str2 = $aSplit[2]
    ConsoleWrite("$Str2=" & $Str2 & @CRLF)
    ShellExecute($Str1, $Str2)
Else
    ShellExecute($Str1)
EndIf

 

I know that I know nothing

Link to comment
Share on other sites

 

The same issue as before didn't work for me, changing to any line code below that includes double quotes after /AutoIt3ExecuteScript works.

Local $Txt = '@AutoItExe, /AutoIt3ExecuteScript "' & $AutoIt3Dir & '\Examples\Helpfile\StringRegExpGUI.au3"'
Local $Txt = "@AutoItExe, '/AutoIt3ExecuteScript " & Chr(34) & "' & $AutoIt3Dir & '\Examples\Helpfile\StringRegExpGUI.au3" & Chr(34) & "'"

 

image.thumb.png.feb838c853498cca873f4d78baeaacf6.png

Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

I just want to make you aware of the double quotes especially if you are manually creating the .ini file.  This is the perfect tool I needed for the missing toolbar in the Windows 11 taskbar.  I found it even better than the Windows 10 toolbar because I don't have to navigate through directories to get to the application.

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

UpDate to Version 0.0.0.4

After a bit of study and some meditation,  :)

i decided to replacing the Execute() approach, (in some cases he ate the quotes)
with the Opt("ExpandVarStrings", 1)  option (for simpler expression in the .ini file)


and so

#include <StringConstants.au3>

; With
Opt("ExpandVarStrings", 1) ;0=don't expand, 1=do expand

; And
Local $AutoIt3Dir = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1)

; The
; "C:\Program Files (x86)\AutoIt3\autoit3.exe", /AutoIt3ExecuteScript "C:\Program Files (x86)\AutoIt3\Examples\Helpfile\StringRegExpGUI.au3"

; is expressed as
Local $Txt = '"@AutoItExe@", /AutoIt3ExecuteScript "$AutoIt3Dir$\Examples\Helpfile\StringRegExpGUI.au3"'

ConsoleWrite("$Txt=" & $Txt & @CRLF)


I also added an Editor as an option, for easy alignment and management of commands

I know that I know nothing

Link to comment
Share on other sites

Nice tool and add-on for the taskbar to access some tools faster.

I like the concept - well done. 👍

The d in Folders.ini is missing. 😉

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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...