{"id":4723,"date":"2008-12-04T13:24:00","date_gmt":"2008-12-04T13:24:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2008\/12\/04\/ctaskdialog-an-alternative-to-the-simple-message-box\/"},"modified":"2019-02-18T18:53:57","modified_gmt":"2019-02-18T18:53:57","slug":"ctaskdialog-an-alternative-to-the-simple-message-box","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/ctaskdialog-an-alternative-to-the-simple-message-box\/","title":{"rendered":"CTaskDialog: an alternative to the simple message box!"},"content":{"rendered":"<p class=\"MsoNormal\"><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">Hello everybody,<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">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 <b>CTaskDialog<\/b> class which wraps the Windows API* in the MFC library. What actually is the <b>CTaskDialog<\/b>? It is a class\/component which can be easily customized depending on your application\u2019s needs. You can set following elements on the <b>CTaskDialog<\/b>:<\/font><\/span><\/p>\n<p class=\"MsoListParagraphCxSpFirst\"><span lang=\"EN-CA\"><span><font size=\"3\">\u00b7<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">Window title<\/font><\/span><\/p>\n<p class=\"MsoListParagraphCxSpMiddle\"><span lang=\"EN-CA\"><span><font size=\"3\">\u00b7<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">Main icon<\/font><\/span><\/p>\n<p class=\"MsoListParagraphCxSpMiddle\"><span lang=\"EN-CA\"><span><font size=\"3\">\u00b7<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">Main instruction<\/font><\/span><\/p>\n<p class=\"MsoListParagraphCxSpMiddle\"><span lang=\"EN-CA\"><span><font size=\"3\">\u00b7<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">Content<\/font><\/span><\/p>\n<p class=\"MsoListParagraphCxSpMiddle\"><span lang=\"EN-CA\"><span><font size=\"3\">\u00b7<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">Progress bar<\/font><\/span><\/p>\n<p class=\"MsoListParagraphCxSpMiddle\"><span lang=\"EN-CA\"><span><font size=\"3\">\u00b7<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">Radio buttons<\/font><\/span><\/p>\n<p class=\"MsoListParagraphCxSpMiddle\"><span lang=\"EN-CA\"><span><font size=\"3\">\u00b7<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">Custom button<\/font><\/span><\/p>\n<p class=\"MsoListParagraphCxSpMiddle\"><span lang=\"EN-CA\"><span><font size=\"3\">\u00b7<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">Expand\/collapse button<\/font><\/span><\/p>\n<p class=\"MsoListParagraphCxSpMiddle\"><span lang=\"EN-CA\"><span><font size=\"3\">\u00b7<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">Verification check box<\/font><\/span><\/p>\n<p class=\"MsoListParagraphCxSpMiddle\"><span lang=\"EN-CA\"><span><font size=\"3\">\u00b7<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">Footer icon<\/font><\/span><\/p>\n<p class=\"MsoListParagraphCxSpMiddle\"><span lang=\"EN-CA\"><span><font size=\"3\">\u00b7<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">Footer text<\/font><\/span><\/p>\n<p class=\"MsoListParagraphCxSpLast\"><span lang=\"EN-CA\"><span><font size=\"3\">\u00b7<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">Common button<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">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\u2019s text or create a simple wizard. Also, the MFC implementation provides a simple mechanism that allows the developer to handle dialog events.<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">The <b>CTaskDialog<\/b> API delivers simple methods to create and initialise controls. For instance:<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\">CTaskDialog dlg(_T(<span>&#8220;A CTaskDialog presents information in a clear and consistent way.&#8221;<\/span>),<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>_T(<span>&#8220;How much do you like CTaskDialog?&#8221;<\/span>), _T(<span>&#8220;Sample CTaskDialog&#8221;<\/span>), 0, <\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>TDF_ENABLE_HYPERLINKS | TDF_USE_COMMAND_LINKS , _T(<span>&#8220;I hope you like it!&#8221;<\/span>));<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>dlg.AddCommandControl( 10, _T(<span>&#8220;&amp;Use it!\\nIt&#8217;s the best dialog you can have!&#8221;<\/span>));<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>dlg.AddCommandControl( 20, _T(<span>&#8220;&amp;Maybe?\\nDon&#8217;t you want to try it?&#8221;<\/span>));<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>dlg.AddCommandControl( 25, _T(<span>&#8220;&amp;No way!\\nI&#8217;m not going to use it!&#8221;<\/span>));<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>dlg.AddRadioButton( 3, _T(<span>&#8220;Lots&#8221;<\/span>));<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>dlg.AddRadioButton( 7, _T(<span>&#8220;A little&#8221;<\/span>));<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>dlg.AddRadioButton( 4, _T(<span>&#8220;Not at all&#8221;<\/span>));<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp; <\/span>dlg.SetMainIcon(TD_SHIELD_ICON);<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>dlg.SetFooterIcon(TD_INFORMATION_ICON);<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>INT_PTR nResult = dlg.DoModal();<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">It creates the following window:<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/vcblog%20CTaskDialog.jpg\"><\/font><\/span><\/p>\n<p class=\"MsoNormal\" align=\"center\"><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">&nbsp;<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">Or the one line function call:<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\">INT_PTR nResult = CTaskDialog::ShowDialog(<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>_T(<span>&#8220;Don&#8217;t spend to much time on code, write only one line and get your CTaskDialog!&#8221;<\/span>), <\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>_T(<span>&#8220;Where do you like to go?&#8221;<\/span>), <\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>_T(<span>&#8220;One line command&#8221;<\/span>), IDS_RADIO_START, IDS_RADIO_START + 3, TDCBF_CANCEL_BUTTON);<\/span><span lang=\"EN-CA\"><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">This feature was introduced in Windows Vista, thus it is required for the <b>_WIN32_WINNT<\/b> define to be set to 0x0600 (value for Windows Vista) or higher. Anyway, it is set per default to Windows Vista in <b>targetver.h<\/b> file. You should be aware that Windows provides two <b>comctl32.dll<\/b> libraries (version 5.x.x.x and 6.x.x.x). The <b>CTaskDialog<\/b> 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: \u201cThe ordinal XXX could not be located in the dynamic link library COMCTL32.dll.\u201d it means that your operating system used the incorrect library version for the application. This can be caused by the wrong assemblies\u2019 configuration in manifest file \u2013 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.<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\">&lt;dependency&gt;<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp; <\/span>&lt;dependentAssembly&gt;<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&lt;assemblyIdentity<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>type=&#8221;win32&#8243;<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>name=&#8221;Microsoft.Windows.Common-Controls&#8221;<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>version=&#8221;6.0.0.0&#8243;<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>processorArchitecture=&#8221;x86&#8243;<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>publicKeyToken=&#8221;6595b64144ccf1df&#8221;<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>language=&#8221;*&#8221;<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>\/&gt;<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp; <\/span>&lt;\/dependentAssembly&gt;<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp; <\/span>&lt;\/dependency&gt;<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">Operating systems below Windows Vista does not support the TaskDialog API. To check the availability of <b>CTaskDialog<\/b> it is possible to use the <b>CTaskDialog::IsSupported()<\/b> method. The simple workaround for this problem would be:<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\">if (CTaskDialog::IsSupported())<span>&nbsp; <\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\">{<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8230; \/\/call CTaskDialog <\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\">}<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\">else MessageBox();<span>&nbsp; <\/span>\/\/call standard message box<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">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 <\/font><a href=\"http:\/\/www.microsoft.com\/downloads\/details.aspx?FamilyId=922B4655-93D0-4476-BDA4-94CF5F8D4814\"><font face=\"Calibri\" color=\"#0000ff\" size=\"3\">http:\/\/www.microsoft.com\/downloads\/details.aspx?FamilyId=922B4655-93D0-4476-BDA4-94CF5F8D4814<\/font><\/a><font face=\"Calibri\" size=\"3\"> . The sample application, which uses <b>CTaskDialog,<\/b> is provided with Visual Studio 2010 and is placed in the Samples directory.<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><font size=\"3\"><span lang=\"EN-CA\"><font face=\"Calibri\">I hope that I\u2019ve encouraged you to use <b>CTaskDialog<\/b>. Feedback is always appreciated <\/font><\/span><span lang=\"EN-CA\"><span>J<\/span><\/span><span lang=\"EN-CA\"><font face=\"Calibri\">.<\/font><\/span><\/font><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">Thx!<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">Lukasz<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">&#8212;<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-CA\"><font face=\"Calibri\" size=\"3\">* More information about it you can be found on MSDN page (<\/font><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb760441(VS.85).aspx\"><font face=\"Calibri\" color=\"#0000ff\" size=\"3\">http:\/\/msdn.microsoft.com\/en-us\/library\/bb760441(VS.85).aspx<\/font><\/a><font face=\"Calibri\" size=\"3\"> ).<\/font><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":289,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4723","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus"],"acf":[],"blog_post_summary":"<p>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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/4723","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/289"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=4723"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/4723\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=4723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=4723"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=4723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}