C# 在Taskdialog中使用隐藏的安全图标

C# 在Taskdialog中使用隐藏的安全图标,c#,taskdialog,C#,Taskdialog,我试图在TaskDialog消息框中显示安全成功图标(蓝色背景)。这不是TaskDialogStandardIcon的枚举值之一。参考文献: 如何将这些非标准值分配给((TaskDialog)sender).Icon?甚至在C#中也有可能吗?C# 任何指示都会非常有用 问候,, Ashwin我认为您需要自己从comctl32.dll导入函数: static class TaskDialogWrapper { [DllImport("comctl32.dll", CharSet = Cha

我试图在TaskDialog消息框中显示安全成功图标(蓝色背景)。这不是TaskDialogStandardIcon的枚举值之一。参考文献:

如何将这些非标准值分配给((TaskDialog)sender).Icon?甚至在C#中也有可能吗?C#

任何指示都会非常有用

问候,,
Ashwin

我认为您需要自己从
comctl32.dll导入函数:

static class TaskDialogWrapper
{
    [DllImport("comctl32.dll", CharSet = CharSet.Unicode, EntryPoint = "TaskDialog")]
    static extern int TaskDialog(IntPtr hWnd, IntPtr hInstance, string pszWindowTitle, string pszMainInstruction, string pszContent, TaskDialogCommonButton dwCommonButtons, IntPtr pszIcon, out IntPtr pnButton);

    public static TaskDialogCommonButton Show(IntPtr handle, IntPtr instance, string title, string instructionText, string content, TaskDialogCommonButton commonButtons, TaskDialogCommonIcon commonIcon)
    {
        IntPtr resultButton;
        if (TaskDialog(handle, instance, title, instructionText, content, commonButtons, new IntPtr((int)commonIcon), out resultButton) != 0)
            throw new InvalidOperationException();
        return (TaskDialogCommonButton)resultButton;
    }
}

[Flags()]
enum TaskDialogCommonButton
{
    Ok = 0x1,
    Yes = 0x2,
    No = 0x4,
    Cancel = 0x8,
    Retry = 0x10,
    Close = 0x20
}

enum TaskDialogCommonIcon
{
    ShieldGrey = 65527,
    ShieldOk = 65528,
    ShieldError = 65529,
    ShieldWarning = 65530,
    ShieldBlue = 65531,
    Shield = 65532,
    Information = 65533,
    Error = 65534,
    Warning = 65535,
}
要从文件中使用自己的图标,需要导入


(顺便说一句,我为
TaskDialogCommonIcon
找到了许多其他有趣的图标样式。您可以添加例如:

enum TaskDialogCommonIcon
{
    None = 0,
    Sheet = 2,
    ExplorerFolderOpen = 3,
    ExplorerFolderFlat = 5,
    ExplorerFolderLeft = 6,
    Search = 8,
    ExplorerFolderClosed = 10,
    ExplorerGames = 14,
    Application = 15,
    TransparentSpace = 17,
    ExplorerSearch = 18,
    TextFile = 19,
    Letter = 20,
    Picture = 21,
    Diashow = 103,
    // ...
}

我知道这是一个老问题,但我一直在寻找类似的问题,所以我想把我发现的东西传给大家。利用@KnorxThieus发布的信息,我找到了一种使用“隐藏”的方法TaskDialog中的安全图标不需要经过上面概述的DLLImport过程。使用他为
TaskDialogCommonIcon
枚举提供的实际值,我发现您可以简单地将它们转换为适当的类型(即
TaskDialogCommonIcon
),应用程序应该正确显示它们

请注意,我使用的是Nuget(Nuget.org/packages/WindowsAPICodePack Core)的WindowsAPICodePack版本1.1.2,下面的代码是使用Telerik代码转换器()从Visual Basic转换而来的,因此您可能需要在C#中进行一些微调:

在我的测试中,这似乎适用于列出的所有@KnorxThieus枚举以及其他几个枚举。我试图找出是否有类似的方法将
图标
属性设置为另一个(非标准)图像文件,但到目前为止我还没有成功。我希望这能帮助以后遇到此问题的任何人。

看看。它实现了
任务对话框
和其他对话框,并且有针对性和针对性的版本


我知道这有点旧,但是你在哪里找到这些特定的枚举(在“顺便说一下”部分)?我想看看我是否可以在某个地方找到它们的完整列表,而不必手动识别每个。我发现我可以使用Nuget()的WindowsAPICodePack通过将Icon属性设置为铸造值(
CType(65528,TaskDialogCommonIcon)
)调用这些,我想尽量得到一个完整的列表。我恐怕会让你失望,但我发现这些常量的方式一直在尝试它们。尽管如此,可能存在任何以相同顺序存储相同图标的DLL(例如imageres?我不知道)您可以通过谷歌搜索图标的官方含义。您可能想查看,它实现了
任务对话框
和其他功能
if (TaskDialog.IsPlatformSupported) {
    using (TaskDialog dialog = new TaskDialog()) {
        dialog.Caption = "TESTING";
        dialog.InstructionText = "THIS IS A TEST";
        dialog.Text = "This is a test of casting a value to the desired Icon type for a TaskDialog.";

        // Produces the green shield with green background
        dialog.Icon = (TaskDialogStandardIcon)65528;
        dialog.OwnerWindowHandle = this.Handle;
        dialog.Show();
    }
}