;-- TIME_STAMP   2017-11-23 03:43:12   v 0.1

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#Region    ;************ Includes ************
#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <GUIImageList.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>
#include <WinAPIRes.au3>
#include <WinAPIShellEx.au3>
#include <WinAPIvkeysConstants.au3>
#EndRegion ;************ Includes ************

Opt('MustDeclareVars', 1)
OnAutoItExitRegister('_Exit')

#Region Global
Global $g_aResources = [ _
		[23, '%windir%\system32\accessibilitycpl.dll', 'Icons for Accessibility Features in Windows 10'], _
		[100, '%windir%\system32\compstui.dll', 'Icons for Common Property Sheet User Interface'], _
		[19, '%windir%\system32\comres.dll', 'Icons for COM+ Resources'], _
		[141, '%windir%\system32\ddores.dll', 'Icons for Device Category Information and Resources'], _
		[20, '%windir%\system32\dmdskres.dll', 'Icons for Disk Management Support Snap-In'], _
		[35, '%windir%\system32\dsuiext.dll', 'Icons for Directory Service Common UI'], _
		[14, '%windir%\system32\gameux.dll', 'Few Gaming related Icons'], _
		[100, '%windir%\system32\ieframe.dll', 'Icons for Internet Explorer'], _
		[411, '%windir%\System32\imageres.dll', 'Icons for Windows Image Resource'], _
		[128, '%windir%\system32\mmcndmgr.dll', 'Icons for Microsoft Management Console Node Manager'], _
		[17, '%windir%\system32\mmres.dll', 'Icons for General Audio Resources'], _
		[112, '%windir%\system32\moricons.dll', 'Icons for Windows NT Setup'], _
		[13, '%windir%\system32\netcenter.dll', 'Icons for Network related Settings and Features'], _
		[164, '%windir%\system32\netshell.dll', 'Icons for Network Connections Shell'], _
		[19, '%windir%\system32\networkexplorer.dll', 'Another .dll file with a few Network related Icons'], _
		[37, '%windir%\system32\pifmgr.dll', 'Icons for Windows NT PIF Manager'], _
		[34, '%windir%\system32\pnidui.dll', 'Icons for Network System'], _
		[19, '%windir%\system32\mstsc.exe', 'Icons for Remote Desktop Connection Client'], _
		[12, '%windir%\system32\mstscax.dll', 'Icons for Remote Desktop Services ActiveX Client'], _
		[21, '%windir%\system32\sensorscpl.dll', 'Few Icons for different Kinds of Sensors'], _
		[60, '%windir%\system32\setupapi.dll', 'Icons for Windows Setup API'], _
		[2, '%windir%\system32\shdocvw.dll', 'Icons for Shell Doc Object and Control Library'], _
		[325, '%windir%\system32\shell32.dll', 'Icons for Windows Shell Common'], _
		[17, '%windir%\system32\urlmon.dll', 'Icons for OLE32 Extension for Win32'], _
		[21, '%windir%\system32\wiashext.dll', 'Icons for Imaging Devices Shell Folder UI'], _
		[188, '%windir%\system32\wmploc.dll', 'Icons for Windows Media Player Resources'], _
		[21, '%windir%\system32\wpdshext.dll', 'Icons for Portable Devices Shell Extension'], _
		[20, '%TC%\PLUGINS\Media\XnView\xnview.exe', 'Associated Icons from Picture viewer'], _
		[39, '%windir%\system32\mspaint.exe', 'Associated Icons from Picture editor'], _
		[1, '%TC%\PLUGINS\Media\Gimp\Bin\Gimp\bin\gimp-2.8.exe', 'Associated Icons from Picture editor'], _
		[28, '%systemroot%\explorer.exe', 'Associated Icons from Explorer']]
Global Enum $eIconCount, $ePath, $eComment

Global Const $g_sIniFile = @ScriptDir & '\ExtractIcon.ini'
Global $g_sSavePath, $g_aIconSize = [256, 128, 64, 48, 32, 24, 16], $g_iIconX = $g_aIconSize[2], $g_iIconY = $g_aIconSize[2]

Global $g_iWidth = 544, $g_iHeight = 744, $g_iLeft, $g_iTop, $g_hGui, $idLabel_Comment, $g_idListview, $g_hListView, $g_hImageList, $g_iHotItem = 0, $g_iHotSubItem = 0, $g_iResourceID = IniRead($g_sIniFile, 'Global', 'ResourceID', 11)
#EndRegion Global

