Windows eigenen Progress-Dialog öffnen

  • Da heute einer (glaub Matthias) in der Shoutbox gefragt hat, ob man den Windows-Kopier-Dialog öffnen kann, habe ich nach einer Lösung gesucht und bin auch fündig geworden.

    Man benötigt dafür die objbase-UDF von progandy.

    Das ganze könnte manchmal ziemlich nützlich sein.

    Spoiler anzeigen
    [autoit]

    #include "objbase.au3"
    #include <WinAPI.au3>

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

    ;funkey 2010, Dec 10th
    ;http://msdn.microsoft.com/en-us/library/…8(v=VS.85).aspx

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

    Global Const $PROGDLG_NORMAL = 0x00000000 ;default normal progress dlg behavior
    Global Const $PROGDLG_MODAL = 0x00000001 ; the dialog is modal to its hwndParent (default is modeless)
    Global Const $PROGDLG_AUTOTIME = 0x00000002 ; automatically updates the "Line3" text with the "time remaining" (you cant call SetLine3 if you passs this!)
    Global Const $PROGDLG_NOTIME = 0x00000004 ; we dont show the "time remaining" if this is set. We need this if dwTotal < dwCompleted for sparse files
    Global Const $PROGDLG_NOMINIMIZE = 0x00000008 ; Do not have a minimize button in the caption bar.
    Global Const $PROGDLG_NOPROGRESSBAR = 0x00000010 ; Don't display the progress bar
    Global Const $PROGDLG_MARQUEEPROGRESS = 0x00000020 ; Vista and above only
    Global Const $PROGDLG_NOCANCEL = 0x00000040 ; Vista and above only

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

    Global Const $PDTIMER_RESET = 0x00000001
    Global Const $PDTIMER_PAUSE = 0x00000002
    Global Const $PDTIMER_RESUME = 0x00000003

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

    Global Const $AVI_SEARCH = 150
    Global Const $AVI_SEARCH_DOC = 151
    Global Const $AVI_SEARCH_PC = 152
    Global Const $AVI_MOVE = 160
    Global Const $AVI_COPY = 161
    Global Const $AVI_DELETE = 162
    Global Const $AVI_EMPTY_RECYCLEBIN = 163
    Global Const $AVI_DELETE_DIRECT = 164
    Global Const $AVI_COPY_DOC = 165
    Global Const $AVI_SEARCH_IE = 166
    Global Const $AVI_MOVE_OLD = 167
    Global Const $AVI_COPY_OLD = 168
    Global Const $AVI_DELETE_DIRECT_OLD = 169
    Global Const $AVI_DOWNLOAD = 170

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

    Global $CLSID_ProgressDialog = _GUID("{F8383852-FCD3-11d1-A6B9-006097DF5BD4}")
    Global $IID_ProgressDialog = _GUID("{EBBC7C04-315E-11d2-B62F-006097DF5BD4}")

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

    Global $Dialog_vTable = $IUnknown_vTable & _
    "ptr StartProgressDialog;ptr StopProgressDialog;ptr SetTitle;ptr SetAnimation;ptr HasUserCancelled;" & _
    "ptr SetProgress;ptr SetProgress64;ptr SetLine;ptr SetCancelMsg;ptr Timer"

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

    _OLEInitialize()

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

    Global $aObj = _ObjCoCreateInstance($CLSID_ProgressDialog, $IID_ProgressDialog, $Dialog_vTable)

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

    Global $hParent = HWnd(0)
    Global $sTitle = "Kopieren..."
    Global $dwFlags = $PROGDLG_NOMINIMIZE
    Global $hInstAnimation = _WinAPI_GetModuleHandle("shell32.dll")
    Global $idAnimation = $AVI_COPY
    Global $dwCompleted = 0
    Global $dwTotal = 600 ;1 Minuten alle 100ms ein Prozent
    Global $dwTimerAction = $PDTIMER_PAUSE
    Global $strCancelMsg = "Der Abbrechen-Button wurde gedrückt ;)"
    Global $dwLineNum = 1
    Global $strText = "Eine sehr große Datei.dat"
    Global $fCompactPath = 0
    Global $pvReserved = 0

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

    _ObjFuncCall($HRESULT, $aObj, "SetTitle", "wstr", $sTitle)
    _ObjFuncCall($HRESULT, $aObj, "SetAnimation", "handle", $hInstAnimation, "dword", $idAnimation)

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

    _ObjFuncCall($HRESULT, $aObj, "SetCancelMsg", "wstr", $strCancelMsg, "dword", $pvReserved)

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

    _ObjFuncCall($HRESULT, $aObj, "SetLine", "dword", $dwLineNum, "wstr", $strText, "long", $fCompactPath, "dword", $pvReserved)
    $dwLineNum = 2
    $strText = 'Von "Ordner" nach "Ordner_neu"'
    _ObjFuncCall($HRESULT, $aObj, "SetLine", "dword", $dwLineNum, "wstr", $strText, "long", $fCompactPath, "dword", $pvReserved)

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

    _ObjFuncCall($HRESULT, $aObj, "StartProgressDialog", "hwnd", $hParent, "ptr", 0, "dword", $dwFlags, "ptr", 0)

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

    ;~ _ObjFuncCall($HRESULT, $aObj, "Timer", "dword", $dwTimerAction, "dword", $pvReserved)

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

    AdlibRegister("_CountUp", 100)

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

    Do
    Sleep(10)
    $Canceled = _ObjFuncCall($HRESULT, $aObj, "HasUserCancelled")
    Until $Canceled[0] = 1 Or $dwCompleted = $dwTotal
    Sleep(2000)

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

    _ObjFuncCall($HRESULT, $aObj, "StopProgressDialog")
    _OLEUnInitialize()
    DllClose($OLE32)

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

    Func _CountUp()
    $dwCompleted += 1
    _ObjFuncCall($HRESULT, $aObj, "SetProgress", "dword", $dwCompleted, "dword", $dwTotal)
    EndFunc ;==>_CountUp

    [/autoit]
  • Mit AutoItObject wird das noch besser ;)

    IProgressDialog.intfc
    [autoit]

    #include-once
    ;===============================================================================
    #API "Windows Progress Dialog"
    ; IProgressDialog
    ;===============================================================================

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

    Global Const $PROGDLG_NORMAL = 0x00000000 ;default normal progress dlg behavior
    Global Const $PROGDLG_MODAL = 0x00000001 ; the dialog is modal to its hwndParent (default is modeless)
    Global Const $PROGDLG_AUTOTIME = 0x00000002 ; automatically updates the "Line3" text with the "time remaining" (you cant call SetLine3 if you passs this!)
    Global Const $PROGDLG_NOTIME = 0x00000004 ; we dont show the "time remaining" if this is set. We need this if dwTotal < dwCompleted for sparse files
    Global Const $PROGDLG_NOMINIMIZE = 0x00000008 ; Do not have a minimize button in the caption bar.
    Global Const $PROGDLG_NOPROGRESSBAR = 0x00000010 ; Don't display the progress bar
    Global Const $PROGDLG_MARQUEEPROGRESS = 0x00000020 ; Vista and above only
    Global Const $PROGDLG_NOCANCEL = 0x00000040 ; Vista and above only

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

    Global Const $PDTIMER_RESET = 0x00000001
    Global Const $PDTIMER_PAUSE = 0x00000002
    Global Const $PDTIMER_RESUME = 0x00000003

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

    Global Const $AVI_SEARCH = 150
    Global Const $AVI_SEARCH_DOC = 151
    Global Const $AVI_SEARCH_PC = 152
    Global Const $AVI_MOVE = 160
    Global Const $AVI_COPY = 161
    Global Const $AVI_DELETE = 162
    Global Const $AVI_EMPTY_RECYCLEBIN = 163
    Global Const $AVI_DELETE_DIRECT = 164
    Global Const $AVI_COPY_DOC = 165
    Global Const $AVI_SEARCH_IE = 166
    Global Const $AVI_MOVE_OLD = 167
    Global Const $AVI_COPY_OLD = 168
    Global Const $AVI_DELETE_DIRECT_OLD = 169
    Global Const $AVI_DOWNLOAD = 170

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

    ;===============================================================================
    #interface "IProgressDialog"
    Global Const $sCLSID_IProgressDialog = "{F8383852-FCD3-11d1-A6B9-006097DF5BD4}"
    Global Const $sIID_IProgressDialog = "{EBBC7C04-315E-11d2-B62F-006097DF5BD4}"

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

    ; Definition
    Global Const $dtagIProgressDialog = _
    "StartProgressDialog hresult(hwnd;ptr;dword;ptr);" & _
    "StopProgressDialog hresult();" & _
    "SetTitle hresult(wstr);" & _
    "SetAnimation hresult(handle;uint);" & _
    "HasUserCancelled int();" & _
    "SetProgress hresult(dword;dword);" & _
    "SetProgress64 hresult(uint64;uint64);" & _
    "SetLine hresult(dword;wstr;int;ptr);" & _
    "SetCancelMsg hresult(wstr;ptr);" & _
    "Timer hresult();"
    ;===============================================================================

    [/autoit]
    Spoiler anzeigen
    [autoit]

    #include <WinAPI.au3>
    #include "IProgressDialog.intfc"

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

    $oDlg = ObjCreateInterface($sCLSID_IProgressDialog, $sIID_IProgressDialog, $dtagIProgressDialog)

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

    Global $hParent = HWnd(0)
    Global $sTitle = "Kopieren..."
    Global $dwFlags = $PROGDLG_NOMINIMIZE
    Global $hInstAnimation = _WinAPI_GetModuleHandle("shell32.dll")
    Global $idAnimation = $AVI_COPY
    Global $dwCompleted = 0
    Global $dwTotal = 600 ;1 Minuten alle 100ms ein Prozent
    Global $dwTimerAction = $PDTIMER_PAUSE
    Global $strCancelMsg = "Der Abbrechen-Button wurde gedrückt ;)"
    Global $dwLineNum = 1
    Global $strText = "Eine sehr große Datei.dat"
    Global $fCompactPath = 0
    Global $pvReserved = 0

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

    $oDlg.SetTitle($sTitle)
    $oDlg.SetAnimation(Number($hInstAnimation), $idAnimation)

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

    $oDlg.SetCancelMsg($strCancelMsg, $pvReserved)

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

    $oDlg.SetLine($dwLineNum, $strText, $fCompactPath, $pvReserved)

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

    $dwLineNum = 2
    $strText = 'Von "Ordner" nach "Ordner_neu"'

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

    $oDlg.SetLine($dwLineNum, $strText, $fCompactPath, $pvReserved)

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

    $oDlg.StartProgressDialog(Number($hParent), 0, $dwFlags, 0)

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

    AdlibRegister("_CountUp", 100)

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

    Do
    Sleep(10)
    Until $oDlg.HasUserCancelled() Or $dwCompleted = $dwTotal
    Sleep(2000)

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

    $oDlg.StopProgressDialog()

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

    Func _CountUp()
    $dwCompleted += 1
    $oDlg.setProgress($dwCompleted, $dwTotal)
    EndFunc

    [/autoit]


    Edit: Aktualisiert für ObjCreateInterface

    Einmal editiert, zuletzt von progandy (13. April 2012 um 14:06)

  • Hallo funkey,

    Ja, das war ich! Danke dir, schaut gut aus! Großvater hatte mir auch etwas empfohlen, habe hier aber gerade nicht meine Bookmarks verfügbar. :)

    Viele Grüße,
    Matthias

  • Danke progandy.
    Sieht so aus, als ob ich mich mehr mir AutoItObject befassen müsste. Aber ich habs ja auch so hinbekommen.


    Paule:
    Das hättest du bestimmt selber geschafft!

    Spoiler anzeigen
    [autoit]

    #include <AutoItObject.au3>
    #include <WinAPI.au3>
    #include "IProgressDialog.intfc"

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

    _AutoItObject_StartUp()

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

    OnAutoItExitRegister("_OnExit")
    Func _OnExit()
    _AutoItObject_Shutdown()
    EndFunc

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

    Global $oDlg = _AutoItObject_ObjCreate($sCLSID_IProgressDialog, $sIID_IProgressDialog, $dtagIProgressDialog)

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

    Global $hParent = HWnd(0)
    Global $sTitle = "Downloading..."
    Global $dwFlags = $PROGDLG_NOMINIMIZE
    Global $hInstAnimation = _WinAPI_GetModuleHandle("shell32.dll")
    Global $idAnimation = $AVI_DOWNLOAD
    Global $dwCompleted = 0
    Global $dwTotal = 6000 ;1 Minuten alle 100ms ein Prozent
    Global $dwTimerAction = $PDTIMER_PAUSE
    Global $strCancelMsg = "Der Abbrechen-Button wurde gedrückt ;)"
    Global $dwLineNum = 1
    Global $strText = "Download the whole internet"
    Global $fCompactPath = 0
    Global $pvReserved = 0

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

    $oDlg.SetTitle($sTitle)
    $oDlg.SetAnimation(Number($hInstAnimation), $idAnimation)

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

    $oDlg.SetCancelMsg($strCancelMsg, $pvReserved)

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

    $oDlg.SetLine($dwLineNum, $strText, $fCompactPath, $pvReserved)

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

    $dwLineNum = 2
    $strText = 'From "Internet" to "PC"'

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

    $oDlg.SetLine($dwLineNum, $strText, $fCompactPath, $pvReserved)

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

    $oDlg.StartProgressDialog(Number($hParent), 0, $dwFlags, 0)

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

    AdlibRegister("_CountUp", 100)

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

    Do
    Sleep(10)
    $Canceled = $oDlg.HasUserCancelled()
    Until $Canceled[0] = 1 Or $dwCompleted = $dwTotal
    Sleep(2000)

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

    $oDlg.StopProgressDialog()

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

    Func _CountUp()
    $dwCompleted += 1
    $oDlg.SetProgress($dwCompleted, $dwTotal)
    EndFunc

    [/autoit]
  • Zitat von Paule

    Ich blicke immer noch nicht, wie ich damit eine Datei oder mehere kopiere.
    Hast Du ein Beispiel?

    Das ist nur der Windows-Dialog beim Kopieren, verschieben, löschen, downloaden, etc., da kannst du im Hintergrund eigentlich jede x-beliebige Funktion so anpassen, dass sie mit dem Progressbalken zusammenpasst.

    Hier ein Beispiel für einen Download

    Spoiler anzeigen
    [autoit]

    #include <AutoItObject.au3>
    #include <WinAPI.au3>
    #include "IProgressDialog.intfc"

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

    _AutoItObject_StartUp()

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

    Global $FileToDownload = "http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe"
    Global $FileDestination = @ScriptDir & "/autoit-v3-setup.exe"

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

    Global $oDlg = _AutoItObject_ObjCreate($sCLSID_IProgressDialog, $sIID_IProgressDialog, $dtagIProgressDialog)

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

    $oDlg.SetTitle("Downloading...")
    $oDlg.SetAnimation(Number(_WinAPI_GetModuleHandle("shell32.dll")), $AVI_DOWNLOAD)
    $oDlg.SetLine(1, "File Download", 0, 0)
    $oDlg.SetLine(2, "autoit-v3-setup.exe from http://www.autoitscript.com", 0, 0)
    $oDlg.StartProgressDialog(0, 0, $PROGDLG_NOMINIMIZE, 0)

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

    Global $FileSize = InetGetSize($FileToDownload)
    Global $hDownload = InetGet($FileToDownload, $FileDestination, 1, 1)
    Global $Loaded, $TimeConstant = 500 ; 50 Sekunden

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

    Do
    Sleep(50)
    $Loaded = InetGetInfo($hDownload, -1)
    $Canceled = $oDlg.HasUserCancelled()
    $oDlg.SetProgress($Loaded[0] / $FileSize * $TimeConstant, $TimeConstant)
    Until $Canceled[0] = 1 Or $Loaded[2]

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

    InetClose($hDownload)

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

    $oDlg.StopProgressDialog()

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

    If $Loaded[2] Then
    MsgBox(64, "Info", "Datei erfolgreich heruntergeladen")
    Else
    MsgBox(16, "Fehler", "Der Download wurde abgebrochen")
    EndIf

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

    _AutoItObject_Shutdown()

    [/autoit]
  • Guten Morgen,

    ich habe mich mit den Objekten noch nicht so richtig angefreundet. Deshalb kommt hier eine "old-fashioned" Methode für die Nutzung der Shellfunktion SHFileOperation. Es gibt schon einen älteren Beitrag zum Thema, aber der ist schwer zu finden und ich habe mich deshalb nochmal damit beschäftigt (es meinem persönlichen Stil angepasst), um es hier dazu zu stellen:

    Demo.au3
    [autoit]

    #include "SHFileOperation.au3"

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

    $Func = $FO_COPY
    $From1 = @ScriptDir & "\Demo.au3"
    $From2 = @ScriptDir & "\SHFileOperation.au3"
    $From = $From1 & "|" & $From2
    $To = "F:\AutoIt_Backup"
    $Result = _SHFileOperation($Func, $From, $To)
    If @error Then
    MsgBox(0, "Error", @error & " - " & _SHFileOperation_GetErrorMessage(@extended))
    EndIf

    [/autoit]
    SHFileOperation.au3
    [autoit]

    #include-once

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

    ; #INDEX# =======================================================================================================================
    ; Title .........: SHFileOperation
    ; AutoIt Version : 3.3.6.1
    ; Description ...: Funktionen für den Aufruf der Shellfunktion SHFileOperation
    ; Author(s) .....: teh_hahn & Großvater (http://www.autoit.de)
    ; Dll ...........: Shell32.dll
    ; ===============================================================================================================================

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

    ; #CURRENT# =====================================================================================================================
    ; _SHFileOperation
    ; _SHFileOperation_GetErrorMessage
    ; ===============================================================================================================================

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

    ; #CONSTANTS# ===================================================================================================================
    ; wFunc: A value that indicates which operation to perform.
    Global Const $FO_MOVE = 0x0001
    Global Const $FO_COPY = 0x0002
    Global Const $FO_DELETE = 0x0003
    Global Const $FO_RENAME = 0x0004

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

    ; fFlags: Flags that control the file operation.
    Global Const $FOF_MULTIDESTFILES = 0x0001
    ; The pTo member specifies multiple destination files (one for each source file in pFrom)
    ; rather than one directory where all source files are to be deposited.
    Global Const $FOF_CONFIRMMOUSE = 0x0002
    ; Not used
    Global Const $FOF_SILENT = 0x0004
    ; Do not display a progress dialog box.
    Global Const $FOF_RENAMEONCOLLISION = 0x0008
    ; Give the file being operated on a new name in a move, copy, or rename operation
    ; if a file with the target name already exists at the destination.
    Global Const $FOF_NOCONFIRMATION = 0x0010
    ; Respond with Yes to All for any dialog box that is displayed.
    Global Const $FOF_WANTMAPPINGHANDLE = 0x0020
    ; Fill in SHFILEOPSTRUCT.hNameMappings; must be freed using SHFreeNameMappings
    Global Const $FOF_ALLOWUNDO = 0x0040
    ; Preserve undo information, if possible.
    ; If the source file parameter does not contain fully qualified path and file names, this flag is ignored.
    Global Const $FOF_FILESONLY = 0x0080
    ; Perform the operation only on files (not on folders) if a wildcard file name (*.*) is specified.
    Global Const $FOF_SIMPLEPROGRESS = 0x0100
    ; Display a progress dialog box but do not show individual file names as they are operated on.
    Global Const $FOF_NOCONFIRMMKDIR = 0x0200
    ; Do not ask the user to confirm the creation of a new directory if the operation requires one to be created.
    Global Const $FOF_NOERRORUI = 0x0400
    ; Do not display a dialog to the user if an error occurs.
    Global Const $FOF_NOCOPYSECURITYATTRIBS = 0x0800
    ; Do not copy the security attributes of the file.
    ; The destination file receives the security attributes of its new folder.
    Global Const $FOF_NORECURSION = 0x1000
    ; Only perform the operation in the local directory.
    ; Do not operate recursively into subdirectories, which is the default behavior.
    Global Const $FOF_NO_CONNECTED_ELEMENTS = 0x2000
    ; Do not move connected files as a group. Only move the specified files.
    Global Const $FOF_WANTNUKEWARNING = 0x4000
    ; Send a warning if a file is being permanently destroyed during a delete operation rather than recycled.
    ; This flag partially overrides FOF_NOCONFIRMATION.
    Global Const $FOF_NORECURSEREPARSE = 0x8000
    ; Not used.
    Global Const $FOF_NO_UI = BitOR($FOF_SILENT, $FOF_NOCONFIRMATION, $FOF_NOERRORUI, $FOF_NOCONFIRMMKDIR)
    ; Perform the operation silently, presenting no UI to the user. (Win Vista +)
    ; ===============================================================================================================================

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _SHFileOperation
    ; Description ...: Aufruf der Shellfunktion SHFileOperation zum Kopieren, Löschen, Verschieben und Umbenennen von Dateien und Ordnern
    ; Syntax.........: _SHFileOperation($uMode, $sFrom[, $sTo = ""[, $wFlags = 0x0[, $hWnd = 0[, $sTitle = ""]]]])
    ; Parameters ....: $wFunc - auszuführende Aktion - siehe $FO_ Konstanten
    ; $sFrom - Quellpfad(e) - siehe Remarks
    ; $sTo - Zielpfad(e) - siehe Remarks
    ; |Default = ""
    ; $wFlags - Vorgaben für die Ausführung - siehe $FOF_ Konstanten
    ; |Default = 0x0
    ; $hWnd - Handle des "besitzenden" Fensters (Owner)
    ; |Default = 0 (Desktop)
    ; $sTitle - Titel für den Dialog (wird nur berücksichtigt, wenn das Flag FOF_SIMPLEPROGRESS gesetzt ist)
    ; |Default = ""
    ; Return values .: Im Erfolgsfall: True - @extended enthält 1, wenn die Aktion vom Anwender abgebrochen wurde
    ; Im Fehlerfall: False - @error und @extended enthalten ergänzende fehlerbeschreibende Werte
    ; |@error
    ; |1 : Fehler beim DllCall SHFileOperationW - @extended enthält der Errorcode
    ; |2 : SHFileOperationW hat einen Fehler gemeldet - @extended enthält den Fehlercode
    ; Author ........: teh_hahn & Großvater (http://www.autoit.de)
    ; Modified.......:
    ; Remarks .......: In $sFrom und $sTo können mehrere durch Opt("GUIDataSeparatorChar") getrennte absolute Pfade übergeben
    ; werden. In $sFrom können im Dateinamensteil die üblichen DOS-Wildcards (z.B. *) verwendet werden, in
    ; $sTo sind sie nicht erlaubt. Die Verwendung von relativen Pfaden oder Wildcards in unzulässigen Bereichen
    ; führt laut MS zu "unvorhersagbaren Ergebnissen". Wenn $sTo mehrere Pfade enthält, müssen für jeden Pfad
    ; in $sFrom ein zugehöriger Pfad in $sTo übergeben und das Flag $FOF_MULTIDESTFILES gesetzt werden.
    ; Related .......: _SHFileOperation_GetErrorMessage
    ; Link ..........:
    ; Example .......:
    ; ===============================================================================================================================
    Func _SHFileOperation($wFunc, $sFrom, $sTo = "", $wFlags = 0x0, $hWnd = 0, $sTitle = "")
    ; http://msdn.microsoft.com/en-us/library/…28VS.85%29.aspx
    Local $tSHFILEOPSTRUCT = DllStructCreate("HWND hWnd;UINT wFunc;Ptr pFrom;Ptr pTo;WORD fFlags;BOOL fAborted;Ptr;Ptr pTitle")
    Local $Sep = Opt("GUIDataSeparatorChar")
    Local $iFrom = 0, $iTo = 0, $pTo = 0, $pTitle = 0
    While StringRight($sFrom, 1) = $Sep
    StringTrimRight($sFrom, 1)
    WEnd
    While StringRight($sTo, 1) = $Sep
    StringTrimRight($sTo, 1)
    WEnd
    $sFrom = StringReplace($sFrom & $Sep & $Sep, $Sep, Chr(0))
    $iFrom = @extended
    Local $tFrom = DllStructCreate("WChar[" & StringLen($sFrom) & "]")
    DllStructSetData($tFrom, 1, $sFrom)
    Local $pFrom = DllStructGetPtr($tFrom)
    If $sTo Then
    $sTo = StringReplace($sTo & $Sep & $Sep, $Sep, Chr(0))
    $iTo = @extended
    Local $tTo = DllStructCreate("WChar[" & StringLen($sTo) & "]")
    DllStructSetData($tTo, 1, $sTo)
    $pTo = DllStructGetPtr($tTo)
    EndIf
    If $iFrom > 2 And $iTo > 2 And $iFrom = $iTo Then
    $wFlags = BitOR($wFlags, $FOF_MULTIDESTFILES)
    EndIf
    If $sTitle Then
    Local $tTitle = DllStructCreate("WChar[" & StringLen($sTitle) + 1 & "]")
    DllStructSetData($tTitle, 1, $sTitle)
    $pTitle = DllStructGetPtr($tTitle)
    EndIf
    DllStructSetData($tSHFILEOPSTRUCT, "hWnd", $hWnd) ; hwnd
    DllStructSetData($tSHFILEOPSTRUCT, "wFunc", $wFunc) ; wFunc
    DllStructSetData($tSHFILEOPSTRUCT, "pFrom", $pFrom) ; pFrom
    DllStructSetData($tSHFILEOPSTRUCT, "pTo", $pTo) ; pTo
    DllStructSetData($tSHFILEOPSTRUCT, "fFlags", $wFlags) ; fFlags
    DllStructSetData($tSHFILEOPSTRUCT, "fAborted", 0) ; fAnyOperationsAborted
    DllStructSetData($tSHFILEOPSTRUCT, 7, 0) ; hNameMappings - wird nicht unterstützt
    DllStructSetData($tSHFILEOPSTRUCT, "pTitle", $pTitle) ; lpszProgressTitle
    Local $aResult = DllCall("Shell32.dll", "INT", "SHFileOperationW", "Ptr", DllStructGetPtr($tSHFILEOPSTRUCT))
    If @error <> 0 Then Return SetError(1, @error, False)
    If $aResult[0] <> 0 Then Return SetError(2, $aResult[0], False)
    If DllStructGetData($tSHFILEOPSTRUCT, "fAborted") Then Return SetExtended(1, True)
    Return True
    EndFunc ;==>_SHFileOperation

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _SHFileOperation_GetErrorMessage
    ; Description ...: Fehlertext für einen Fehlercode aus _SHFileOperation liefern
    ; Syntax.........: _SHFileOperation_GetErrorMessage($Error)
    ; Parameters ....: $Error - Numerischer Fehlercode aus _SHFileOperation
    ; Return values .: Im Erfolgsfall: Fehlertext
    ; Im Fehlerfall: "Unknown ErrorCode: " & $Error
    ; Author ........: Großvater (http://www.autoit.de)
    ; Modified.......:
    ; Remarks .......:
    ; Related .......: _SHFileOperation
    ; Link ..........:
    ; Example .......:
    ; ===============================================================================================================================
    Func _SHFileOperation_GetErrorMessage($Error)
    ; http://msdn.microsoft.com/en-us/library/…28VS.85%29.aspx
    Local Const $DE_00000071 = "The source and destination files are the same file."
    Local Const $DE_00000072 = "Multiple file paths were specified in the source buffer, but only one destination file path."
    Local Const $DE_00000073 = "Rename operation was specified but the destination path is a different directory. Use the move operation instead."
    Local Const $DE_00000074 = "The source is a root directory, which cannot be moved or renamed."
    Local Const $DE_00000075 = "The operation was canceled by the user, or silently canceled if the appropriate flags were supplied to SHFileOperation."
    Local Const $DE_00000076 = "The destination is a subtree of the source."
    Local Const $DE_00000078 = "Security settings denied access to the source."
    Local Const $DE_00000079 = "The source or destination path exceeded or would exceed MAX_PATH."
    Local Const $DE_0000007A = "The operation involved multiple destination paths, which can fail in the case of a move operation."
    Local Const $DE_0000007C = "The path in the source or destination or both was invalid."
    Local Const $DE_0000007D = "The source and destination have the same parent folder."
    Local Const $DE_0000007E = "The destination path is an existing file."
    Local Const $DE_00000080 = "The destination path is an existing folder."
    Local Const $DE_00000081 = "The name of the file exceeds MAX_PATH."
    Local Const $DE_00000082 = "The destination is a read-only CD-ROM, possibly unformatted."
    Local Const $DE_00000083 = "The destination is a read-only DVD, possibly unformatted."
    Local Const $DE_00000084 = "The destination is a writable CD-ROM, possibly unformatted."
    Local Const $DE_00000085 = "The file involved in the operation is too large for the destination media or file system."
    Local Const $DE_00000086 = "The source is a read-only CD-ROM, possibly unformatted."
    Local Const $DE_00000087 = "The source is a read-only DVD, possibly unformatted."
    Local Const $DE_00000088 = "The source is a writable CD-ROM, possibly unformatted."
    Local Const $DE_000000B7 = "MAX_PATH was exceeded during the operation."
    Local Const $DE_00000402 = "An unknown error occurred. This is typically due to an invalid path in the source or destination."
    Local Const $DE_00010000 = "An unspecified error occurred on the destination."
    Local Const $DE_00010074 = "Destination is a root directory and cannot be renamed."
    If IsDeclared("DE_" & Hex($Error)) = -1 Then Return Eval("DE_" & Hex($Error))
    Return "Unknown ErrorCode: " & Hex($Error)
    EndFunc ;==>_SHFileOperationGetError

    [/autoit]

    Einmal editiert, zuletzt von Großvater (14. Dezember 2010 um 14:02)

  • @grossvater

    habe dein Skript getestet mit dem Flag $FOF_MULTIDESTFILES

    Spoiler anzeigen
    [autoit]


    #include "SHFileOperation.au3"
    $Func = $FO_COPY
    $From = $From1 & "|" & $From2
    ;~ $From = "\\aspirehome\Save.TV-Aufnahmen\p*.mp4"
    $To = "E:\" & "|f:\"

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

    $Result = _SHFileOperation($Func, $From, $To, BitOR($FOF_RENAMEONCOLLISION, $FOF_MULTIDESTFILES))
    If @error Then
    MsgBox(0, "Error", @error & " - " & _SHFileOperation_GetErrorMessage(@extended))
    EndIf

    [/autoit]

    Dann bekomme ich eine Fehlermeldung:
    "Es ist bereits ein Ordner mit dem angebenen Namen vorhanden ......"

    Ich kann dann nur noch Wiederholen, Überspringen oder Abbrechen wählen.
    Betriebssystem Windows 7 64 Bit Ultimate.

    für was sind die Varibalen in der SHFileOperation.au3
    $iFrom, $iTo ?
    Die sind doch immer =0, so dass die IF Klausel überfüssig ist.

    If $iFrom > 2 And $iTo > 2 And $iFrom = $iTo Then
    $wFlags = BitOR($wFlags, $FOF_MULTIDESTFILES)
    EndIf

    Gruß Paule

  • Hallo Paule,

    vielen Dank erst einmal für Deinen Test.

    für was sind die Varibalen in der SHFileOperation.au3
    $iFrom, $iTo ?
    Die sind doch immer =0, so dass die IF Klausel überfüssig ist.


    Das ist wohl wahr. Ursprünglich wurden die Chr(0)-Ersetzungen in einer Schleife gemacht, in der ich auch die Variablen hochgezäht habe. Als ich dann sicher war, dass das nicht nötig ist, habe ich die Schreifen entfernt, ohne an die Zählerei zu denken. Ich habe das oben korrigiert. Danke! :)

    Dann bekomme ich eine Fehlermeldung:
    "Es ist bereits ein Ordner mit dem angebenen Namen vorhanden ......"
    Ich kann dann nur noch Wiederholen, Überspringen oder Abbrechen wählen.
    Betriebssystem Windows 7 64 Bit Ultimate.


    Der Name des Flags $FOF_MULTIDESTFILES ist wörtlich zu nehmen, SHFileOperation erwartet in pFrom und pTo mehrere Dateipfade in gleicher Anzahl. Es ist dann nicht möglich, einen Ordner oder ein Laufwerk als Ziel vorzugeben. Anstelle des Ordners wird eine gleichnamige Datei erstellt, wenn es ihn nicht gibt, bei einem Laufwerk ist das nicht möglich.

  • Danke @Großvater

    Spoiler anzeigen
    [autoit]


    #include "SHFileOperation.au3"

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

    $Func = $FO_COPY
    $From1 = "\\aspirehome\Save.TV-Aufnahmen\check\360_Geo_Reportage_Die_verrückten_Karren_des_Mister_Winfield_11-12-2010_1930_348937.mp4"
    $From2 = "\\aspirehome\Save.TV-Aufnahmen\check\Extreme_Rage_11-12-2010_2230_348937.mp4"

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

    $From1 = "f:\Acronis.iso"
    $From2 = "f:\kasperski.iso"

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

    $From = $From1 & "|" & $From2
    ;~ $From = "\\aspirehome\Save.TV-Aufnahmen\p*.mp4"
    $To = "E:\Acronis.iso" & "|f:\kasperski.iso"

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

    $Result = _SHFileOperation($Func, $From, $To, BitOR($FOF_RENAMEONCOLLISION, $FOF_MULTIDESTFILES))
    If @error Then
    MsgBox(0, "Error", @error & " - " & _SHFileOperation_GetErrorMessage(@extended))
    EndIf

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

    Jepp, jetzt funktioniert es.

    Gruß Paule