행위

Autoit tab 과 listview 이용 ini파일 불러오기

DB CAFE

thumb_up 추천메뉴 바로가기


Autoit tab 과 listview 이용 ini파일 불러오기[편집]

#include <GUIConstantsEx.au3>
#include <GuiTab.au3>
#include <GuiListView.au3>
#include <Array.au3>

; INI 파일 경로 설정
Local $sIniFile = @ScriptDir & "\test.ini"

; GUI 생성
GUICreate("INI 파일 탭과 ListView", 900, 800)

; 탭 컨트롤 생성
Local $hTab = GUICtrlCreateTab(10, 10, 480, 300)

; INI 파일에서 섹션 읽기
Local $aSections = IniReadSectionNames($sIniFile)
If @error Then
    MsgBox(16, "Error", "INI 파일을 읽는 중 오류가 발생했습니다.")
    Exit
EndIf

; 섹션 별 탭 생성
For $i = 1 To UBound($aSections) - 1
    GUICtrlCreateTabItem($aSections[$i])
Next
GUICtrlCreateTabItem("")

; ListView 생성
Local $hListView = GUICtrlCreateListView("* | Key               |                Value ", 10, 32, 480, 270)

; GUI 표시
GUISetState()

; 처음에 첫 번째 섹션 데이터를 로드
UpdateListView($sIniFile, $aSections[1])

; 탭 변경 이벤트 처리
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $hTab
            ; 현재 선택된 탭 인덱스 가져오기
            Local $iTabIndex = GUICtrlRead($hTab) + 1 ; 탭 인덱스는 0부터 시작하므로 +1
            If $iTabIndex > 0 And $iTabIndex <= UBound($aSections) - 1 Then
                ; 선택된 탭에 해당하는 섹션 데이터를 ListView에 반영
                UpdateListView($sIniFile, $aSections[$iTabIndex])
            EndIf
    EndSwitch
WEnd

GUIDelete()
Exit

; 섹션 데이터를 ListView에 업데이트하는 함수
Func UpdateListView($sIniFile, $sSectionName)
    ; ListView 초기화
;~     GUICtrlSetData($hListView, "")
	_GUICtrlListView_DeleteAllItems ( $hListView )
    ; 선택된 섹션의 데이터 읽기
    Local $aSectionData = IniReadSection($sIniFile, $sSectionName)

    ; ListView에 섹션 데이터 추가
    If Not @error Then
        For $i = 1 To UBound($aSectionData) - 1
            GUICtrlCreateListViewItem("* | " & $aSectionData[$i][0] & "|" & $aSectionData[$i][1], $hListView)
        Next
    EndIf
EndFunc