﻿;-- TIME_STAMP   2023-01-16 13:36:42


#cs
    Nutzt INI, die mit "makeINI.au3" erstellt wurde
#ce


#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListBox.au3>
#include <GuiListView.au3>
#include <WinAPIIcons.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>

Global $mSections, $hGui, $cListProg, $hLVRun, $hImage

_CreateGUI()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState(@SW_SHOW, $hGui)


While True
    Switch GUIGetMsg()
        Case -3
            _GUIImageList_Destroy($hImage)
            Exit
        Case $cListProg
            _LV_AddItemWithImage()
    EndSwitch
WEnd




Func _CreateGUI()
    Local $aAll = _INIReadAllSections()
    $mSections = $aAll[1]

    $hGui = GUICreate('Portable', 320, 595, @DesktopWidth-330, 10)

    GUICtrlCreateLabel('Programm Ordner', 10, 15)
    $cListProg = GUICtrlCreateList('', 10, 35, 300, 450, BitOR(0x00800000,0x00200000)) ; ($WS_BORDER,$WS_VSCROLL)
    GUICtrlSetData($cListProg, $aAll[0])
    _GUICtrlListBox_SetCurSel(GUICtrlGetHandle($cListProg), 0)

    Local $cLVRun = GuiCtrlCreateListView('Ausführen', 10, 495, 300, 90)
    $hLVRun = GUICtrlGetHandle($cLVRun)
    _GUICtrlListView_SetColumnWidth($hLVRun, 0, $LVSCW_AUTOSIZE_USEHEADER )

    _LV_AddItemWithImage()
EndFunc


Func _INIReadAllSections()
    Local $INI = @ScriptDir & '\' & StringTrimLeft(@ScriptDir, StringInStr(@ScriptDir, '\', 0, -1)) & '.ini'
    Local $aSections = IniReadSectionNames($INI)
    Local $map[]
    For $i = 1 To $aSections[0]
        $map[$aSections[$i]] = _newMap()
        $map[$aSections[$i]]['path'] = IniRead($INI, $aSections[$i], 'path', '')
        $map[$aSections[$i]]['run'] = IniRead($INI, $aSections[$i], 'run', '')
    Next
    Local $aRet[] = [_ArrayToString($aSections, '|', 1), $map]
    Return $aRet
EndFunc


Func _newMap()
    Local $m[]
    Return $m
EndFunc


Func _LV_AddItemWithImage()
    _GUICtrlListView_DeleteAllItems($hLVRun)
    _GUIImageList_Destroy($hImage)
    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    Local $aExe = StringSplit($mSections[GUICtrlRead($cListProg)]['run'], '|')
    Local $sPath = $mSections[GUICtrlRead($cListProg)]['path']
    Local $aIconSmall
    For $i = 1 To $aExe[0]
        If _WinAPI_ExtractIconEx($sPath & '\' & $aExe[$i], -1, 0, $aIconSmall, 0) = 0 Then
            _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 98) ; add default
        Else
            _GUIImageList_AddIcon($hImage, $sPath & '\' & $aExe[$i])
        EndIf
    Next
    _GUICtrlListView_SetImageList($hLVRun, $hImage, 1)
    For $i = 1 To $aExe[0]
        _GUICtrlListView_AddItem($hLVRun, $aExe[$i], $i-1)
    Next
EndFunc


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    If HWnd($tNMHDR.hWndFrom) = $hLVRun Then
        If $tNMHDR.Code = $NM_CLICK Then
            Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
            Local $sItem = _GUICtrlListView_GetItemText($hLVRun, $tInfo.Index)
            Exit ShellExecute($mSections[GUICtrlRead($cListProg)]['path'] & '\' & $sItem)
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