_Main()

Func _Main()

	_LoadIni()

	#Region GUI Create
	$g_hGui = GUICreate(StringReplace(@ScriptName, '.au3', '()'), $g_iWidth, $g_iHeight, $g_iLeft, $g_iTop, -1, $WS_EX_TOPMOST)
	GUISetBkColor(0x000080, $g_hGui)

	Local $idLabel = GUICtrlCreateLabel('Press F5 to save the selected Icons', 10, 5, $g_iWidth - 20, 44)
	GUICtrlSetFont(-1, 24, 900, 0, 'Segoe UI')
	GUICtrlSetColor(-1, 0xAFEEEE)

	GUICtrlCreateLabel('SavePath: ', 10, 55, 90, 22)
	GUICtrlSetFont(-1, 14, 900, 0, 'Segoe UI')
	GUICtrlSetColor(-1, 0xAFEEEE)
	Local $idInput_SavePath = GUICtrlCreateInput($g_sSavePath, 110, 55, $g_iWidth - 180)
	GUICtrlSetFont(-1, 10, 900, 0, 'Segoe UI')
	Local $aPos = ControlGetPos($g_hGui, '', $idInput_SavePath)
	Local $idButton_SavePath = GUICtrlCreateButton('...', $g_iWidth - 60, 53, 50, $aPos[3] + 4)
	GUICtrlSetFont(-1, 12, 900, 0, 'Segoe UI')
	GUICtrlSetColor(-1, 0xAFEEEE)

	Local $sCombo = $g_aResources[0][$ePath]
	GUICtrlCreateLabel('Resource: ', 10, 80, 90)
	GUICtrlSetFont(-1, 14, 900, 0, 'Segoe UI')
	GUICtrlSetColor(-1, 0xAFEEEE)
	Local $idCombo_Resource = GUICtrlCreateCombo($g_aResources[$g_iResourceID][$ePath], 110, 80, $g_iWidth - 180)
	GUICtrlSetFont(-1, 10, 900, 0, 'Segoe UI')
	Local $aPos = ControlGetPos($g_hGui, '', $idCombo_Resource)
	For $i = 1 To UBound($g_aResources) - 1 Step 1
		$sCombo &= '|' & $g_aResources[$i][$ePath]
	Next
	GUICtrlSetData($idCombo_Resource, $sCombo)
	Local $idButton_LoadResource = GUICtrlCreateButton('...', $g_iWidth - 60, 78, 50, $aPos[3] + 4)
	GUICtrlSetFont(-1, 12, 900, 0, 'Segoe UI')
	GUICtrlSetColor(-1, 0xAFEEEE)

	$idLabel_Comment = GUICtrlCreateLabel('', 10, 115, $g_iWidth - 20, 28)
	GUICtrlSetFont(-1, 14, 900, 0, 'Segoe UI')
	GUICtrlSetColor(-1, 0xAFEEEE)

	$g_idListview = GUICtrlCreateListView('ID', 10, 145, $g_iWidth - 20, $g_iIconY, $LVS_SHOWSELALWAYS)
	$g_hListView = GUICtrlGetHandle($g_idListview)
	_GUICtrlListView_SetExtendedListViewStyle($g_idListview, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $WS_EX_CLIENTEDGE, $LVS_EX_DOUBLEBUFFER, $LVS_EX_INFOTIP, $LVS_EX_BORDERSELECT, $LVS_EX_TRACKSELECT))
	_GUICtrlListView_SetColumnWidth($g_idListview, 0, $g_iWidth - 42)
	_GUICtrlListView_JustifyColumn($g_idListview, 0, 1)

	; BRG-Color!!!
	_GUICtrlListView_SetBkColor($g_idListview, 0xCD5A6A)
	_GUICtrlListView_SetOutlineColor($g_idListview, 0x0000FF)
	_GUICtrlListView_SetTextBkColor($g_idListview, 0x800000)
	_GUICtrlListView_SetTextColor($g_idListview, 0xD7EBFA)

	$g_hImageList = _GUIImageList_Create($g_iIconX, $g_iIconY, 5, 1)
	_GUICtrlListView_SetImageList($g_idListview, $g_hImageList, 1)
	GUICtrlSetFont($g_idListview, 24, 800, 0, 'Courier New')

	Local $idButton_Exit = GUICtrlCreateButton('Exit', 10, $g_iHeight - 50, $g_iWidth - 20, 44)
	GUICtrlSetFont(-1, 12, 900, 0, 'Segoe UI')

	Local $idSaveIconKey = GUICtrlCreateDummy(), $aAccelKeys[1][2] = [["{F5}", $idSaveIconKey]]
	GUISetAccelerators($aAccelKeys)

	_LoadResourceIcons($g_aResources[$g_iResourceID][$ePath])
