win32 dialog

This commit is contained in:
Lightczx
2023-11-16 16:58:41 +08:00
parent 0dd66288cd
commit b13ec8c12a
5 changed files with 50 additions and 3 deletions

View File

@@ -2,7 +2,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Snap.Hutao.Test;
namespace Snap.Hutao.Test.BaseClassLibrary;
[TestClass]
public class JsonSerializeTest

View File

@@ -1,7 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using System;
namespace Snap.Hutao.Test;
namespace Snap.Hutao.Test.PlatformExtensions;
[TestClass]
public sealed class DependencyInjectionTest

View File

@@ -51,6 +51,8 @@ IPersistFile
IShellLinkW
ShellLink
SHELL_LINK_DATA_FLAGS
FileOpenDialog
IFileOpenDialog
// WinRT
IMemoryBufferByteAccess

View File

@@ -0,0 +1,45 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Core.LifeCycle;
using System.Runtime.InteropServices;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.System.Com;
using Windows.Win32.UI.Shell;
using static Windows.Win32.PInvoke;
namespace Snap.Hutao.Factory.Picker;
internal interface IFileSystemPickerInteraction
{
}
[ConstructorGenerated]
[Injection(InjectAs.Transient, typeof(IFileSystemPickerInteraction))]
internal sealed partial class FileSystemPickerInteraction : IFileSystemPickerInteraction
{
private readonly ICurrentWindowReference currentWindowReference;
public unsafe string PickFile()
{
HRESULT result = CoCreateInstance<FileOpenDialog, IFileOpenDialog>(default, CLSCTX.CLSCTX_INPROC_SERVER, out IFileOpenDialog dialog);
Marshal.ThrowExceptionForHR(result);
dialog.Show(currentWindowReference.GetWindowHandle());
dialog.GetResult(out IShellItem item);
PWSTR name = default;
string file;
try
{
item.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out name);
file = new((char*)name);
}
finally
{
Marshal.FreeCoTaskMem((nint)name.Value);
}
return file;
}
}

View File

@@ -12,7 +12,7 @@
<Identity
Name="60568DGPStudio.SnapHutao"
Publisher="CN=35C8E923-85DF-49A7-9172-B39DC6312C52"
Version="1.7.17.0" />
Version="1.7.18.0" />
<Properties>
<DisplayName>Snap Hutao</DisplayName>