Jump to content

Windows Copy Paste GUI Status


Recommended Posts

https://www.blogsdna.com/wp-content/uploads/2012/07/t1.png?ezimgfmt=ng:webp/ngcb2

Link above shows an image of what I'm talking about.
I would like to make a script that plays a sound, notifies me, or does something on every event happening in this window.

The events I currently work with are copying is finished: option to shutdown or play a sound.
Every 10% it plays a beep slightly higher (10% = lowest beep, 90% = highest beep).

On errors "file is to big" or "can't be copied" etc.. or if the gui needs me to push e.g. "overwrite existing files" it needs to play an alarm sound.

Why all this effort? I copy a lot of big files to backup drives and sometimes need to shutdown my pc afterwards or wait for long periods of time.
It would be handy to watch some TV while my pc is monitoring how copy-pasting is going and play sounds if it needs me for example.

Does anyone know a better way of handling these events and how to get every possible event to work with?

Also there a a few ways of getting the progress percentage:

#Include <SendMessage.au3>
#include <ProgressConstants.au3>

$copy_paste_gui_handle = WinGetHandle('[class:#32770]')
$copy_paste_gui_progressbar_handle = ControlGetHandle($copy_paste_gui_handle, '', '[CLASS:msctls_progress32; INSTANCE:1]')

$old_percentage = 0

While 1
    
    $current_percentage = _SendMessage($copy_paste_gui_progressbar_handle, $PBM_GETPOS, 0, 0)
    
    If $current_percentage > $old_percentage then
        
        $old_percentage = $current_percentage
        ConsoleWrite(@CRLF & $current_percentage)
        
        Switch $current_percentage
            Case 100, 200, 300, 400, 500, 600, 700, 800, 900
                Beep($current_percentage * 5, 500)
        EndSwitch
        
    EndIf
    
    If $current_percentage = 1000 Then
        SoundPlay('Done.wav', 1)
        ExitLoop ; 1000 = max
    EndIf
    
WEnd

Second (older) code snippet uses windows 10 title, ....but i use windows 11 now and it had a different appearance:

Local $hwnd = WinGetHandle('[class:OperationStatusWindow]')

While BitAND(WinGetState($hWnd), 2)
$status = WinGetTitle($hwnd)
Switch $status
            Case 'Replace or Skip Files', 'Item Not Found', 'Item in use'
                SoundPlay(@ScriptDir & '\warning.wav')

            Case '10% complete'
                SoundPlay(@ScriptDir & '\1.wav')
            Case '20% complete'
                SoundPlay(@ScriptDir & '\2.wav')
            Case '30% complete'
                SoundPlay(@ScriptDir & '\3.wav')
            Case '40% complete'
                SoundPlay(@ScriptDir & '\4.wav')
            Case '50% complete'
                SoundPlay(@ScriptDir & '\5.wav')
            Case '60% complete'
                SoundPlay(@ScriptDir & '\6.wav')
            Case '70% complete'
                SoundPlay(@ScriptDir & '\7.wav')
            Case '80% complete'
                SoundPlay(@ScriptDir & '\8.wav')
            Case '90% complete'
                SoundPlay(@ScriptDir & '\9.wav')

        EndSwitch
WEnd
Edited by TheAutomator
Link to post
Share on other sites

If you need more control, maybe you should use WinApi: _WinAPI_CopyFileEx  I'm sorry I don't find documentation help file to post hyperlink. There is an example on AutoIt help file.

This WinApi allows to create a callback function for a progress bar too.

In my opinion, it's better to check things before it happens and take control than respond to unexpected events. This way you only need to play a sound when everything finish, because you are sure it will work (because you coded). You could create a log file, shutdown computer automatically at the end, etc.

Instead of "overwritting" you could check weather File previously exists or not.
For "file is too big" you could check file size before trying to copy it.

"file can't be copied' is just to check result value of CopyFileEx and GetlastError as help file says.

 

Since you didn't say who launched the copy process, may be this couldn't be implemented...

Link to post
Share on other sites

There is also the PBM_GETSTATE message that you could use to query the state of the progress bar.  I personally wouldn't use title to check the status of the bar, as I am using a french version of OS, so my script wouldn't be exportable.

Link to post
Share on other sites
12 hours ago, Nine said:

There is also the PBM_GETSTATE message that you could use to query the state of the progress bar.  I personally wouldn't use title to check the status of the bar, as I am using a french version of OS, so my script wouldn't be exportable.

I kinda have to use the title, how else would I look for copy errors that halt the progress unfortunately.. PBM_GETSTATE is a control command or a _winapi function argument?
Can you give an example on how to use it?

@Lepes, I'm gonna look into that, thanks :)

Link to post
Share on other sites

Same as the other :

Local $iState = _SendMessage($copy_paste_gui_progressbar_handle, $PBM_GETSTATE, 0, 0)

Possible return value :

  • PBST_NORMAL = In progress.
  • PBST_ERROR = Error.
  • PBST_PAUSED = Paused.
Link to post
Share on other sites
On 12/2/2022 at 2:08 PM, Nine said:

Same as the other :

Local $iState = _SendMessage($copy_paste_gui_progressbar_handle, $PBM_GETSTATE, 0, 0)

Possible return value :

  • PBST_NORMAL = In progress.
  • PBST_ERROR = Error.
  • PBST_PAUSED = Paused.

Oh I see :) and PBST_ERROR is for when there is an error setting / reading a value to the progressbar I suppose?
Thanks for the example, didn't know i was for _sendmessage.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...