;~ 	$g_iResourceID = @extended

	GUISetState(@SW_SHOW)
	#EndRegion GUI Create

	_GUICtrlListView_SetItemSelected($g_idListview, 1, True, True)
	_GUICtrlListView_SetHoverTime($g_idListView, 1)

	GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

	Local $iLVHeigth = _GUICtrlListView_ApproximateViewHeight($g_idListview, 7)
	_WinAPI_SetWindowPos(GUICtrlGetHandle($g_idListview), $HWND_NOTOPMOST, 10, 145, $g_iWidth - 20, $iLVHeigth, $SWP_NOZORDER)

	ControlFocus($g_hGui, '', $g_idListview)

	#Region - GUI SwitchLoop
	Local $sPath, $sName, $sResource, $hIcon, $iItemCount, $iIndex, $iSelectedIndices, $aSelectedIndices, $aPos
	While 1
		Switch GUIGetMsg()
			Case $GUI_EVENT_CLOSE, $idButton_Exit
				ExitLoop
			Case $idInput_SavePath
				$sPath = GUICtrlRead($idInput_SavePath)
				If FileExists($sPath) Then
					$g_sSavePath = $sPath
					ConsoleWrite('+ SavePath wurde aktualisiert: ' & $g_sSavePath & @CRLF)
				Else
					ConsoleWrite('! Der Pfad ' & $sPath & ' existiert nicht!' & @CRLF)
				EndIf
			Case $idButton_SavePath
				Local $sPath = FileSelectFolder('Select a folder', '', 0, $g_sSavePath, $g_hGui)
				If $sPath <> '' Then
					$g_sSavePath = $sPath
					ConsoleWrite('+ SavePath wurde aktualisiert: ' & $g_sSavePath & @CRLF)
					GUICtrlSetData($idInput_SavePath, $g_sSavePath)
				EndIf
			Case $idSaveIconKey
				$iItemCount = _GUICtrlListView_GetItemCount($g_idListview)
				For $i = 0 To $iItemCount -1 Step 1
					If Not _GUICtrlListView_GetItemChecked($g_idListview, $i) Then ContinueLoop
					$hIcon = _WinAPI_Create32BitHICON(_GUIImageList_GetIcon($g_hImageList, $i, 0))
					$sName = StringFormat('%s%s_%03i.ico', $g_sSavePath, _WinAPI_PathStripPath($g_aResources[$g_iResourceID][$ePath]), $i)
					If FileExists($sName) Then
						ConsoleWrite('- Icon existiert bereits: ' & $sName & @CRLF)
					Else
						ConsoleWrite('+ Save Icon: ' & $sName & @CRLF)
						_WinAPI_SaveHICONToFile($sName, $hIcon)
						_WinAPI_DestroyIcon($hIcon)
					EndIf
					_GUICtrlListView_SetItemChecked($g_idListview, $i, False) ; clear checkbox
				Next
			Case $idButton_LoadResource
				$sResource = FileOpenDialog('Select a file', '', 'All (*.*)', $FD_FILEMUSTEXIST, '', $g_hGui)
				$iIndex = _ArraySearch($g_aResources, $sResource, 0, 0, 0, 1, 1, $ePath)
				If $iIndex = -1 Then
					$hIcon = _WinAPI_ExtractIcon($sResource, 0, False)
					If $hIcon = 0 Then
						ConsoleWrite('Diese Resource enthält keine Icons! --> ' & $sResource & @CRLF)
					Else
						ConsoleWrite('New Resource = ' & $sResource & @CRLF)
						_WinAPI_DestroyIcon($hIcon)
						$iIndex = _ArrayAdd($g_aResources, StringFormat('%i|%s|%s', 1, $sResource, InputBox('ExtractIcon', 'Willst du einen Kommentar für diese Resource hinzufügen?', '', '', 340, 120)))
						_ArrayDisplay($g_aResources, '$g_aResources')
						$g_aResources[$iIndex][$eIconCount] = _LoadResourceIcons($sResource)
						$g_iResourceID = @extended
						$iIndex = _GUICtrlComboBox_AddString($idCombo_Resource, $sResource)
						_GUICtrlComboBox_SetCurSel($idCombo_Resource, $iIndex)
					EndIf
				Else
					ConsoleWrite('Diese Resource wurde bereits hinzugefügt! --> ' & $sResource & @CRLF)
				EndIf
			Case $idCombo_Resource
				$sResource = GUICtrlRead($idCombo_Resource)
				ConsoleWrite('$idCombo_Resource = ' & $sResource & @CRLF)
				_LoadResourceIcons($sResource)
				$g_iResourceID = @extended
		EndSwitch
	WEnd
	#EndRegion - GUI SwitchLoop
