📄 shellapi.cs
字号:
CharSet = CharSet.Auto,
SetLastError = true)]
public static extern void ReleaseStgMedium(
ref STGMEDIUM pmedium);
// Carries out an OLE drag and drop operation
[DllImport("ole32.dll",
CharSet = CharSet.Auto,
SetLastError = true)]
public static extern int DoDragDrop(
IntPtr pDataObject,
[MarshalAs(UnmanagedType.Interface)]
IDropSource pDropSource,
DragDropEffects dwOKEffect,
out DragDropEffects pdwEffect);
// Retrieves a drag/drop helper interface for drawing the drag/drop images
[DllImport("ole32.dll",
CharSet = CharSet.Auto,
SetLastError = true)]
public static extern int CoCreateInstance(
ref Guid rclsid,
IntPtr pUnkOuter,
CLSCTX dwClsContext,
ref Guid riid,
out IntPtr ppv);
// Retrieves a data object that you can use to access the contents of the clipboard
[DllImport("ole32.dll",
CharSet = CharSet.Auto,
SetLastError = true)]
public static extern int OleGetClipboard(
out IntPtr ppDataObj);
#endregion
#endregion
#region Shell GUIDs
public static Guid IID_DesktopGUID = new Guid("{00021400-0000-0000-C000-000000000046}");
public static Guid IID_IShellFolder = new Guid("{000214E6-0000-0000-C000-000000000046}");
public static Guid IID_IContextMenu = new Guid("{000214e4-0000-0000-c000-000000000046}");
public static Guid IID_IContextMenu2 = new Guid("{000214f4-0000-0000-c000-000000000046}");
public static Guid IID_IContextMenu3 = new Guid("{bcfce0a0-ec17-11d0-8d10-00a0c90f2719}");
public static Guid IID_IDropTarget = new Guid("{00000122-0000-0000-C000-000000000046}");
public static Guid IID_IDataObject = new Guid("{0000010e-0000-0000-C000-000000000046}");
public static Guid IID_IQueryInfo = new Guid("{00021500-0000-0000-C000-000000000046}");
public static Guid IID_IPersistFile = new Guid("{0000010b-0000-0000-C000-000000000046}");
public static Guid CLSID_DragDropHelper = new Guid("{4657278A-411B-11d2-839A-00C04FD918D0}");
public static Guid CLSID_NewMenu = new Guid("{D969A300-E7FF-11d0-A93B-00A0C90F2719}");
public static Guid IID_IDragSourceHelper = new Guid("{DE5BF786-477A-11d2-839D-00C04FD918D0}");
public static Guid IID_IDropTargetHelper = new Guid("{4657278B-411B-11d2-839A-00C04FD918D0}");
public static Guid IID_IShellExtInit = new Guid("{000214e8-0000-0000-c000-000000000046}");
public static Guid IID_IStream = new Guid("{0000000c-0000-0000-c000-000000000046}");
public static Guid IID_IStorage = new Guid("{0000000B-0000-0000-C000-000000000046}");
#endregion
#region Structs
// Contains strings returned from the IShellFolder interface methods
[StructLayout(LayoutKind.Explicit)]
public struct STRRET
{
[FieldOffset(0)]
public uint uType;
[FieldOffset(4)]
public IntPtr pOleStr;
[FieldOffset(4)]
public IntPtr pStr;
[FieldOffset(4)]
public uint uOffset;
[FieldOffset(4)]
public IntPtr cStr;
}
// Contains information about a file object
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct SHFILEINFO
{
public IntPtr hIcon;
public int iIcon;
public SFGAO dwAttributes;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)]
public string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string szTypeName;
}
// Contains extended information about a shortcut menu command
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct CMINVOKECOMMANDINFOEX
{
public int cbSize;
public CMIC fMask;
public IntPtr hwnd;
public IntPtr lpVerb;
[MarshalAs(UnmanagedType.LPStr)]
public string lpParameters;
[MarshalAs(UnmanagedType.LPStr)]
public string lpDirectory;
public SW nShow;
public int dwHotKey;
public IntPtr hIcon;
[MarshalAs(UnmanagedType.LPStr)]
public string lpTitle;
public IntPtr lpVerbW;
[MarshalAs(UnmanagedType.LPWStr)]
public string lpParametersW;
[MarshalAs(UnmanagedType.LPWStr)]
public string lpDirectoryW;
[MarshalAs(UnmanagedType.LPWStr)]
public string lpTitleW;
public POINT ptInvoke;
}
// Contains information about a menu item
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct MENUITEMINFO
{
public MENUITEMINFO(string text)
{
cbSize = cbMenuItemInfo;
dwTypeData = text;
cch = text.Length;
fMask = 0;
fType = 0;
fState = 0;
wID = 0;
hSubMenu = IntPtr.Zero;
hbmpChecked = IntPtr.Zero;
hbmpUnchecked = IntPtr.Zero;
dwItemData = IntPtr.Zero;
hbmpItem = IntPtr.Zero;
}
public int cbSize;
public MIIM fMask;
public MFT fType;
public MFS fState;
public uint wID;
public IntPtr hSubMenu;
public IntPtr hbmpChecked;
public IntPtr hbmpUnchecked;
public IntPtr dwItemData;
[MarshalAs(UnmanagedType.LPTStr)]
public string dwTypeData;
public int cch;
public IntPtr hbmpItem;
}
// Contains extended parameters for the TrackPopupMenuEx function
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct TPMPARAMS
{
int cbSize;
RECT rcExclude;
}
// Contains combo box status information
[StructLayout(LayoutKind.Sequential)]
public struct COMBOBOXINFO
{
public int cbSize;
public RECT rcItem;
public RECT rcButton;
public IntPtr stateButton;
public IntPtr hwndCombo;
public IntPtr hwndEdit;
public IntPtr hwndList;
}
// A generalized Clipboard format, it is enhanced to encompass a
// target device, the aspect or view of the data, and a storage medium indicator
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct FORMATETC
{
public CF cfFormat;
public IntPtr ptd;
public DVASPECT dwAspect;
public int lindex;
public TYMED Tymd;
}
// A generalized global memory handle used for data transfer operations by the
// IAdviseSink, IDataObject, and IOleCache interfaces
[StructLayout(LayoutKind.Sequential)]
public struct STGMEDIUM
{
public TYMED tymed;
public IntPtr hBitmap;
public IntPtr hMetaFilePict;
public IntPtr hEnhMetaFile;
public IntPtr hGlobal;
public IntPtr lpszFileName;
public IntPtr pstm;
public IntPtr pstg;
public IntPtr pUnkForRelease;
}
// Contains the information needed to create a drag image
[StructLayout(LayoutKind.Sequential)]
public struct SHDRAGIMAGE
{
public SIZE sizeDragImage;
public POINT ptOffset;
public IntPtr hbmpDragImage;
public Color crColorKey;
}
// Contains and receives information for change notifications
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct SHChangeNotifyEntry
{
public IntPtr pIdl;
public bool Recursively;
}
// Contains two PIDLs concerning the notify message
[StructLayout(LayoutKind.Sequential)]
public struct SHNOTIFYSTRUCT
{
public IntPtr dwItem1;
public IntPtr dwItem2;
}
// Contains statistical data about an open storage, stream, or byte-array object
[StructLayout(LayoutKind.Sequential)]
public struct STATSTG
{
[MarshalAs(UnmanagedType.LPWStr)]
public string pwcsName;
public STGTY type;
public long cbSize;
public ShellAPI.FILETIME mtime;
public ShellAPI.FILETIME ctime;
public ShellAPI.FILETIME atime;
public STGM grfMode;
public LOCKTYPE grfLocksSupported;
public Guid clsid;
public int grfStateBits;
public int reserved;
}
// Represents the number of 100-nanosecond intervals since January 1, 1601
[StructLayout(LayoutKind.Sequential)]
public struct FILETIME
{
public int dwLowDateTime;
public int dwHighDateTime;
}
// Defines the x- and y-coordinates of a point
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct POINT
{
public POINT(int x, int y)
{
this.x = x;
this.y = y;
}
public int x;
public int y;
}
// Defines the coordinates of the upper-left and lower-right corners of a rectangle
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct RECT
{
public RECT(Rectangle rect)
{
left = rect.Left;
top = rect.Top;
right = rect.Right;
bottom = rect.Bottom;
}
int left;
int top;
int right;
int bottom;
}
// The SIZE structure specifies the width and height of a rectangle
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct SIZE
{
public int cx;
public int cy;
}
#endregion
#region Enums
// Used to retrieve directory paths to system special folders
public enum CSIDL
{
ADMINTOOLS = 0x30,
ALTSTARTUP = 0x1d,
APPDATA = 0x1a,
BITBUCKET = 10,
CDBURN_AREA = 0x3b,
COMMON_ADMINTOOLS = 0x2f,
COMMON_ALTSTARTUP = 30,
COMMON_APPDATA = 0x23,
COMMON_DESKTOPDIRECTORY = 0x19,
COMMON_DOCUMENTS = 0x2e,
COMMON_FAVORITES = 0x1f,
COMMON_MUSIC = 0x35,
COMMON_PICTURES = 0x36,
COMMON_PROGRAMS = 0x17,
COMMON_STARTMENU = 0x16,
COMMON_STARTUP = 0x18,
COMMON_TEMPLATES = 0x2d,
COMMON_VIDEO = 0x37,
CONTROLS = 3,
COOKIES = 0x21,
DESKTOP = 0,
DESKTOPDIRECTORY = 0x10,
DRIVES = 0x11,
FAVORITES = 6,
FLAG_CREATE = 0x8000,
FONTS = 20,
HISTORY = 0x22,
INTERNET = 1,
INTERNET_CACHE = 0x20,
LOCAL_APPDATA = 0x1c,
MYDOCUMENTS = 12,
MYMUSIC = 13,
MYPICTURES = 0x27,
MYVIDEO = 14,
NETHOOD = 0x13,
NETWORK = 0x12,
PERSONAL = 5,
PRINTERS = 4,
PRINTHOOD = 0x1b,
PROFILE = 40,
PROFILES = 0x3e,
PROGRAM_FILES = 0x26,
PROGRAM_FILES_COMMON = 0x2b,
PROGRAMS = 2,
RECENT = 8,
SENDTO = 9,
STARTMENU = 11,
STARTUP = 7,
SYSTEM = 0x25,
TEMPLATES = 0x15,
WINDOWS = 0x24
}
// Defines the values used with the IShellFolder::GetDisplayNameOf and IShellFolder::SetNameOf
// methods to specify the type of file or folder names used by those methods
[Flags]
public enum SHGNO
{
NORMAL = 0x0000,
INFOLDER = 0x0001,
FOREDITING = 0x1000,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -