[VB6] Class to display a standard Explorer-style progress window
cProgressWindow
Windows provides a simple interface that allows you to use an asychronous Explorer-style progress dialog with just a few lines of code. So I thought I'd wrap up this functionality in a class to make it a bit easier to use, especially with automating checking for cancel, raising an event for it, and closing the dialog.
It's all pretty self-explanatory... the class comes with a demo project that shows usage of the most basic options, and the class itself implements all the functionality (except setting an animation, because that's only supported in XP).
Requirements
Windows XP or newer oleexp.tlb, any version (or olelib)
Future Work
If you're working with files, you may want the more detailed progress window that you get with IFileOperation and Explorer in Windows 7... you can manually control such a progress dialog in a manner similar to this one with another interface supported by the same ProgressDialog object, IOperationsProgressDialog. You can then use it like this or as the custom dialog from IFileOperation.SetProgressDialog.
I'll be putting up a demo of using that interface in a few days, but if you wanted to experiment in the mean time, all the definitions are already in oleexp (but this one isn't XP compatible and not present in olelib), and you can create an instance of it via
Code:
Dim cProg As IOperationsProgressDialog
Set cProg = New ProgressDialog
Note that with this version, your first call must be .StartProgressDialog, or you get a 'catastrophic error' message. Also always use .SetMode, or the dialog might just flash at the end of the operation instead of show throughout.
Last edited by fafalone; Mar 17th, 2020 at 05:44 AM.
Re: [VB6] Class to show a standard Explorer-style progress window
Hi fafalone,
This actually looks pretty cool. I've got many things I do that take a bit of time, most to do with Word and Excel automation. I've got this clunky "Working" window I throw onto the screen, and I'm considering swapping it out with your work. But, a few questions, if you don't mind:
1) Can you have it display without the "Cancel" button?
2) Can you programmatically position it anywhere on the screen? My users like my "Working" box to display up in the top-left corner.
3) Does it have an option for a "Show More", similar to when Windows is doing a large copy? In certain instances, I will need to update my users to how things are progressing. For example, here's a snippet of how I use my "Working" form:
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
As for your questions:
1. No Cancel button. Yes for Vista+. It's an optional flag in the StartProgressDialog function: PROGDLG_NOCANCEL
2. Positioning dialog. Don't see anywhere that the interface offers the dialog's hWnd. But we can typically get this by creating a hook just before displaying it, wait for dialog to be created, then positioning it and removing the hook
3. Changing the text. Yes. In the class that fafalone provided are comments regarding that.
Note: There is no "show more" option that I see. The TaskDialog implementation (Vista+ message box overhaul) offers that functionality along with progress bar but IIRC can't opt for button-free dialog without a bit of work to find the default "Ok" button and hide it. Can you disable it instead? Maybe, don't recall at the moment.
Last edited by LaVolpe; Jan 6th, 2018 at 11:06 AM.
Insomnia is just a byproduct of, "It can't be done"
Re: [VB6] Class to show a standard Explorer-style progress window
@LaVolpe: Thanks. I'm not going to jump on this today, but it's definitely going on the "todo" list. Here's my little "Working" form that I currently use:
I just change that lower label to report to the user what step we're on. It would take a bit of work, but I could estimate the percentage done as well. I suppose I could build my own bleed-bar, but just letting Windows take care of it sounds nice.
Again, Thanks,
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
Re: [VB6] Class to show a standard Explorer-style progress window
I just did a large copy. It's actually the "More details" "Fewer details" option that's nice. I could totally see my way to reporting my progress details in that area.
I'm also wondering when that got introduced in Windows.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
Re: [VB6] Class to show a standard Explorer-style progress window
Originally Posted by Elroy
I just did a large copy. It's actually the "More details" "Fewer details" option that's nice. I could totally see my way to reporting my progress details in that area.
I'm also wondering when that got introduced in Windows.
IOperationsProgressDialog usage gives you the "More/Fewer Details" option. That interface can be applied via IFileOperation which is the modern replacement for SHFileOperation API. Offered with Vista and beyond. The details button doesn't exist with the standard IProgressDialog shown in this posting. IProgressDialog is basically a generic, somewhat customizable, dialog.
Insomnia is just a byproduct of, "It can't be done"
Re: [VB6] Class to show a standard Explorer-style progress window
Thank you, LaVolpe.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
Re: [VB6] Class to show a standard Explorer-style progress window
The Show More option is part of IOperationsProgressDialog that's supported by the same default implementation (CLSID_ProgressDialog ProgressDialog object in the tlb). There's a note about it at the bottom of the first post (Future Work); you can use it just like this one too and I'll be posting a similar class for it soon; haven't been able to check in here for a couple days, sorry.
Re: [VB6] Class to show a standard Explorer-style progress window
Originally Posted by Elroy
...
2) Can you programmatically position it anywhere on the screen? My users like my "Working" box to display up in the top-left corner.
...
Elroy
Using an interface scanner I found out that ProgressDialog also supports these interfaces:
IOperationsProgressDialog, IActionProgressDialog, IActionProgress, IObjectWithSite, IOleWindow
Take the latter one to position the window altering the procedure OpenProgressWindow in the class e.g. as follows:
Code:
Public Sub OpenProgressWindow(dwFlags As PROGDLG, Optional hWndOwner As Long = 0&)
m_hOwner = hWndOwner
m_lFlag = dwFlags
cProg.StartProgressDialog m_hOwner, Nothing, m_lFlag
Dim IOLEW As IOleWindow
Dim hwnd As Long
Const SWP_NOSIZE = 1&
Const SWP_SHOWWINDOW = &H40
DoEvents
Set IOLEW = cProg
hwnd = IOLEW.GetWindow
If hwnd <> 0 Then
SetWindowPos hwnd, 0&, 10&, 10&, 0&, 0&, SWP_NOSIZE Or SWP_SHOWWINDOW
End If
End Sub
This moves the progress window to the left corner of the display (10&,10&).
You need furthermore to declare this API in the modules header:
Code:
Private Declare Function SetWindowPos Lib "user32.dll" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Should mention that the most of the other interfaces throw automation errors when using their methods.
Last edited by SaschaT; Jan 26th, 2018 at 12:56 PM.