EndFunc

Func _LoadResourceIcons($sResource)
	Local Static $iLastIndex
	Local $hIcon, $iIconCount = 0, $k = 0, $l = '', $m = 0, $n = 20000, $o = 1, $sName = _WinAPI_PathStripPath($sResource)
	Local $iIndex = _ArraySearch($g_aResources, $sResource, 0, 0, 0, 1, 1, $ePath)
	If $iLastIndex == $iIndex Then Return
	$iLastIndex = $iIndex

	_GUICtrlListView_DeleteAllItems($g_idListview)
	_GUIImageList_Destroy($g_hImageList)
	$g_hImageList = _GUIImageList_Create($g_iIconX, $g_iIconY, 5, 1)
	_GUICtrlListView_SetImageList($g_idListview, $g_hImageList, 1)

	GUICtrlSetData($idLabel_Comment, $g_aResources[$iIndex][$eComment])
	For $i = $m To $n Step $o
		$hIcon = _WinAPI_ShellExtractIcon($g_aResources[$iIndex][$ePath], $i, $g_iIconX, $g_iIconY)
;~ 		ConsoleWrite('$hIcon = ' & $hIcon & @CRLF)
		If $i = 1 And $hIcon = 0 Then
			$o = -1
			$i = 0
			ContinueLoop
		EndIf
		If Abs($i) > 1 And $hIcon = 0 Then ExitLoop
		_GUICtrlListView_AddItem($g_idListview, $iIconCount, _GUIImageList_ReplaceIcon($g_hImageList, -1, $hIcon))
;~ 		_GUICtrlListView_AddSubItem($g_idListview, $iIconCount, _GUIImageList_ReplaceIcon($g_hImageList, -1, $hIcon))
		_WinAPI_DestroyIcon($hIcon)
		If $l = '' Then $l = $i
		$k = $i
		$iIconCount += 1
	Next
	$g_aResources[$iIndex][$eIconCount] = $iIconCount
	IniWrite($g_sIniFile, 'Global', 'ResourceID', $iIndex)
	IniWrite($g_sIniFile, 'Resources', StringFormat('Resource_%03i', $iIndex), StringFormat('%i|%s|%s', $g_aResources[$iIndex][$eIconCount], $g_aResources[$iIndex][$ePath], $g_aResources[$iIndex][$eComment]))
	ControlFocus($g_hGui, '', $g_idListview)
	ConsoleWrite(StringFormat('$iIndex = %i, $iIconCount = %i\r', $iIndex, $iIconCount))
	Return SetExtended($iIndex, $iIconCount)
EndFunc   ;==>_LoadResourceIcons

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
	#forceref $hWnd, $iMsg, $wParam
	Local $tNMHDR, $hWndFrom, $iIDFrom, $iCode, $tInfo, $tNMHEADER, $iIndex, $iItemCount, $VKEY
	$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
	$hWndFrom = HWnd(DllStructGetData($tNMHDR, 'hWndFrom'))
	$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
	$iCode = DllStructGetData($tNMHDR, 'Code')
	Switch $hWndFrom
		Case $g_hListView
;~ 			$iItemCount = _GUICtrlListView_GetItemCount($g_hListView)
;~ 			ConsoleWrite('$iItemCount = ' & $iItemCount & @CRLF)
;~ 			If $iItemCount > 0 Then
			Switch $iCode
				Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key
					_DebugPrint("$NM_RETURN" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
							"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
							"-->Code:" & @TAB & $iCode)
				Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
					ConsoleWrite('Case $NM_CLICK' & @CRLF)
					$tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
					$iIndex = DllStructGetData($tInfo, 'Index') ; den Index des Items ermitteln
					If $iIndex > -1 Then
						Local $iChecked
