Welcome to MSDN Blogs Sign in | Join | Help

CTaskDialog: an alternative to the simple message box!

Hello everybody,

Let me introduce myself, my name is Lukasz Chodorski and I am a new SDE in the Visual C++ Libraries Team. In this post I would like to present to you the CTaskDialog class which wraps the Windows API* in the MFC library. What actually is the CTaskDialog? It is a class/component which can be easily customized depending on your application’s needs. You can set following elements on the CTaskDialog:

·         Window title

·         Main icon

·         Main instruction

·         Content

·         Progress bar

·         Radio buttons

·         Custom button

·         Expand/collapse button

·         Verification check box

·         Footer icon

·         Footer text

·         Common button

So, as you can see there are many configuration options which can be set. In the simplest configuration, it looks like a standard message box, but in more advanced forms it can have progress bars, custom buttons or radio buttons. It is even possible to define a http link in the control’s text or create a simple wizard. Also, the MFC implementation provides a simple mechanism that allows the developer to handle dialog events.

The CTaskDialog API delivers simple methods to create and initialise controls. For instance:

CTaskDialog dlg(_T("A CTaskDialog presents information in a clear and consistent way."),

                     _T("How much do you like CTaskDialog?"), _T("Sample CTaskDialog"), 0,

                     TDF_ENABLE_HYPERLINKS | TDF_USE_COMMAND_LINKS , _T("I hope you like it!"));

 

       dlg.AddCommandControl( 10, _T("&Use it!\nIt's the best dialog you can have!"));

       dlg.AddCommandControl( 20, _T("&Maybe?\nDon't you want to try it?"));

       dlg.AddCommandControl( 25, _T("&No way!\nI'm not going to use it!"));

      

       dlg.AddRadioButton( 3, _T("Lots"));

       dlg.AddRadioButton( 7, _T("A little"));

       dlg.AddRadioButton( 4, _T("Not at all"));

      

    dlg.SetMainIcon(TD_SHIELD_ICON);

       dlg.SetFooterIcon(TD_INFORMATION_ICON);

      

       INT_PTR nResult = dlg.DoModal();

It creates the following window:

 

Or the one line function call:

INT_PTR nResult = CTaskDialog::ShowDialog(

                     _T("Don't spend to much time on code, write only one line and get your CTaskDialog!"),

                     _T("Where do you like to go?"),

                     _T("One line command"), IDS_RADIO_START, IDS_RADIO_START + 3, TDCBF_CANCEL_BUTTON);

This feature was introduced in Windows Vista, thus it is required for the _WIN32_WINNT define to be set to 0x0600 (value for Windows Vista) or higher. Anyway, it is set per default to Windows Vista in targetver.h file. You should be aware that Windows provides two comctl32.dll libraries (version 5.x.x.x and 6.x.x.x). The CTaskDialog requires version 6.x.x.x or higher, that is why the VC10 adds the required information to the application manifest file. When you get the error message: “The ordinal XXX could not be located in the dynamic link library COMCTL32.dll.” it means that your operating system used the incorrect library version for the application. This can be caused by the wrong assemblies’ configuration in manifest file – external or internal one. To force Windows to use the appropriate version of library it is necessary to add the following snippet into the manifest file.

<dependency>

    <dependentAssembly>

      <assemblyIdentity

          type="win32"

          name="Microsoft.Windows.Common-Controls"

          version="6.0.0.0"

          processorArchitecture="x86"

          publicKeyToken="6595b64144ccf1df"

          language="*"

        />

    </dependentAssembly>

  </dependency>

Operating systems below Windows Vista does not support the TaskDialog API. To check the availability of CTaskDialog it is possible to use the CTaskDialog::IsSupported() method. The simple workaround for this problem would be:

if (CTaskDialog::IsSupported()) 

{

       ... //call CTaskDialog

}

else MessageBox();  //call standard message box

The described feature is a part of the Microsoft Pre-release Software Visual Studio 2010 and .NET Framework 4.0 Community Technology Preview (CTP) which can be downloaded from http://www.microsoft.com/downloads/details.aspx?FamilyId=922B4655-93D0-4476-BDA4-94CF5F8D4814 . The sample application, which uses CTaskDialog, is provided with Visual Studio 2010 and is placed in the Samples directory.

I hope that I’ve encouraged you to use CTaskDialog. Feedback is always appreciated J.

Thx!

Lukasz

--

