Jump to content

GUICtrlDelete() Help


Recommended Posts

Hey Guys...

Trying to write a special INI Viewer and I can't get the GUICtrlDelete() function to work... Generally this is how the program works:

User opens a file and then they view it and then close the file, the list view is then deleted and the buttons are enabled to open another file. The only problem is that i can't get the list view to be deleted with the function.

Any help is appreciated :lmao: and feel free to use this code if you like!!!

#include <GuiConstants.au3>
#NoTrayIcon
; ----------------------------------------------------------------------------
; Create the GUI features
; ----------------------------------------------------------------------------  
    $WinTitle   = 'IniViewer'
    $WinWidth   = 600
    $WinHeight  = 440
    
;GUI
    GUICreate($WinTitle, $WinWidth, $WinHeight)
    GuiSetIcon('icon.ico', 0)
    
;FILE MENU
    $FileMenu = GuiCtrlCreateMenu ("File")
    $FileItem = GuiCtrlCreateMenuitem ("Open...", $FileMenu)
    $CloseItem = GuiCtrlCreateMenuitem ("Close", $FileMenu)
    $Separator = GuiCtrlCreateMenuitem ("", $FileMenu)
    $ExitItem = GuiCtrlCreateMenuitem ("Exit", $FileMenu)
    
    GUICtrlSetState ($CloseItem, $GUI_DISABLE)
    
;LIST VIEW
    Dim $listView
    
; ----------------------------------------------------------------------------
; Set the operations for program events
; ----------------------------------------------------------------------------  

    GuiSetState()
    While 1
        $Event = GuiGetMsg()
        Select
            Case $Event = -3 Or $Event = -1 or $Event = $ExitItem
                ExitLoop
            
            Case $Event = $FileItem
                Dim $Filename = FileOpenDialog("Select File:", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "INI Configuration Settings (*.ini)", 1)
                
                If FileExists ($Filename) Then
                ; LIST VIEW
                    Dim $SectionNames   = IniReadSectionNames ($Filename)
                    Dim $KeyNames       = IniReadSection ($Filename, $SectionNames[1]) 
                    Dim $Headings       = ''
                    Dim $Rows       = ''
                    
                    For $i = 1 To $KeyNames[0][0]
                        If $i = 1 Then
                            $Headings = $Headings & $KeyNames[$i][0]
                        Else
                            $Headings = $Headings & '|' & $KeyNames[$i][0]
                        EndIf
                    Next
                
                    $listView = GuiCtrlCreateListView($Headings, 0, 0, 600, 440)
                
                    For $i = 1 To $SectionNames[0]
                        $KeyNames = IniReadSection ($Filename, $SectionNames[$i])
                    
                        For $j = 1 To $KeyNames[0][0]
                            If $j = 1 Then
                                $Rows = $Rows & $KeyNames[$j][1]
                            Else
                                $Rows = $Rows & '|' & $KeyNames[$j][1]
                            EndIf
                        Next
                        GuiCtrlCreateListViewItem($Rows, $listView)
                        $Rows = ''
                    Next
                    
                    GUICtrlSetState ($FileItem, $GUI_DISABLE)
                    GUICtrlSetState ($CloseItem, $GUI_ENABLE)
                EndIf
                
            Case $Event = $CloseItem
                GUICtrlDelete ($listView)
                GUICtrlSetState ($listView, $GUI_HIDE)
                GUICtrlSetState ($FileItem, $GUI_ENABLE)
        EndSelect
    WEnd
    GUIDelete()

; ----------------------------------------------------------------------------
; Exit the Program
; ----------------------------------------------------------------------------  
    
    Exit
Link to comment
Share on other sites

See Assign and Eval for my changes:

#include <GuiConstants.au3>
#NoTrayIcon
; ----------------------------------------------------------------------------
; Create the GUI features
; ----------------------------------------------------------------------------  
    $WinTitle    = 'IniViewer'
    $WinWidth    = 600
    $WinHeight  = 440
    
;GUI
    GUICreate($WinTitle, $WinWidth, $WinHeight)
    GuiSetIcon('icon.ico', 0)
    
;FILE MENU
    $FileMenu = GuiCtrlCreateMenu ("File")
    $FileItem = GuiCtrlCreateMenuitem ("Open...", $FileMenu)
    $CloseItem = GuiCtrlCreateMenuitem ("Close", $FileMenu)
    $Separator = GuiCtrlCreateMenuitem ("", $FileMenu)
    $ExitItem = GuiCtrlCreateMenuitem ("Exit", $FileMenu)
    
    GUICtrlSetState ($CloseItem, $GUI_DISABLE)
    
;LIST VIEW
    Dim $listView
    
; ----------------------------------------------------------------------------
; Set the operations for program events
; ----------------------------------------------------------------------------  

    GuiSetState()
    While 1
        $Event = GuiGetMsg()
        Select
            Case $Event = -3 Or $Event = -1 or $Event = $ExitItem
                ExitLoop
            
            Case $Event = $FileItem
                Dim $Filename = FileOpenDialog("Select File:", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "INI Configuration Settings (*.ini)", 1)
                
                If FileExists ($Filename) Then
               ; LIST VIEW
                    Dim $SectionNames    = IniReadSectionNames ($Filename)
                    Dim $KeyNames        = IniReadSection ($Filename, $SectionNames[1]) 
                    Dim $Headings        = ''
                    Dim $Rows        = ''
                    
                    For $i = 1 To $KeyNames[0][0]
                        If $i = 1 Then
                            $Headings = $Headings & $KeyNames[$i][0]
                        Else
                            $Headings = $Headings & '|' & $KeyNames[$i][0]
                        EndIf
                    Next
                
                    $listView = GuiCtrlCreateListView($Headings, 0, 0, 600, 440)
                
                    For $i = 1 To $SectionNames[0]
                        $KeyNames = IniReadSection ($Filename, $SectionNames[$i])
                    
                        For $j = 1 To $KeyNames[0][0]
                            If $j = 1 Then
                                $Rows = $Rows & $KeyNames[$j][1]
                            Else
                                $Rows = $Rows & '|' & $KeyNames[$j][1]
                            EndIf
                        Next
                        Assign ("lvItem" & $i, GuiCtrlCreateListViewItem ($Rows, $listView))
                        $Rows = ''
                    Next
                    
                    GUICtrlSetState ($FileItem, $GUI_DISABLE)
                    GUICtrlSetState ($CloseItem, $GUI_ENABLE)
                EndIf
                
            Case $Event = $CloseItem
                For $i = 1 To $SectionNames[0]
                    GUICtrlDelete (Eval ("lvItem" & $i))
                Next
                GUICtrlSetState ($listView, $GUI_HIDE)
                GUICtrlSetState ($FileItem, $GUI_ENABLE)
        EndSelect
    WEnd
    GUIDelete()

; ----------------------------------------------------------------------------
; Exit the Program
; ----------------------------------------------------------------------------  
    
    Exit
Edited by pacman
Link to comment
Share on other sites

I think I understand what you are trying to do... You have to delete the list view items before deleting the list view in order for it to remove that GUI object...

I'll try that when I get home and tell you if it works, then I'll repost the program for anyone that wants to use it.

Thanks a lot for your reply though... :lmao:

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