From 82ed3949031c2c5fb938cfb99dc41050973e7e3d Mon Sep 17 00:00:00 2001 From: Speykious Date: Mon, 31 Jan 2022 17:28:20 +0100 Subject: [PATCH] Write first example --- ...eFileDialogs.Net.Example.OpenDialog.csproj | 15 +++++++ .../Program.cs | 42 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 NativeFileDialogs.Net.Example.OpenDialog/NativeFileDialogs.Net.Example.OpenDialog.csproj create mode 100644 NativeFileDialogs.Net.Example.OpenDialog/Program.cs diff --git a/NativeFileDialogs.Net.Example.OpenDialog/NativeFileDialogs.Net.Example.OpenDialog.csproj b/NativeFileDialogs.Net.Example.OpenDialog/NativeFileDialogs.Net.Example.OpenDialog.csproj new file mode 100644 index 0000000..aa84295 --- /dev/null +++ b/NativeFileDialogs.Net.Example.OpenDialog/NativeFileDialogs.Net.Example.OpenDialog.csproj @@ -0,0 +1,15 @@ + + + + Exe + net6.0 + true + enable + enable + + + + + + + diff --git a/NativeFileDialogs.Net.Example.OpenDialog/Program.cs b/NativeFileDialogs.Net.Example.OpenDialog/Program.cs new file mode 100644 index 0000000..9fca20f --- /dev/null +++ b/NativeFileDialogs.Net.Example.OpenDialog/Program.cs @@ -0,0 +1,42 @@ +// Copyright (c) Speykious +// This file is part of NativeFileDialogs.NET. +// NativeFileDialogs.NET is licensed under the Zlib License. See LICENSE for details. + +using NativeFileDialogs.AutoGen; + +unsafe +{ + nfd.NFD_Init(); + + NfdnfilteritemT[] filterItem = new[] + { + new NfdnfilteritemT + { + Name = "Source code", + Spec = "c,cpp,cc", + }, + new NfdnfilteritemT + { + Name = "Headers", + Spec = "h,hpp", + }, + }; + + sbyte* outPathPtr; + NfdresultT result = nfd.NFD_OpenDialogN(&outPathPtr, filterItem, (uint)filterItem.Length, null); + switch (result) + { + case NfdresultT.NFD_OKAY: + Console.WriteLine("Success!"); + Console.WriteLine(new string(outPathPtr)); + break; + case NfdresultT.NFD_CANCEL: + Console.WriteLine("User pressed Cancel."); + break; + default: + Console.WriteLine($"Error: {nfd.NFD_GetError()}"); + break; + } + + nfd.NFD_Quit(); +}