开发者

Using TaskDialogIndirect in C#

开发者 https://www.devze.com 2022-12-28 03:42 出处:网络
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 TaskDialo

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 impl开发者_StackOverflow中文版ementations, 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.


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

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


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.


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


Look at http://www.codeproject.com/Articles/21276/Vista-TaskDialog-Wrapper-and-Emulator. Specifically the file VistaUnsafeNativeMethods.cs has the relevant DllImport bits, including VistaTaskDialogCallback which I think is the callback you are interested in.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号