本文整理汇总了C#中IShellFolder.GetUIObjectOf方法的典型用法代码示例。如果您正苦于以下问题:C# IShellFolder.GetUIObjectOf方法的具体用法?C# IShellFolder.GetUIObjectOf怎么用?C# IShellFolder.GetUIObjectOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IShellFolder
的用法示例。
在下文中一共展示了IShellFolder.GetUIObjectOf方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromShellFolder
public static ExtractIconWrapper FromShellFolder(IShellFolder folder, IntPtr pidl)
{
if (folder == null)
{
throw new ArgumentNullException("folder");
}
if (pidl == IntPtr.Zero)
{
throw new ArgumentException("pidl == IntPtr.Zero", "pidl");
}
try
{
object obj2;
IntPtr[] apidl = new IntPtr[] { pidl };
folder.GetUIObjectOf(IntPtr.Zero, 1, apidl, typeof(IExtractIconW).GUID, IntPtr.Zero, out obj2);
if (obj2 != null)
{
return new ExtractIconWrapper((IExtractIconW) obj2);
}
}
catch (FileNotFoundException)
{
}
return null;
}
示例2: GetContextMenuInterfaces
private static bool GetContextMenuInterfaces(IShellFolder oParentFolder, IntPtr PIDLs, out IntPtr ctxMenuPtr)
{
var arrPidLs = new IntPtr[1];
arrPidLs[0] = PIDLs;
var nResult = oParentFolder.GetUIObjectOf(IntPtr.Zero, (uint) arrPidLs.Length, arrPidLs, ref _iidIContextMenu, IntPtr.Zero, out ctxMenuPtr);
if (SOk == nResult)
{
_oContextMenu = (IContextMenu) Marshal.GetTypedObjectForIUnknown(ctxMenuPtr, typeof (IContextMenu));
return true;
}
ctxMenuPtr = IntPtr.Zero;
_oContextMenu = null;
return false;
}
示例3: GetContextMenuInterfaces
/// <summary>Gets the interfaces to the context menu</summary>
/// <param name="oParentFolder">Parent folder</param>
/// <param name="arrPIDLs">PIDLs</param>
/// <returns>true if it got the interfaces, otherwise false</returns>
private bool GetContextMenuInterfaces(IShellFolder oParentFolder, IntPtr[] arrPIDLs, out IntPtr ctxMenuPtr)
{
int nResult = oParentFolder.GetUIObjectOf(
IntPtr.Zero,
(uint)arrPIDLs.Length,
arrPIDLs,
ref IID_IContextMenu,
IntPtr.Zero,
out ctxMenuPtr);
if (S_OK == nResult)
{
_oContextMenu = (IContextMenu)Marshal.GetTypedObjectForIUnknown(ctxMenuPtr, typeof(IContextMenu));
return true;
}
else
{
ctxMenuPtr = IntPtr.Zero;
_oContextMenu = null;
return false;
}
}
示例4: GetContextMenuInterfaces
/// <summary>Gets the interfaces to the context menu</summary>
/// <param name="oParentFolder">Parent folder</param>
/// <param name="arrPIDLs">PIDLs</param>
/// <returns>true if it got the interfaces, otherwise false</returns>
private bool GetContextMenuInterfaces(IShellFolder oParentFolder, IntPtr[] arrPIDLs)
{
IntPtr pUnknownContextMenu = IntPtr.Zero;
int nResult = oParentFolder.GetUIObjectOf(
IntPtr.Zero,
(uint)arrPIDLs.Length,
arrPIDLs,
ref IID_IContextMenu,
IntPtr.Zero,
out pUnknownContextMenu);
if (S_OK == nResult)
{
_oContextMenu = (IContextMenu)Marshal.GetTypedObjectForIUnknown(pUnknownContextMenu, typeof(IContextMenu));
IntPtr pUnknownContextMenu2 = IntPtr.Zero;
if (S_OK == Marshal.QueryInterface(pUnknownContextMenu, ref IID_IContextMenu2, out pUnknownContextMenu2))
{
_oContextMenu2 = (IContextMenu2)Marshal.GetTypedObjectForIUnknown(pUnknownContextMenu2, typeof(IContextMenu2));
}
IntPtr pUnknownContextMenu3 = IntPtr.Zero;
if (S_OK == Marshal.QueryInterface(pUnknownContextMenu, ref IID_IContextMenu3, out pUnknownContextMenu3))
{
_oContextMenu3 = (IContextMenu3)Marshal.GetTypedObjectForIUnknown(pUnknownContextMenu3, typeof(IContextMenu3));
}
return true;
}
else
{
return false;
}
}
示例5: GetIContextMenu
/// <summary>
/// Retrieves the IContextMenu for specific items
/// </summary>
/// <param name="parent">the parent IShellFolder which contains the items</param>
/// <param name="pidls">the pidls of the items for which to retrieve the IContextMenu</param>
/// <param name="icontextMenuPtr">the pointer to the IContextMenu</param>
/// <param name="iContextMenu">the IContextMenu for the items</param>
/// <returns>true if the IContextMenu has been retrieved succesfully, false otherwise</returns>
public static bool GetIContextMenu(
IShellFolder parent,
IntPtr[] pidls,
out IntPtr iContextMenuPtr,
out IContextMenu iContextMenu)
{
if (parent.GetUIObjectOf(
IntPtr.Zero,
(uint)pidls.Length,
pidls,
ref ShellAPI.IID_IContextMenu,
IntPtr.Zero,
out iContextMenuPtr) == ShellAPI.S_OK)
{
iContextMenu =
(IContextMenu)Marshal.GetTypedObjectForIUnknown(
iContextMenuPtr, typeof(IContextMenu));
return true;
}
else
{
iContextMenuPtr = IntPtr.Zero;
iContextMenu = null;
return false;
}
}
示例6: getThumbnail
private bool getThumbnail(string file, IntPtr pidl, IShellFolder item)
{
IntPtr hBmp = IntPtr.Zero;
IExtractImage extractImage = null;
try
{
string pidlPath = PathFromPidl(pidl);
if (Path.GetFileName(pidlPath).ToUpperInvariant().Equals(Path.GetFileName(file).ToUpperInvariant()))
{
// we have the item:
IUnknown iunk = null;
int prgf = 0;
Guid iidExtractImage = new Guid("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1");
item.GetUIObjectOf(IntPtr.Zero, 1, ref pidl, ref iidExtractImage, out prgf, ref iunk);
extractImage = (IExtractImage)iunk;
if (extractImage != null)
{
//Got an IExtractImage object!
SIZE sz = new SIZE();
sz.cx = desiredSize.Width;
sz.cy = desiredSize.Height;
StringBuilder location = new StringBuilder(260, 260);
int priority = 0;
int requestedColourDepth = 32;
//EIEIFLAG flags = EIEIFLAG.IEIFLAG_ASPECT | EIEIFLAG.IEIFLAG_SCREEN;
EIEIFLAG flags = EIEIFLAG.IEIFLAG_ORIGSIZE | EIEIFLAG.IEIFLAG_ASPECT | EIEIFLAG.IEIFLAG_QUALITY;
int uFlags = (int)flags;
// E.g. for PDFs on Vista...
try
{
extractImage.GetLocation(location, location.Capacity, ref priority, ref sz, requestedColourDepth,
ref uFlags);
}
catch (Exception) {}
extractImage.Extract(out hBmp);
if (hBmp != IntPtr.Zero)
{
// create the image object:
thumbNail = System.Drawing.Bitmap.FromHbitmap(hBmp);
// is thumbNail owned by the Bitmap?
}
Marshal.ReleaseComObject(extractImage);
extractImage = null;
}
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
if (hBmp != IntPtr.Zero)
{
UnManagedMethods.DeleteObject(hBmp);
}
if (extractImage != null)
{
Marshal.ReleaseComObject(extractImage);
}
throw ex;
}
}
示例7: GetContextMenu
private static IContextMenu GetContextMenu(IWin32Window owner, IShellFolder parent, string[] fileNames)
{
IContextMenu menu;
IntPtr[] apidl = new IntPtr[fileNames.Length];
try
{
for (int i = 0; i < fileNames.Length; i++)
{
apidl[i] = parent.ParseDisplayName(owner.Handle, fileNames[i]);
}
menu = parent.GetUIObjectOf<IContextMenu>(owner.Handle, apidl);
}
finally
{
foreach (IntPtr ptr in apidl)
{
if (ptr != IntPtr.Zero)
{
Marshal.FreeCoTaskMem(ptr);
}
}
}
return menu;
}
示例8: GetThumbnail
private bool GetThumbnail(string file, IntPtr pidl, IShellFolder item)
{
IntPtr bmp = IntPtr.Zero;
IExtractImage extractImage = null;
try
{
string pidlPath = PathFromPidl(pidl);
if (Path.GetFileName(pidlPath).ToUpper().Equals(Path.GetFileName(file).ToUpper()))
{
// we have the item:
IUnknown iunk = null;
int prgf;
Guid iidExtractImage = new Guid("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1");
item.GetUIObjectOf(IntPtr.Zero, 1, ref pidl, ref iidExtractImage, out prgf, ref iunk);
extractImage = (IExtractImage)iunk;
if (extractImage != null)
{
//Got an IExtractImage object!
ShellAPI.SIZE size = new ShellAPI.SIZE { cx = this.DesiredSize.Width, cy = this.DesiredSize.Height };
StringBuilder location = new StringBuilder(260, 260);
int priority = 0;
const int requestedColourDepth = 32;
const IEIFLAG flags = IEIFLAG.IEIFLAG_ASPECT | IEIFLAG.IEIFLAG_SCREEN;
int uFlags = (int)flags;
extractImage.GetLocation(location, location.Capacity, ref priority, ref size, requestedColourDepth, ref uFlags);
extractImage.Extract(out bmp);
if (bmp != IntPtr.Zero)
{
// create the image object:
this.ThumbNail = Image.FromHbitmap(bmp);
// is thumbNail owned by the Bitmap?
}
Marshal.ReleaseComObject(extractImage);
extractImage = null;
}
return true;
}
else
{
return false;
}
}
catch (Exception)
{
if (bmp != IntPtr.Zero)
{
UnManagedMethods.DeleteObject(bmp);
}
if (extractImage != null)
{
Marshal.ReleaseComObject(extractImage);
}
throw;
}
}
示例9: getThumbNail
private bool getThumbNail(string file, IntPtr pidl, IShellFolder item)
{
IntPtr hBmp = IntPtr.Zero;
IExtractImage extractImage = null;
try
{
var pidlPath = pathFromPidl(pidl);
if (!Path.GetFileName(pidlPath).ToUpper().Equals(Path.GetFileName(file).ToUpper()))
{
return false;
}
IUnknown iunk = null;
var prgf = 0;
var iidExtractImage = new Guid("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1");
item.GetUIObjectOf(IntPtr.Zero, 1, ref pidl, ref iidExtractImage, ref prgf, ref iunk);
extractImage = (IExtractImage)iunk;
if (extractImage == null)
{
return true;
}
var sz = new Size { cx = DesiredSize.Width, cy = DesiredSize.Height };
var location = new StringBuilder(260, 260);
var priority = 0;
const int requestedColourDepth = 32;
const EIEIFLAG flags =
EIEIFLAG.IeiflagScreen | EIEIFLAG.IeiflagAsync | EIEIFLAG.IeiflagQuality | EIEIFLAG.IeiflagCache;
var uFlags = (int)flags;
try
{
extractImage.GetLocation(
location, location.Capacity, ref priority, ref sz, requestedColourDepth, ref uFlags);
}
catch { }
extractImage.Extract(ref hBmp);
if (hBmp != IntPtr.Zero)
{
ThumbNail = Image.FromHbitmap(hBmp);
}
Marshal.ReleaseComObject(extractImage);
extractImage = null;
return true;
}
finally
{
if (hBmp != IntPtr.Zero)
{
UnmanagedMethods.DeleteObject(hBmp);
}
if (extractImage != null)
{
Marshal.ReleaseComObject(extractImage);
}
}
}
示例10: GetThumbnailHelper
private bool GetThumbnailHelper(string file, IntPtr pidl, IShellFolder item)
{
IntPtr bitmapPointer = IntPtr.Zero;
IExtractImage extractImage = null;
try
{
string pidlPath = this.PathFromPidl(pidl);
if (Path.GetFileName(pidlPath).ToUpper().Equals(Path.GetFileName(file).ToUpper()))
{
IUnknown iunk = null;
int prgf = 0;
Guid iidExtractImage = new Guid("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1");
item.GetUIObjectOf(IntPtr.Zero, 1, ref pidl, ref iidExtractImage, ref prgf, ref iunk);
extractImage = (IExtractImage)iunk;
if (extractImage != null)
{
Console.WriteLine("Got an IExtractImage object - " + file);
SIZE sz = new SIZE();
sz.HorizontalSize = this.DesiredSize.Width;
sz.VerticalSize = this.DesiredSize.Height;
StringBuilder location = new StringBuilder(260, 260);
int priority = 0;
int requestedColourDepth = 32;
EIEIFLAG flags = EIEIFLAG.IEIFLAG_ASPECT | EIEIFLAG.IEIFLAG_SCREEN;
int nameFlags = (int)flags;
extractImage.GetLocation(location, location.Capacity, ref priority, ref sz, requestedColourDepth, ref nameFlags);
extractImage.Extract(ref bitmapPointer);
if (bitmapPointer != IntPtr.Zero)
{
this.thumbNail = Bitmap.FromHbitmap(bitmapPointer);
}
Marshal.ReleaseComObject(extractImage);
extractImage = null;
}
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
if (bitmapPointer != IntPtr.Zero)
{
UnmanagedMethods.DeleteObject(bitmapPointer);
}
if (extractImage != null)
{
Marshal.ReleaseComObject(extractImage);
}
throw ex;
}
}
示例11: GetThumbnail
private bool GetThumbnail(string file, IntPtr pidl, IShellFolder item, int width, int height)
{
IntPtr hBmp = IntPtr.Zero;
IExtractImage extractImage = null;
try
{
string pidlPath = PathFromPidl(pidl);
if (Path.GetFileName(pidlPath).ToUpper().Equals(Path.GetFileName(file).ToUpper()))
{
IUnknown iunk = null;
int prgf = 0;
Guid iidExtractImage = new Guid("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1");
item.GetUIObjectOf(IntPtr.Zero, 1, ref pidl, ref iidExtractImage, out prgf, ref iunk);
extractImage = (IExtractImage)iunk;
if (extractImage != null)
{
SIZE sz = new SIZE();
sz.cx = width;
sz.cy = height;
StringBuilder location = new StringBuilder(260, 260);
int priority = 0;
int requestedColourDepth = 32;
EIEIFLAG flags = EIEIFLAG.IEIFLAG_ASPECT | EIEIFLAG.IEIFLAG_SCREEN;
int uFlags = (int)flags;
extractImage.GetLocation(location, location.Capacity, ref priority, ref sz, requestedColourDepth, ref uFlags);
extractImage.Extract(out hBmp);
if (hBmp != IntPtr.Zero)
{
thumbNail = System.Drawing.Bitmap.FromHbitmap(hBmp);
}
Marshal.ReleaseComObject(extractImage);
extractImage = null;
}
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
if (hBmp != IntPtr.Zero)
{
UnmanagedMethods.DeleteObject(hBmp);
}
if (extractImage != null)
{
Marshal.ReleaseComObject(extractImage);
}
throw ex;
}
}
示例12: GetIDropTarget
/// <summary>
/// This method will use the GetUIObjectOf method of IShellFolder to obtain the IDropTarget of a
/// ShellItem.
/// </summary>
/// <param name="item">The item for which to obtain the IDropTarget</param>
/// <param name="dropTargetPtr">A pointer to the returned IDropTarget</param>
/// <returns>the IDropTarget from the ShellItem</returns>
public static bool GetIDropTarget(IntPtr[] pidls, IShellFolder parent, out IntPtr dropTargetPtr, out ShellDll.IDropTarget dropTarget)
{
if (parent.GetUIObjectOf(
IntPtr.Zero,
1,
pidls,
ref ShellAPI.IID_IDropTarget,
IntPtr.Zero,
out dropTargetPtr) == ShellAPI.S_OK)
{
dropTarget =
(ShellDll.IDropTarget)Marshal.GetTypedObjectForIUnknown(dropTargetPtr, typeof(ShellDll.IDropTarget));
return true;
}
else
{
dropTarget = null;
dropTargetPtr = IntPtr.Zero;
return false;
}
}
示例13: GetIDataObject
/// <summary>
/// This method will use the GetUIObjectOf method of IShellFolder to obtain the IDataObject of a
/// ShellItem.
/// </summary>
/// <returns>the IDataObject the ShellItem</returns>
public static IntPtr GetIDataObject(IntPtr[] pidls, IShellFolder parent)
{
IntPtr dataObjectPtr;
if (parent.GetUIObjectOf(
IntPtr.Zero,
(uint)pidls.Length,
pidls,
ref ShellAPI.IID_IDataObject,
IntPtr.Zero,
out dataObjectPtr) == ShellAPI.S_OK)
{
return dataObjectPtr;
}
else
{
return IntPtr.Zero;
}
}
示例14: _getThumbNail
private bool _getThumbNail(string file, IntPtr pidl, IShellFolder item)
{
IntPtr hBmp = IntPtr.Zero;
IExtractImage extractImage = null;
IntPtr[] pidl_array = new IntPtr[] { pidl };
try
{
string pidlPath = PathFromPidl(pidl);
if (Path.GetFileName(pidlPath).ToUpper().Equals(Path.GetFileName(file).ToUpper()))
{
object iunk = null;
Guid iidExtractImage = new Guid("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1");
item.GetUIObjectOf(IntPtr.Zero, 1, pidl_array, ref iidExtractImage, IntPtr.Zero, out iunk);
extractImage = (IExtractImage)iunk;
if (extractImage != null)
{
Console.WriteLine("Got an IExtractImage object!");
SIZE sz = new SIZE();
sz.cx = DesiredSize.Width;
sz.cy = DesiredSize.Height;
StringBuilder location = new StringBuilder(260, 260);
int priority = 0;
int requestedColourDepth = 32;
EIEIFLAG flags = EIEIFLAG.IEIFLAG_ASPECT | EIEIFLAG.IEIFLAG_SCREEN;
int uFlags = (int)flags;
extractImage.GetLocation(location, location.Capacity, ref priority, ref sz, requestedColourDepth, ref uFlags);
extractImage.Extract(ref hBmp);
if (hBmp != IntPtr.Zero)
{
_thumbNail = Bitmap.FromHbitmap(hBmp);
}
Marshal.ReleaseComObject(extractImage);
extractImage = null;
}
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
if (hBmp != IntPtr.Zero)
{
UnmanagedMethods.DeleteObject(hBmp);
}
if (extractImage != null)
{
Marshal.ReleaseComObject(extractImage);
}
throw ex;
}
}