Skip to content

Commit

Permalink
フォルダ選択ダイアログを追加。
Browse files Browse the repository at this point in the history
  • Loading branch information
YouseiSakusen committed May 19, 2019
1 parent b54459b commit d3f0229
Show file tree
Hide file tree
Showing 62 changed files with 8,810 additions and 14 deletions.
73 changes: 73 additions & 0 deletions 13_episode15/Ookii.Dialogs.Wpf/AnimationResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.IO;

namespace Ookii.Dialogs.Wpf
{
/// <summary>
/// Represents an animation for the <see cref="ProgressDialog"/> loaded from a Win32 resource.
/// </summary>
/// <threadsafety instance="false" static="true" />
public sealed class AnimationResource
{
/// <summary>
/// Initializes a new instance of the <see cref="AnimationResource"/> class.
/// </summary>
/// <param name="resourceFile">The file containing the animation resource.</param>
/// <param name="resourceId">The resource ID of the animation resource.</param>
/// <exception cref="ArgumentNullException"><paramref name="resourceFile"/> is <see langword="null"/>.</exception>
public AnimationResource(string resourceFile, int resourceId)
{
if (resourceFile == null)
throw new ArgumentNullException("resourceFile");

ResourceFile = resourceFile;
ResourceId = resourceId;
}

/// <summary>
/// Gets the name of the file containing the animation resource.
/// </summary>
/// <value>
/// The name of the file containing the animation resource. This is typically a DLL or EXE file.
/// </value>
public string ResourceFile { get; private set; }

/// <summary>
/// Gets the ID of the animation resource.
/// </summary>
/// <value>
/// The ID of the animation resource.
/// </value>
public int ResourceId { get; private set; }

/// <summary>
/// Gets a default animation from shell32.dll.
/// </summary>
/// <param name="animation">The animation to get.</param>
/// <returns>An instance of the <see cref="AnimationResource"/> class representing the specified animation.</returns>
/// <exception cref="ArgumentOutOfRangeException">The <paramref name="animation"/> parameter was not a value defined in the
/// <see cref="ShellAnimation"/> enumeration.</exception>
public static AnimationResource GetShellAnimation(ShellAnimation animation)
{
if (!Enum.IsDefined(typeof(ShellAnimation), animation))
throw new ArgumentOutOfRangeException("animation");

return new AnimationResource("shell32.dll", (int)animation);
}

internal SafeModuleHandle LoadLibrary()
{
SafeModuleHandle handle = NativeMethods.LoadLibraryEx(ResourceFile, IntPtr.Zero, NativeMethods.LoadLibraryExFlags.LoadLibraryAsDatafile);
if (handle.IsInvalid)
{
int error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
if (error == NativeMethods.ErrorFileNotFound)
throw new FileNotFoundException(string.Format(System.Globalization.CultureInfo.CurrentCulture, Properties.Resources.FileNotFoundFormat, ResourceFile));
else
throw new System.ComponentModel.Win32Exception(error);
}

return handle;
}
}
}
41 changes: 41 additions & 0 deletions 13_episode15/Ookii.Dialogs.Wpf/ButtonType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright © Sven Groot (Ookii.org) 2009
// BSD license; see license.txt for details.

namespace Ookii.Dialogs.Wpf
{
/// <summary>
/// Represents the type of a task dialog button.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1027:MarkEnumsWithFlags")]
public enum ButtonType
{
/// <summary>
/// The button is a custom button.
/// </summary>
Custom = 0,
/// <summary>
/// The button is the common OK button.
/// </summary>
Ok = 1,
/// <summary>
/// The button is the common Yes button.
/// </summary>
Yes = 6,
/// <summary>
/// The button is the common No button.
/// </summary>
No = 7,
/// <summary>
/// The button is the common Cancel button.
/// </summary>
Cancel = 2,
/// <summary>
/// The button is the common Retry button.
/// </summary>
Retry = 4,
/// <summary>
/// The button is the common Close button.
/// </summary>
Close = 8
}
}
103 changes: 103 additions & 0 deletions 13_episode15/Ookii.Dialogs.Wpf/ComCtlv6ActivationContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;
using System.IO;
using System.Runtime.InteropServices;

namespace Ookii.Dialogs.Wpf
{
sealed class ComCtlv6ActivationContext : IDisposable
{
// Private data
private IntPtr _cookie;
private static NativeMethods.ACTCTX _enableThemingActivationContext;
private static ActivationContextSafeHandle _activationContext;
private static bool _contextCreationSucceeded;
private static readonly object _contextCreationLock = new object();

public ComCtlv6ActivationContext(bool enable)
{
if (enable && NativeMethods.IsWindowsXPOrLater)
{
if (EnsureActivateContextCreated())
{
if (!NativeMethods.ActivateActCtx(_activationContext, out _cookie))
{
// Be sure cookie always zero if activation failed
_cookie = IntPtr.Zero;
}
}
}
}

~ComCtlv6ActivationContext()
{
Dispose(false);
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

private void Dispose(bool disposing)
{
if (_cookie != IntPtr.Zero)
{
if (NativeMethods.DeactivateActCtx(0, _cookie))
{
// deactivation succeeded...
_cookie = IntPtr.Zero;
}
}
}

private static bool EnsureActivateContextCreated()
{
lock (_contextCreationLock)
{
if (!_contextCreationSucceeded)
{
// Pull manifest from the .NET Framework install
// directory

string assemblyLoc = null;

assemblyLoc = typeof(Object).Assembly.Location;

string manifestLoc = null;
string installDir = null;
if (assemblyLoc != null)
{
installDir = Path.GetDirectoryName(assemblyLoc);
const string manifestName = "XPThemes.manifest";
manifestLoc = Path.Combine(installDir, manifestName);
}

if (manifestLoc != null && installDir != null)
{
_enableThemingActivationContext = new NativeMethods.ACTCTX();
_enableThemingActivationContext.cbSize = Marshal.SizeOf(typeof(NativeMethods.ACTCTX));
_enableThemingActivationContext.lpSource = manifestLoc;

// Set the lpAssemblyDirectory to the install
// directory to prevent Win32 Side by Side from
// looking for comctl32 in the application
// directory, which could cause a bogus dll to be
// placed there and open a security hole.
_enableThemingActivationContext.lpAssemblyDirectory = installDir;
_enableThemingActivationContext.dwFlags = NativeMethods.ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;

// Note this will fail gracefully if file specified
// by manifestLoc doesn't exist.
_activationContext = NativeMethods.CreateActCtx(ref _enableThemingActivationContext);
_contextCreationSucceeded = !_activationContext.IsInvalid;
}
}

// If we return false, we'll try again on the next call into
// EnsureActivateContextCreated(), which is fine.
return _contextCreationSucceeded;
}
}
}
}
Binary file added 13_episode15/Ookii.Dialogs.Wpf/CredentialDialog.bmp
Binary file not shown.
Loading

0 comments on commit d3f0229

Please sign in to comment.