65.9K
CodeProject is changing. Read more.
Home

TaskDialog via Windows API Code Pack for Microsoft .NET Framework

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Aug 29, 2011

CPOL

2 min read

viewsIcon

21283

Using the TaskDialog API as an attactive alternative to the standard windows MessageBox.

TaskDialog quick reference

I'm currently developing an application and I got so tired of looking at the same old MessageBox that I've been looking at for years and thought surely someone on CP has a better mouse trap. I found a few fairly decent solutions but then discovered that when Vista came out Microsoft included a very nifty TaskDialog control and provided an API but it was in unmanaged code. So I looked around a little more and found an excellent article by KevinGre TaskDialog for WinFormsthat was basically a wrapper but when I tried to run it I had problems and as opposed to diving into old code (written in Jan 2007) I looked around for something more recent.

What I ran accoss is the Windows API Code Pack for Microsoft .NET Framework that included among a lot of other things a managed TaskDialog. So I download the code and included a reference in my code and followed the instructions that I had found on a couple of sites and when I ran it I got a "Unable to find an entry point name 'TaskDialogIndirect' in DLL 'comctl32.dll'" exception so it was back to google and it took quite a while but I found this article that proposed a trick that solved this problem and by gum it worked. In a nut shell this is what is needed to resolve the problem with the exception.
  • Open Project Properties
  • Go to Security Tab and click the Enable ClickOnce Security Settings don't close window yet
  • This will create an app.manifest file in the Properties solution folder.
  • Edit this file and under the </trustInfo> insert the code shown below.
  • Compile your soution, you will get an error
  • Go back to the ClickOnce option and deselect it.
  • Recompile your code. This time it will compile without errors and your code will run without exception.
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*" />
    </dependentAssembly>
  </dependency>
    

I was so glad to find that article and it really is nice to be able to interact with the user using the new TaskDialog. It is so much more flexible and easy to use.

As an added bonus during my googling I ran across this articledescribing some undocumented/hidden icons that are available for use in the TaskDialog. The icon definitions are listed here;

Value Description
0 None
65535 Warning
65535 Warning
65534 Error
65533 Information
65532 Shield
65531 SecurityShieldBlue
65530 SecurityWarning
65529 SecurityError
65528 SecuritySuccess
65527 SecurityShieldGray