GUIControls anhand Handle löschen?

  • Hallo,

    mit ControlGetHandle erhält man ja den Handle eines Controls. Aber warum kann man diesem Handle nicht einen Control löschen bzw. wie mache ich das?

    Mein Script:

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <ComboConstants.au3>
    #include <DateTimeConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GUIListBox.au3>
    #include <ListViewConstants.au3>
    #include <ProgressConstants.au3>
    #include <SliderConstants.au3>
    #include <StaticConstants.au3>
    #include <TabConstants.au3>
    #include <TreeViewConstants.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("Form1", 633, 447, 192, 124)
    $Label1 = GUICtrlCreateLabel("Label1", 8, 32, 36, 17)
    $Label2 = GUICtrlCreateLabel("Label2", 8, 8, 36, 17)
    $Input1 = GUICtrlCreateInput("Input1", 8, 56, 121, 21)
    $Edit1 = GUICtrlCreateEdit("", 152, 8, 185, 89)
    GUICtrlSetData(-1, "Edit1")
    $Radio1 = GUICtrlCreateRadio("Radio1", 8, 80, 113, 17)
    $Label3 = GUICtrlCreateLabel("Label3", 80, 8, 36, 17)
    $Label4 = GUICtrlCreateLabel("Label4", 80, 32, 36, 17)
    $Button1 = GUICtrlCreateButton("Button1", 8, 104, 75, 25, $WS_GROUP)
    $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 96, 104, 97, 17)
    $List1 = GUICtrlCreateList("", 8, 136, 121, 97)
    $Combo1 = GUICtrlCreateCombo("Combo1", 192, 104, 145, 25)
    $Group1 = GUICtrlCreateGroup("Group1", 144, 136, 185, 105)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Slider1 = GUICtrlCreateSlider(376, 8, 150, 45)
    $Progress1 = GUICtrlCreateProgress(376, 56, 150, 17)
    $Date1 = GUICtrlCreateDate("2009/06/17 10:42:24", 376, 88, 186, 21)
    $MonthCal1 = GUICtrlCreateMonthCal("2009/06/17", 376, 112, 191, 154)
    $TreeView1 = GUICtrlCreateTreeView(264, 272, 121, 97)
    $ListView1 = GUICtrlCreateListView("", 8, 248, 250, 150)
    $Tab1 = GUICtrlCreateTab(416, 304, 193, 105)
    GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
    $TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
    $TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
    $TabSheet3 = GUICtrlCreateTabItem("TabSheet3")
    GUICtrlSetState(-1, $GUI_SHOW)
    GUICtrlCreateTabItem("")
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    _Delete_All_Controls()

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

    [/autoit] [autoit][/autoit] [autoit]

    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Delete_All_Controls()
    _Delete_Controls("Static")
    _Delete_Controls("Edit")
    _Delete_Controls("ComboBox")
    _Delete_Controls("Button")
    _Delete_Controls("SysMonthCal32")
    _Delete_Controls("msctls_trackbar32")
    _Delete_Controls("SysTabControl32")
    _Delete_Controls("SysDateTimePick32")
    _Delete_Controls("SysListView32")
    _Delete_Controls("ListBox")
    _Delete_Controls("msctls_progress32")
    _Delete_Controls("SysTreeView32")
    EndFunc ;==>_Delete_All_Controls

    [/autoit] [autoit][/autoit] [autoit]

    Func _Delete_Controls($Controlname)
    Local $1
    While 1
    $1 += 1
    $Hwnd = ControlGetHandle($Form1, "", $Controlname & $1)
    If @error Then ExitLoop
    GUICtrlDelete($Hwnd)
    ;~ ControlHide($Form1, "", $Hwnd)
    WEnd
    EndFunc ;==>_Delete_Controls

    [/autoit]
  • Hallo,
    controlid <> Handle!
    du müsstest nur die Anzahl der Controls in deiner Gui zählen und dann statt

    [autoit]

    GUICtrlDelete($Hwnd)

    [/autoit]

    mit

    [autoit]

    GUICtrlDelete($1)

    [/autoit]

    löschen

  • du musst das handle erst in die ControlID umwandlen ;)

    [autoit]

    GUICtrlDelete(_WinAPI_GetDlgCtrlID($hWnd))

    [/autoit]