Sign in to follow this  
Followers 0
funkey

Use own windows Copy (or move) dialog box

4 posts in this topic

Here is my result of today. I made to show the windows coping progress dialog.

This could be usefull sometimes.

You will need the objbase-UDF from progandy.

Have fun!

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

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

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

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

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

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

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"

_OLEInitialize()

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

Global $hParent = HWnd(0)
Global $sTitle = "Copying..."
Global $dwFlags = $PROGDLG_NOMINIMIZE
Global $hInstAnimation = _WinAPI_GetModuleHandle("shell32.dll")
Global $idAnimation = $AVI_COPY
Global $dwCompleted = 0
Global $dwTotal = 600 ;1 minute every 100ms one percent
Global $dwTimerAction = $PDTIMER_PAUSE
Global $strCancelMsg = "Cancel Button pressed ;)"
Global $dwLineNum = 1
Global $strText = "A very big File.dat"
Global $fCompactPath = 0
Global $pvReserved = 0

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

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

_ObjFuncCall($HRESULT, $aObj, "SetLine", "dword", $dwLineNum, "wstr", $strText, "long", $fCompactPath, "dword", $pvReserved)
$dwLineNum = 2
$strText = 'From "Folder" to "Folder_new"'
_ObjFuncCall($HRESULT, $aObj, "SetLine", "dword", $dwLineNum, "wstr", $strText, "long", $fCompactPath, "dword", $pvReserved)

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

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

AdlibRegister("_CountUp", 100)

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

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

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

Copy Dialog.au3

objbase.au3


Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello,

progandy now told me how to do the same using AutoItObject.

Here is a sample for downloading a file from internet.

#include <AutoItObject.au3>
#include <WinAPI.au3>

;===============================================================================
#API "Windows Progress Dialog"
; IProgressDialog
;===============================================================================

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

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

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

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

; Definition
Global Const $dtagIProgressDialog = $dtagIUnknown & _
  "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();"
; List
Global Const $ltagIProgressDialog = $ltagIUnknown & _
  "StartProgressDialog;" & _
  "StopProgressDialog;" & _
  "SetTitle;" & _
  "SetAnimation;" & _
  "HasUserCancelled;" & _
  "SetProgress;" & _
  "SetProgress64;" & _
  "SetLine;" & _
  "SetCancelMsg;" & _
  "Timer;"
;===============================================================================

_AutoItObject_StartUp()

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

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

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

Global $FileSize = InetGetSize($FileToDownload)
Global $hDownload = InetGet($FileToDownload, $FileDestination, 1, 1)
Global $Loaded, $Loaded_old[6], $TimeConstant = 100000
Global $dwCompleted = 0
Global $Diff, $Start = TimerInit()

Do
Sleep(500)
$Diff = TimerDiff($Start)
$dwCompleted = StringFormat("%.0f", $Diff / 100)
$Canceled = $oDlg.HasUserCancelled()
$Loaded = InetGetInfo($hDownload, -1)
$TimeConstant = StringFormat("%.0f", 1 / (($Loaded[0] - $Loaded_old[0]) * 2) * ($FileSize - $Loaded[0]) * 10) + $dwCompleted
$oDlg.SetProgress($dwCompleted, $TimeConstant)
$oDlg.SetLine(2, StringFormat("%.0f %% from %.2f MB (%.0f kB/sec)", $Loaded[0] / $FileSize * 100, $FileSize / (1024 * 1024), ($Loaded[0] - $Loaded_old[0]) * 2 / 1024), 0, 0)
$Loaded_old = $Loaded
Until $Canceled[0] = 1 Or $Loaded[2]

InetClose($hDownload)

$oDlg.StopProgressDialog()
$oDlg = 0

If $Loaded[2] Then
MsgBox(64, "Info", "File successfully downloaded")
Else
FileDelete($FileDestination)
MsgBox(16, "Error", "The download was aborted")
EndIf

_AutoItObject_Shutdown()
Edited by funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

May I just add that proper would be to release the object before the end to avoid possible problems when AutoIt attempts to do that on exit and after/if the connection with object is lost. Your $oDlg is declared as global variable.

$oDlg.StopProgressDialog()
$oDlg = 0
;...

Very nice, btw.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Thank you very much, trancexx!!

I did not know how to release the object, but I knew the error at the exit and just wanted to ask how to do it right. Now it works perfekt from the beginning to the end. Big thx.


Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
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
Sign in to follow this  
Followers 0