|
|
Task Dialog for Windows 98
At last in Windows Vista we now have the Task Dialog to replace the MessageBox API so we can have all the nice little gimmicks that we have always yearned for. Like a checkbox that says "Only display this message once", the ability to have timed messages, or just to have sensible button captions so we no longer have to see popup messages like this:
One of the great new features in the WTL 8 library is the
ability to dynamically construct dialogs.
You may not immediately recognize what you would use such a feature for
but try to imagine that you just downloaded the Visual Studio Express version
and panicked when you discovered that it did not come with a Resource Editor.
Of course you can download a free
Resource Editor
off the Internet, but when you panic you often learn something new and the
new
The problem with the Windows Vista Task Dialog is just that. It's a
Windows Vista-only component.
The control presented here is a remake of the Task Dialog.
It captures nearly all the functionality and works on platforms from Windows 98
and above.
It doesn't try to preserve the unique Vista theme visuals though, but instead
render its controls with the native look of the platform you're running on.
Nor does it use scores of custom painted controls to emulate all the
features of the Vista version. For some parts (such as the ability to embed
HTML links in the footer text) it just leaves them out when there is no
support on the platform it runs on.
Dynamic DialogsThe dialog implementation is available in a separate C++ class calledCTask98DialogImpl. This is the class that does dynamic construction
of the dialog elements based on the passed Task Dialog configuration. Don't be
scared by the plentiful code, it does a number of checks to determine the
size of the window and how to best fit the controls.
The dialog passes through 2 phases to construct the dialog:
First it attempts to decide on the optimal dimensions of the dialog and then
it constructs the dialog with its controls.
Various types of controls are used to display the buttons, Command Links etc. on
the different platforms. Command Links are only supported on Vista so they must
be emulated in other versions of Windows.
The dialog is constructed in-memory using the WTL The native Vista Task Dialog shies away from using a traditional dialog. Instead it uses the now mythical DirectUser library, which is an internally developed - partially windowless - library used by Microsoft. I suspect it has some form of automatic layout algorithm like I experimented with in my windowless test project. Using the controlTo use this control, there are some new functions which mimic the API for the original Task Dialog component.
You call these with the same arguments as the original Task Dialog, except that
the Task98Dialog function takes a string type as defined by your
project settings (UNICODE or MBCS). This makes it slightly easier to
use in legacy applications.
The Task98DialogIndirect function takes the same configuration
structure as the original Task Dialog function.
It also implements the callback functionality so you can override the
behaviour of the Task Dialog.
The
This call doesn't actually give you much new functionality that you didn't
already have with the old MessageBox call.
To make use of all the Task Dialog's functionality you'll need to call the
Task98DialogIndirect method. Here's an example that adds
a verification checkbox and a couple of custom buttons.
If you really want to take control of the dialog, you can attach a callback
function and process notifications when something happens on the dialog.
For instance, when the dialog is constructed it will send the
This produces a dialog with a Progress Bar control. The callback will step the
Progress Bar whenever it gets called with the timer notification (ignited by
the TDF_CALLBACK_TIMER flag). When the Progress Bar reaches 100%
it will automatically press the OK button.
Finally, if you are more comfortable with using the WTL TaskDialog wrapper style of code, this is also possible. Here is a similar example, rewritten to use inheritance programming style:
Ironically, you will need to define a few string resources and add a couple
of icons to your project before you can use this dynamically created dialog.
Have a look in the sample project attached below for more examples.
This should help the pain of converting everything to UNICODE if
your project is not already compiled as that.
NotesThis code requires a version of WTL greater than 8.0 since there
is a bug in the
atldlgs.h code which occasionally prevents
large dialogs from being constructed. Please get the latest version
from the
SourceForge
download area or the latest files from the Subversion repository.Source Code DependenciesMicrosoft WTL 8.5 LibraryDownload Files
Written by Bjarke Viksoe. Article submitted 1/3/2008. To the top
|
|||