CTaskDialog: an alternative to the simple message box!

CTaskDialog: an alternative to the simple message box!

  • Comments 16

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"));





       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.













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.




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

Leave a Comment
  • Please add 6 and 8 and type the answer here:
  • Post
  • Yea, i like it, but could u please announce that you are fixing the damn VC++ intellise bugs first??? so damn annoying

  • 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.

  • 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...

  • 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.

  • 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().

  • 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.

  • 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.

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

  • @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.

  • 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:





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




  • 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.



  • 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.

  • 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.



  • 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/.



  • 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

Page 1 of 2 (16 items) 12