OpenFileDialog in GUI

    • Offizieller Beitrag

    Welchen Sinn soll das Einbetten haben? Stehe da voll auf der Leitung.
    Wenn der Anwender eine Datei wählen soll, erscheint die Datei/der Dateipfad nach der Auswahl in einem Input. Wozu willst du Platz verschwenden und ein Tree/Listview zur Auswahl ständig anzeigen, wenn nur einmalig darauf zugegriffen wird?

  • Es geht mir hier eher um die Optik, Bedienbarkeit. Ich möchte ein kleines Tool realsieren und fand es einfach
    von meiner Überlegung her besser / schöner wenn praktisch ein kleines Explorer Fenster in der GUI eingebettet wäre anstatt
    sich immer wieder ein neues Fenster öffnet...

    • Offizieller Beitrag

    Dann suchst du wohl eher einen SimpleExplorer um zu navigieren und auszuwählen.
    Sowas hab ich vor Jahren mal gemacht. Kannst du ja als Basis nehmen:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <ListBoxConstants.au3>
    #include <WindowsConstants.au3>
    #include <GuiListBox.au3>
    #include <File.au3>

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

    Global $aFile, $aFolder, $aPath[1] = [@HomeDrive & '\'], $currPath, $sUp = '[ EBENE HÖHER ]'
    Global $Safed = '[SHOC]' ; mit diesen Attributen gesperrt für: Ausführen, Umbenennen, Löschen

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

    $GUI = GUICreate("Simple Explorer",400,300)
    $label = GUICtrlCreateLabel('', 5, 5, 390, 53)
    $List = GUICtrlCreateList( '', 2, 65, 396, 230, BitOR($WS_HSCROLL, $WS_VSCROLL, $WS_BORDER))
    $hList = GUICtrlGetHandle($List)
    $menu = GUICtrlCreateContextMenu($List)
    $itemRun = GUICtrlCreateMenuItem('Ausführen', $menu)
    $itemShape = GUICtrlCreateMenuItem('', $menu)
    $itemCopy = GUICtrlCreateMenuItem('Kopieren', $menu)
    $itemPaste = GUICtrlCreateMenuItem('Einfügen', $menu)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $itemRen = GUICtrlCreateMenuItem('Umbenennen', $menu)
    $itemShape = GUICtrlCreateMenuItem('', $menu)
    $itemDel = GUICtrlCreateMenuItem('Löschen', $menu)
    GUISetState(@SW_SHOW)

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

    GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')

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

    _WriteList($aPath[0])

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $itemRun
    _RunFile()
    Case $itemCopy
    _CopyFile()
    Case $itemPaste
    _PasteFile()
    Case $itemRen
    _RenFile()
    Case $itemDel
    _DelFile()
    EndSwitch
    Wend

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

    Func _WriteList($PATH)
    _GUICtrlListBox_ResetContent($hList) ; alte Inhalte löschen
    $aFolder = _FileListToArray($PATH, '*', 2)
    $aFile = _FileListToArray($PATH, '*', 1)
    If UBound($aPath) > 1 Then _GUICtrlListBox_AddString($hList, $sUp)
    If IsArray($aFolder) Then
    _GUICtrlListBox_AddString($hList, '--------------- ORDNER ---------------')
    For $i = 1 To UBound($aFolder) -1
    _GUICtrlListBox_AddString($hList, $aFolder[$i])
    Next
    EndIf
    If IsArray($aFile) Then
    _GUICtrlListBox_AddString($hList, '--------------- DATEIEN ---------------')
    For $i = 1 To UBound($aFile) -1
    _GUICtrlListBox_AddString($hList, $aFile[$i])
    Next
    EndIf
    GUICtrlSetData($label, $PATH)
    EndFunc

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

    Func _ListDblClick()
    Local $str = _GUICtrlListBox_GetText($hList, _GUICtrlListBox_GetCurSel($hList))
    Local $tmpPath = ''
    If $str = $sUp Then
    ReDim $aPath[UBound($aPath)-1]
    $currPath = $aPath[UBound($aPath)-1]
    _WriteList($currPath)
    Else
    $currPath = $aPath[UBound($aPath)-1] & $str & '\' ; neuer Pfad = letzter Pfad + geklickter Pfad
    If Not StringRegExp(FileGetAttrib($currPath), 'D') Then ; ist es kein Ordner ?
    _RunFile()
    Else
    ReDim $aPath[UBound($aPath)+1]
    $aPath[UBound($aPath)-1] = $currPath ; neuen Pfad hinzufügen
    _WriteList($currPath)
    EndIf
    EndIf
    EndFunc

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

    Func _RunFile()
    Local $str = _GUICtrlListBox_GetText($hList, _GUICtrlListBox_GetCurSel($hList))
    If $str = '' Then Return
    Local $attrib = FileGetAttrib($aPath[UBound($aPath)-1] & $str)
    If StringRegExp($attrib, $Safed) Then Return MsgBox(0, 'Geschützt!', $str & ' - Attribut: ' & $attrib)
    ShellExecuteWait($aPath[UBound($aPath)-1] & $str)
    EndFunc

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

    Func _CopyFile()
    Local $str = _GUICtrlListBox_GetText($hList, _GUICtrlListBox_GetCurSel($hList))
    If $str = '' Then Return
    Local $attrib = FileGetAttrib($aPath[UBound($aPath)-1] & $str)
    If StringRegExp($attrib, 'D') Then Return MsgBox(0, 'Achtung', $str & ' ist keine Datei')
    ClipPut($aPath[UBound($aPath)-1] & $str)
    GUICtrlSetState($itemPaste, $GUI_ENABLE)
    EndFunc

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

    Func _PasteFile()
    Local $str = _GUICtrlListBox_GetText($hList, _GUICtrlListBox_GetCurSel($hList))
    If $str = '' Then Return
    Local $attrib = FileGetAttrib($aPath[UBound($aPath)-1] & $str)
    If Not StringRegExp($attrib, 'D') Then Return MsgBox(0, 'Achtung', $str & ' - ist kein Ordner')
    Local $tmp = ClipGet(), $pos = StringInStr($tmp, '\', -1)
    Local $file = StringRight($tmp, StringLen($tmp)-$pos)
    If FileExists($aPath[UBound($aPath)-1] & $str & '\' & $file) Then $file = 'Kopie von ' & $file
    FileCopy($tmp, $aPath[UBound($aPath)-1] & $str & '\' & $file)
    _WriteList($aPath[UBound($aPath)-1])
    GUICtrlSetState($itemPaste, $GUI_DISABLE)
    EndFunc

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

    Func _RenFile()
    Local $str = _GUICtrlListBox_GetText($hList, _GUICtrlListBox_GetCurSel($hList))
    If $str = '' Then Return
    Local $attrib = FileGetAttrib($aPath[UBound($aPath)-1] & $str)
    If StringRegExp($attrib, $Safed) Then Return MsgBox(0, 'Geschützt!', $str & ' - Attribut: ' & $attrib)
    Local $tmp = InputBox('Umbenennen', 'Neuer Name:' & @LF & @LF & $aPath[UBound($aPath)-1], $str)
    If $tmp <> '' Then FileMove($aPath[UBound($aPath)-1] & $str, $aPath[UBound($aPath)-1] & $tmp)
    _WriteList($aPath[UBound($aPath)-1])
    EndFunc

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

    Func _DelFile()
    Local $str = _GUICtrlListBox_GetText($hList, _GUICtrlListBox_GetCurSel($hList))
    If $str = '' Then Return
    Local $attrib = FileGetAttrib($aPath[UBound($aPath)-1] & $str)
    If StringRegExp($attrib, $Safed) Then Return MsgBox(0, 'Geschützt!', $str & ' - Attribut: ' & $attrib)
    FileDelete($aPath[UBound($aPath)-1] & $str)
    _WriteList($aPath[UBound($aPath)-1])
    EndFunc

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

    Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox
    If Not IsHWnd($hList) Then $hWndListBox = GUICtrlGetHandle($hList)
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $hWndFrom
    Case $hList, $hWndListBox
    Switch $iCode
    Case $LBN_DBLCLK ; Sent when the user double-clicks a string in a list box
    _ListDblClick()
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_COMMAND

    [/autoit]