;~ 						Switch _GUICtrlListView_GetItemChecked($g_idListview, $iIndex)
;~ 							Case True
;~ 								$iChecked = False
;~ 							Case Else
;~ 								$iChecked = True
;~ 						EndSwitch
;~ 						_GUICtrlListView_SetItemChecked($g_idListview, $iIndex, $iChecked)
						_GUICtrlListView_SetItemChecked($g_idListview, $iIndex, _GUICtrlListView_GetItemChecked($g_idListview, $iIndex) ? False : True)
					EndIf
					ConsoleWrite('$iIndex = ' & $iIndex & @CRLF)
				Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
					$tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
					$iIndex = DllStructGetData($tInfo, 'Index') ; den Index des Items ermitteln
					ConsoleWrite('- $iIndex = ' & $iIndex & @CRLF)
;~ 						...
				Case $LVN_HOTTRACK ; Sent by a list-view control when the user moves the mouse over an item
					$tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
;~ 					ConsoleWrite('HotItem        = ' & DllStructGetData($tInfo, "Item") & @CRLF)
;~ 					ConsoleWrite('HotSubItem     = ' & DllStructGetData($tInfo, "SubItem") & @CRLF)
;~ 					$g_iHotItem = _GUICtrlListView_GetHotItem($g_idListView)
					$g_iHotItem = DllStructGetData($tInfo, "Item")
					$g_iHotSubItem = DllStructGetData($tInfo, "SubItem")
;~ 					ConsoleWrite('$g_iHotItem    = ' & $g_iHotItem & @CRLF)
				Case $LVN_KEYDOWN ; A key has been pressed
					#cs	****************************************************************************************************************************
						****************************************************************************************************************************
						****************************************************************************************************************************
						**** The original version from www.autoitscript.com does NOT work because of the                                        ****
						**** --> --> --> --> -->  -->  --> -->  "align 1;"  <-- <-- <-- <-- <-- <-- <-- <-- <--                                 ****
						**** --> Global Const $tagNMLVKEYDOWN = "align 1;" & $tagNMHDR & ";word VKey;uint Flags"                                ****
						**** --> $tInfo = DllStructCreate($tagNMLVKEYDOWN, $lParam)                                                             ****
						**** 					                                                                                                ****
						**** So, here is the corrected version! - Changed by Bitnugger                                                          ****
						**** Declare this constant at the beginning of the script.                                                              ****
						**** Global Const $tagFIXEDNMLVKEYDOWN = $tagNMHDR & ";word VKey;uint Flags"                                            ****
						**** In the WM_NOTIFY handler, instead of $tagNMLVKEYDOWN, use $tagFIXEDNMLVKEYDOWN!                                    ****
						**** $tInfo = DllStructCreate($tagFIXEDNMLVKEYDOWN)                                                                     ****
						**** 					                                                                                                ****
						**** Alternatively, without global constant, in full length ...                                                         ****
						**** $tInfo = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct;word VKey;uint Flags", $ilParam) ****
						****************************************************************************************************************************
						****************************************************************************************************************************
					#ce	****************************************************************************************************************************
					$tInfo = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct;word VKey;uint Flags", $lParam)
;~ 					$tInfo = DllStructCreate($tagNMHDR & ";word VKey;uint Flags" , $lParam)
					$VKEY = DllStructGetData($tInfo, 'VKey')
					ConsoleWrite('! $VKEY = ' & $VKEY & @CRLF)
					Switch $VKEY
						Case $VK_SPACE
							_DebugPrint("$LVN_KEYDOWN" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
									"--> IDFrom      :" & @TAB & $iIDFrom & @CRLF & _
									"--> Code        :" & @TAB & $iCode & @CRLF & _
									"--> VKey        :" & @TAB & DllStructGetData($tInfo, "VKey") & ' ($VK_SPACE)' & @CRLF & _
									"--> Flags       :" & @TAB & DllStructGetData($tInfo, "Flags") & @CRLF & _
									"--> $g_iHotItem :" & @TAB & $g_iHotItem)
					EndSwitch
			EndSwitch
;~ 			EndIf
	EndSwitch
	Return $GUI_RUNDEFMSG ; Anweisung an Windows, dass es mit der normalen Abarbeitung fortfahren kann
EndFunc   ;==>_WM_NOTIFY