* More information about it you can be found on MSDN page (http://msdn.microsoft.com/en-us/library/bb760441(VS.85).aspx ).

Published Thursday, December 04, 2008 10:24 AM by vcblog

Comments

Thursday, December 04, 2008 9:49 PM by hereafter

# re: CTaskDialog: an alternative to the simple message box!

Yea, i like it, but could u please announce that you are fixing the damn VC++ intellise bugs first??? so damn annoying

Friday, December 05, 2008 3:18 AM by Karlis

# re: CTaskDialog: an alternative to the simple message box!

Yea, the intellisense in VS08 tends to die on a regular basis, it gets pretty annoying on a larger project. Sometimes you have to close solution, delete .ncb, and start again every 10 minutes.

Friday, December 05, 2008 5:14 AM by Roel

# re: CTaskDialog: an alternative to the simple message box!

Maybe you could implement a version that doesn't depend on Vista - how hard could it be? As it is, with nobody using Vista, it's a pain to use this class...

Friday, December 05, 2008 5:25 AM by pingpong

# re: CTaskDialog: an alternative to the simple message box!

I'm not impressed. After years of neglecting VC++ and MFC majority of users can wrap the Win32 APIs by themselves for MFC consumption.

I'd like to second what Roel said - provide the fallback task dialog implementation for W2K/XP, otherwise nobody will bother.

Friday, December 05, 2008 7:32 AM by Andre

# re: CTaskDialog: an alternative to the simple message box!

I also don't care much about this MFC addition, Codejock has implemented the Task Dialog in their Xtreme Toolkit Pro since a year or so. It either uses the Win32 API on Vista and above or emulates it on any other Windows version. Much better than CTaskDialog::IsSupported().

Friday, December 05, 2008 12:52 PM by R.J

# re: CTaskDialog: an alternative to the simple message box!

Personally, I prefer Qt + Intel C++ Compiler (good conformance) + VS IDE (I haven't found a better choice yet).

And for MFC development, I use Codejock and BCG libraries.

Microsoft is about 3 or 4 years behind in native C++ application development.

Sunday, December 07, 2008 9:19 PM by MR

# re: CTaskDialog: an alternative to the simple message box!

Absolutely agree with others. Anyone who relies on C++/MFC to do their product development (and *many* of us do) have long since moved on.

CodeJock provides an excellent task dialog implementation that's backward compatible, along with many other excellent component implementations.

Monday, December 08, 2008 2:54 AM by Anders Dalvander

# re: CTaskDialog: an alternative to the simple message box!

I agree with Andre and others: it should be emulated if not running Vista, as in Xtreme Toolkit Pro.

Monday, December 08, 2008 9:52 AM by Andre

# re: CTaskDialog: an alternative to the simple message box!

@Anders Dalvander: The C++ team doesn't seem to have enough resources for such things nowadays. Also it shouldn't have to be emulated in the first place on pre Vista versions, but the Shell team also doesn't seem to care about ISVs anymore. Why can't I use version 6.x.x.x of the common controls on XP?

Also why isn't the CTaskDialog in VS2008, thought that's the version targeting Vista? Oh, not enough resources.

Maybe we should start a "MFC Lite" project which can be used with the Toolkits available on the market so that we can drop MFC altogether.

Monday, December 08, 2008 3:33 PM by vcblog

# re: CTaskDialog: an alternative to the simple message box!

Hello

Re: hereafter and Karlis

Thanks very much for taking the time to post and for your feedback. I just replied on another thread to the Intellisense issue, so rather than repeat myself here, can I point you there to take a look:

http://blogs.msdn.com/vcblog/archive/2008/11/21/soma-blog-vc-enhancements-in-vs-2010.aspx#9180817

Thanks

Damien

--

PS: Also can I just check, have you seen Jim Springfield’s posts on Intellisense in VS2008 too:

http://blogs.msdn.com/vcblog/archive/2008/02/29/intellisense-part-2-the-future.aspx

http://blogs.msdn.com/vcblog/archive/2007/12/18/intellisense-history-part-1.aspx

http://blogs.msdn.com/vcblog/archive/2007/11/19/controlling-intellisense-through-macros.aspx

Monday, December 08, 2008 8:15 PM by vcblog

# re: CTaskDialog: an alternative to the simple message box!

Hello

Re: Roel, pingpong, Andre, R.J, MR , Anders Dalvander

Firstly, thanks so much for taking the time to comment – I am always impressed by the enthusiasm of the MFC community whenever we post. Secondly, it is true to say that we did neglect MFC for a while – this is something we are actively addressing in VS2010 (and of course with VS2008 SP1 and the MFC Update http://blogs.msdn.com/vcblog/archive/2008/04/07/visual-c-2008-feature-pack-released.aspx.)

I do want to point out that the CtaskDialog is only the first VS2010 MFC addition that we have spoken about, as we head towards VS2010 please stay tuned for more.

Thanks

Damien

Tuesday, December 09, 2008 4:26 AM by R.J

# re: CTaskDialog: an alternative to the simple message box!

If you want to add something useful to MFC please add a good and flexible grid control like what BCG and CodeJock did.

Add an automatic layout management for dialogs and forms.

And also a reporting system like crystal reports or Microsoft Report for .Net is really missing. Unfortunately I even couldn't find a 3rd party one. Guys please tell me if there is any.

At the end I always dreamed about an extensible XML based GUI library in VC so that I can separate designing GUI from other part of development.

Tuesday, December 09, 2008 3:39 PM by vcblog

# re: CTaskDialog: an alternative to the simple message box!

Hello R.J

Thanks very much for the list – a number of these items have been suggested before and it is always great to see which items most developers request (most often.) Ale and I had coffee yesterday and went over many of the suggestions/requests we have seen recently. Of course I do need to insert the usual disclaimer, I can definitely say that they will not all make VS2010, but I hope when you see VS2010 you will be pleased.

Thanks

Damien

Tuesday, December 09, 2008 5:08 PM by vcblog

# re: CTaskDialog: an alternative to the simple message box!

Hello

PS: please feel free to log a "Connect Suggestion" on items like the CTaskDialog being supported on pre-Vista operating systems too at: http://connect.microsoft.com/.

Thanks

Damien

Wednesday, December 10, 2008 9:51 AM by PJ Naughter

# re: CTaskDialog: an alternative to the simple message box!

If you guys are interested in an emulated version of a Task Dialog from every OS from Windows 98 upwards, check out my freeware XTaskDialog implementation at http://www.naughter.com/xtaskdialog.html. It also provides a MFC wrapping for the Vista native implementation as well as ASCII thunking to the Unicode only Task Dialog API. It's been available from March 2007, plus you do not need to wait for VS 2010 to use it!

P.J. Naughter

Visual C++ MVP

Wednesday, December 17, 2008 9:10 AM by Erik Cox

# re: CTaskDialog: an alternative to the simple message box!

Nice post but basically I agree with the people here that have said that you should provide the fallback task dialog implementation for W2K/<a href="http://www.notionsolutions.com">XP</a>, or nobody will bother...cause truly no one will...

New Comments to this post are disabled
 
Page view tracker