add preview handler

This commit is contained in:
2021-12-28 16:53:45 +08:00
parent 0f48dbe845
commit c03de86d02
14 changed files with 1613 additions and 91 deletions

View File

@ -1,125 +1,280 @@
using System;
#if PREVIEW_HANDLER
using System;
using System.Runtime.InteropServices;
namespace ShellExtensions.Interop.Common
{
/// <summary>
/// The STGM constants are flags that indicate
/// conditions for creating and deleting the object and access modes
/// for the object.
///
/// You can combine these flags, but you can only choose one flag
/// from each group of related flags. Typically one flag from each
/// of the access and sharing groups must be specified for all
/// functions and methods which use these constants.
/// Wraps the native Windows MSG structure.
/// </summary>
[Flags]
public enum AccessModes
public struct Message
{
/// <summary>
/// Indicates that, in direct mode, each change to a storage
/// or stream element is written as it occurs.
/// Gets the window handle
/// </summary>
Direct = 0x00000000,
public IntPtr WindowHandle { get; }
/// <summary>
/// Indicates that, in transacted mode, changes are buffered
/// and written only if an explicit commit operation is called.
/// Gets the window message
/// </summary>
Transacted = 0x00010000,
public uint Msg { get; }
/// <summary>
/// Provides a faster implementation of a compound file
/// in a limited, but frequently used, case.
/// Gets the WParam
/// </summary>
Simple = 0x08000000,
public IntPtr WParam { get; }
/// <summary>
/// Indicates that the object is read-only,
/// meaning that modifications cannot be made.
/// Gets the LParam
/// </summary>
Read = 0x00000000,
public IntPtr LParam { get; }
/// <summary>
/// Enables you to save changes to the object,
/// but does not permit access to its data.
/// Gets the time
/// </summary>
Write = 0x00000001,
public int Time { get; }
/// <summary>
/// Enables access and modification of object data.
/// Gets the point
/// </summary>
ReadWrite = 0x00000002,
public NativePoint Point { get; }
/// <summary>
/// Specifies that subsequent openings of the object are
/// not denied read or write access.
/// Creates a new instance of the Message struct
/// </summary>
ShareDenyNone = 0x00000040,
/// <param name="windowHandle">Window handle</param>
/// <param name="msg">Message</param>
/// <param name="wparam">WParam</param>
/// <param name="lparam">LParam</param>
/// <param name="time">Time</param>
/// <param name="point">Point</param>
internal Message(IntPtr windowHandle, uint msg, IntPtr wparam, IntPtr lparam, int time, NativePoint point)
: this()
{
WindowHandle = windowHandle;
Msg = msg;
WParam = wparam;
LParam = lparam;
Time = time;
Point = point;
}
/// <summary>
/// Prevents others from subsequently opening the object in Read mode.
/// Determines if two messages are equal.
/// </summary>
ShareDenyRead = 0x00000030,
/// <param name="first">First message</param>
/// <param name="second">Second message</param>
/// <returns>True if first and second message are equal; false otherwise.</returns>
public static bool operator ==(Message first, Message second)
{
return first.WindowHandle == second.WindowHandle
&& first.Msg == second.Msg
&& first.WParam == second.WParam
&& first.LParam == second.LParam
&& first.Time == second.Time
&& first.Point == second.Point;
}
/// <summary>
/// Prevents others from subsequently opening the object
/// for Write or ReadWrite access.
/// Determines if two messages are not equal.
/// </summary>
ShareDenyWrite = 0x00000020,
/// <param name="first">First message</param>
/// <param name="second">Second message</param>
/// <returns>True if first and second message are not equal; false otherwise.</returns>
public static bool operator !=(Message first, Message second)
{
return !(first == second);
}
/// <summary>
/// Prevents others from subsequently opening the object in any mode.
/// Determines if this message is equal to another.
/// </summary>
ShareExclusive = 0x00000010,
/// <param name="obj">Another message</param>
/// <returns>True if this message is equal argument; false otherwise.</returns>
public override bool Equals(object obj)
{
return obj != null && obj is Message message && this == message;
}
/// <summary>
/// Opens the storage object with exclusive access to the most
/// recently committed version.
/// Gets a hash code for the message.
/// </summary>
Priority = 0x00040000,
/// <returns>Hash code for this message.</returns>
public override int GetHashCode()
{
int hash = WindowHandle.GetHashCode();
hash = hash * 31 + Msg.GetHashCode();
hash = hash * 31 + WParam.GetHashCode();
hash = hash * 31 + LParam.GetHashCode();
hash = hash * 31 + Time.GetHashCode();
hash = hash * 31 + Point.GetHashCode();
return hash;
}
}
/// <summary>
/// A wrapper for the native POINT structure.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct NativePoint
{
/// <summary>
/// Initialize the NativePoint
/// </summary>
/// <param name="x">The x coordinate of the point.</param>
/// <param name="y">The y coordinate of the point.</param>
public NativePoint(int x, int y)
: this()
{
X = x;
Y = y;
}
/// <summary>
/// Indicates that the underlying file is to be automatically destroyed when the root
/// storage object is released. This feature is most useful for creating temporary files.
/// The X coordinate of the point
/// </summary>
DeleteOnRelease = 0x04000000,
public int X { get; set; }
/// <summary>
/// Indicates that, in transacted mode, a temporary scratch file is usually used
/// to save modifications until the Commit method is called.
/// Specifying NoScratch permits the unused portion of the original file
/// to be used as work space instead of creating a new file for that purpose.
/// The Y coordinate of the point
/// </summary>
NoScratch = 0x00100000,
public int Y { get; set; }
/// <summary>
/// Indicates that an existing storage object
/// or stream should be removed before the new object replaces it.
/// Determines if two NativePoints are equal.
/// </summary>
Create = 0x00001000,
/// <param name="first">First NativePoint</param>
/// <param name="second">Second NativePoint</param>
/// <returns>True if first NativePoint is equal to the second; false otherwise.</returns>
public static bool operator ==(NativePoint first, NativePoint second)
{
return first.X == second.X
&& first.Y == second.Y;
}
/// <summary>
/// Creates the new object while preserving existing data in a stream named "Contents".
/// Determines if two NativePoints are not equal.
/// </summary>
Convert = 0x00020000,
/// <param name="first">First NativePoint</param>
/// <param name="second">Second NativePoint</param>
/// <returns>True if first NativePoint is not equal to the second; false otherwise.</returns>
public static bool operator !=(NativePoint first, NativePoint second)
{
return !(first == second);
}
/// <summary>
/// Causes the create operation to fail if an existing object with the specified name exists.
/// Determines if this NativePoint is equal to another.
/// </summary>
FailIfThere = 0x00000000,
/// <param name="obj">Another NativePoint to compare</param>
/// <returns>True if this NativePoint is equal obj; false otherwise.</returns>
public override bool Equals(object obj)
{
return obj != null && obj is NativePoint point && this == point;
}
/// <summary>
/// This flag is used when opening a storage object with Transacted
/// and without ShareExclusive or ShareDenyWrite.
/// In this case, specifying NoSnapshot prevents the system-provided
/// implementation from creating a snapshot copy of the file.
/// Instead, changes to the file are written to the end of the file.
/// Gets a hash code for the NativePoint.
/// </summary>
NoSnapshot = 0x00200000,
/// <returns>Hash code for the NativePoint</returns>
public override int GetHashCode()
{
int hash = X.GetHashCode();
hash = hash * 31 + Y.GetHashCode();
return hash;
}
}
/// <summary>
/// A wrapper for a RECT struct
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct NativeRect
{
/// <summary>
/// Position of left edge
/// </summary>
public int Left { get; set; }
/// <summary>
/// Supports direct mode for single-writer, multireader file operations.
/// Position of top edge
/// </summary>
DirectSingleWriterMultipleReader = 0x00400000
public int Top { get; set; }
/// <summary>
/// Position of right edge
/// </summary>
public int Right { get; set; }
/// <summary>
/// Position of bottom edge
/// </summary>
public int Bottom { get; set; }
/// <summary>
/// Creates a new NativeRect initialized with supplied values.
/// </summary>
/// <param name="left">Position of left edge</param>
/// <param name="top">Position of top edge</param>
/// <param name="right">Position of right edge</param>
/// <param name="bottom">Position of bottom edge</param>
public NativeRect(int left, int top, int right, int bottom)
: this()
{
Left = left;
Top = top;
Right = right;
Bottom = bottom;
}
/// <summary>
/// Determines if two NativeRects are equal.
/// </summary>
/// <param name="first">First NativeRect</param>
/// <param name="second">Second NativeRect</param>
/// <returns>True if first NativeRect is equal to second; false otherwise.</returns>
public static bool operator ==(NativeRect first, NativeRect second)
{
return first.Left == second.Left
&& first.Top == second.Top
&& first.Right == second.Right
&& first.Bottom == second.Bottom;
}
/// <summary>
/// Determines if two NativeRects are not equal
/// </summary>
/// <param name="first">First NativeRect</param>
/// <param name="second">Second NativeRect</param>
/// <returns>True if first is not equal to second; false otherwise.</returns>
public static bool operator !=(NativeRect first, NativeRect second)
{
return !(first == second);
}
/// <summary>
/// Determines if the NativeRect is equal to another Rect.
/// </summary>
/// <param name="obj">Another NativeRect to compare</param>
/// <returns>True if this NativeRect is equal to the one provided; false otherwise.</returns>
public override bool Equals(object obj)
{
return obj != null && obj is NativeRect rect && this == rect;
}
/// <summary>
/// Creates a hash code for the NativeRect
/// </summary>
/// <returns>Returns hash code for this NativeRect</returns>
public override int GetHashCode()
{
int hash = Left.GetHashCode();
hash = hash * 31 + Top.GetHashCode();
hash = hash * 31 + Right.GetHashCode();
hash = hash * 31 + Bottom.GetHashCode();
return hash;
}
}
}
#endif