Func _GetEnvStrings($sString)
		Local $aEnvStrings[2], $sExpand = _WinAPI_ExpandEnvironmentStrings($sString), $sUnExpand = _WinAPI_PathUnExpandEnvStrings($sString)
		$aEnvStrings[0] = ($sExpand = '') ? $sString : $sExpand
		$aEnvStrings[1] = ($sUnExpand = '') ? $sString : $sUnExpand
		Return $aEnvStrings
EndFunc

Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
	ConsoleWrite( _
			"!===========================================================" & @CRLF & _
			"+======================================================" & @CRLF & _
			"-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
			"+======================================================" & @CRLF)
EndFunc   ;==>_DebugPrint

Func _LoadIni()
	Local $aEnvStrings, $sExpand, $sUnExpand, $aSplit, $aSection

	$g_sSavePath = IniRead($g_sIniFile, 'Global', 'SavePath', @ScriptDir & '\')

	If FileExists($g_sIniFile) Then
		$aSection = IniReadSection($g_sIniFile, 'Resources')
		If UBound($aSection) Then
			ReDim $g_aResources[$aSection[0][0]][3]
			For $i = 1 To $aSection[0][0] Step 1
				$aSplit = StringSplit($aSection[$i][1], '|', 2)
				$aEnvStrings = _GetEnvStrings($aSplit[1])
				$sExpand = $aEnvStrings[0]
				$sUnExpand = $aEnvStrings[1]
				$g_aResources[$i -1][0] = $aSplit[0]
				$g_aResources[$i -1][1] = $sExpand
				$g_aResources[$i -1][2] = $aSplit[2]
				ConsoleWrite('+ $sExpand   = ' & $sExpand   & @CRLF)
				ConsoleWrite('- $sUnExpand = ' & $sUnExpand & @CRLF)
			Next
		EndIf
	Else
		For $i = 0 To UBound($g_aResources) - 1 Step 1
			$aEnvStrings = _GetEnvStrings($g_aResources[$i][$ePath])
			$sExpand = $aEnvStrings[0]
			$sUnExpand = $aEnvStrings[1]
			$g_aResources[$i][$ePath] = $sExpand
			ConsoleWrite('+ $sExpand   = ' & $sExpand   & @CRLF)
			ConsoleWrite('- $sUnExpand = ' & $sUnExpand & @CRLF)
			If FileExists($sExpand) Then
				IniWrite($g_sIniFile, 'Resources', StringFormat('Resource_%03i', $i), StringFormat('%i|%s|%s', $g_aResources[$i][$eIconCount], $sUnExpand, $g_aResources[$i][$eComment]))
			Else
				ConsoleWrite('Resource nicht gefunden --> ' & $sExpand & @CRLF)
			EndIf
		Next
	EndIf

	$g_iLeft = IniRead($g_sIniFile, 'WinPos', 'XPOS', -1)
	$g_iTop = IniRead($g_sIniFile, 'WinPos', 'YPOS', -1)
EndFunc

Func _SaveIni()
	Local $aPos, $aEnvStrings, $sExpand, $sUnExpand

	$aPos = WinGetPos($g_hGui)
	If $aPos[0] = -32000 Then
		WinSetState($g_hGui, '', @SW_RESTORE)
		$aPos = WinGetPos($g_hGui)
	EndIf
	IniWrite($g_sIniFile, 'WinPos', 'XPOS', $aPos[0])
	IniWrite($g_sIniFile, 'WinPos', 'YPOS', $aPos[1])

	IniWrite($g_sIniFile, 'Global', 'SavePath', $g_sSavePath)
	IniWrite($g_sIniFile, 'Global', 'ResourceID', $g_iResourceID)

	For $i = 0 To UBound($g_aResources) - 1 Step 1
		$aEnvStrings = _GetEnvStrings($g_aResources[$i][$ePath])
		$sExpand = $aEnvStrings[0]
		$sUnExpand = $aEnvStrings[1]
		If FileExists($sExpand) Then
			IniWrite($g_sIniFile, 'Resources', StringFormat('Resource_%03i', $i), StringFormat('%i|%s|%s', $g_aResources[$i][$eIconCount], $sUnExpand, $g_aResources[$i][$eComment]))
		Else
			ConsoleWrite('Resource nicht gefunden --> ' & $sExpand & @CRLF)
		EndIf
	Next
EndFunc

Func _Exit()
	_SaveIni()
EndFunc
