views:

102

answers:

4

I've been working for a while with the regular Windows Vista/7 TaskDialog for a while, and I wanted to add some additional functionality (like custom buttons and a footer), so I need to use TaskDialogIndirect.

Following the MSDN documentation for TaskDialogIndirect, I got this signature:

[DllImport("comctl32.dll",CharSet = CharSet.Unicode,EntryPoint="TaskDialogIndirect")]
static extern int TaskDialogIndirect (TASKDIALOGCONFIG pTaskConfig, out int pnButton, out int pnRadioButton, out bool pfVerificationFlagChecked);

The TASKDIALOGCONFIG class is shown below:

public class TASKDIALOGCONFIG
{
    public UInt16 cbSize;
    public IntPtr hwndParent;
    public IntPtr hInstance;
    public String dwFlags;
    public String dwCommonButtons;
    public IntPtr hMainIcon;
    public String pszMainIcon;
    public String pszMainInstruction;
    public String pszContent;
    public UInt16 cButtons;
    public TASKDIALOG_BUTTON pButtons;
    public int nDefaultButton;
    public UInt16 cRadioButtons;
    public TASKDIALOG_BUTTON pRadioButtons;
    public int nDefaultRadioButton;
    public String pszVerificationText;
    public String pszExpandedInformation;
    public String pszExpandedControlText;
    public String pszCollapsedControlText;
    public IntPtr hFooterIcon;
    public IntPtr pszFooterText;
    public String pszFooter;
    // pfCallback;
    // lpCallbackData;
    public UInt16 cxWidth;
}

The TASKDIALOG_BUTTON implementation:

public class TASKDIALOG_BUTTON
{
    public int nButtonID;
    public String pszButtonText;
}

I am not entirely sure if I am on the right track here. Did anyone use TaskDialogIndirect from managed code directly through WinAPI (without VistaBridge or Windows API Code Pack)? I am curious about the possible implementations, as well as the callback declarations (I am not entirely sure how to implement TaskDialogCallbackProc).

PS: I am looking for a direct WinAPI implementation, not one through a wrapper.

A: 

PInvoke.NET is a great resource for PInvoke techniques. Unfortunately, they only have a TODO stub for TaskDialogIndirect so far.

dthorpe
Exactly. This is why I started this research.
Dennis Delimarsky
The callback should be a delegate. Since it's all in params, it should be fairly straightforward. Look at the PInvoke.NET declaration of EnumFontFamilyExProc for comparison: http://pinvoke.net/default.aspx/Delegates.EnumFontFamExProc
dthorpe
+3  A: 

Look into the VistaBridge library. It will give you a pleasant wrapper around all this stuff, including TaskDialogIndirect..

http://code.msdn.microsoft.com/VistaBridge

Alex DeLarge
I am looking for a direct WinAPI implementation. A wrapper is nice, however I am trying to "look under the hood" and build the call from scratch.
Dennis Delimarsky
@Dennis fair enough, still though if you download the above library you will get to see how it's done, all the source code is there.
Alex DeLarge
+1  A: 

It's worth looking through the Windows API code pack source code as it contains a reasonably complete implementation of TaskDialogIndirect using WinAPI - including callbacks - which would be a good starting point for your own implementation.

Stuart Dunkeld
I did look through it, but being a wrapper, it contains a lot of additional code that is not needed in my case. What I am trying to do is, at this point, to create a simple Task Dialog with some custom actions.
Dennis Delimarsky
+1  A: 

Checkout Task Dialogs in Vista

KMan
I am looking at ideas that apply to managed code. As you see, C++ samples are also shown on MSDN and that's a bit of a different topic.
Dennis Delimarsky